X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;ds=sidebyside;f=util%2Frandom.lua;h=574e2e1cdf384cf7d893530fdcd97c80843aaba7;hb=bca35c227886965fb03723280c0fc79bdadb5faa;hp=05f36aba326d661fd93182d3875e13520e1b01c9;hpb=3649d951aa384ebe81c156c692438ff6fc318dff;p=prosody.git diff --git a/util/random.lua b/util/random.lua index 05f36aba..574e2e1c 100644 --- a/util/random.lua +++ b/util/random.lua @@ -6,7 +6,10 @@ -- 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 @@ -15,6 +18,12 @@ local function bytes(n) 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;