projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge 0.10->trunk
[prosody.git]
/
util
/
random.lua
diff --git
a/util/random.lua
b/util/random.lua
index 05f36aba326d661fd93182d3875e13520e1b01c9..574e2e1cdf384cf7d893530fdcd97c80843aaba7 100644
(file)
--- a/
util/random.lua
+++ b/
util/random.lua
@@
-6,7
+6,10
@@
-- COPYING file in the source package for more information.
--
-- COPYING file in the source package for more information.
--
-local urandom = assert(io.open("/dev/urandom", "r"));
+local ok, crand = pcall(require, "util.crand");
+if ok then return crand; end
+
+local urandom, urandom_err = io.open("/dev/urandom", "r");
local function seed()
end
local function seed()
end
@@
-15,6
+18,12
@@
local function bytes(n)
return urandom:read(n);
end
return urandom:read(n);
end
+if not urandom then
+ function bytes()
+ error("Unable to obtain a secure random number generator, please see https://prosody.im/doc/random ("..urandom_err..")");
+ end
+end
+
return {
seed = seed;
bytes = bytes;
return {
seed = seed;
bytes = bytes;