util.random: Restore friendlier error from 0.9/util.uuid
authorKim Alvefur <zash@zash.se>
Sun, 31 Jan 2016 16:27:15 +0000 (17:27 +0100)
committerKim Alvefur <zash@zash.se>
Sun, 31 Jan 2016 16:27:15 +0000 (17:27 +0100)
util/random.lua

index 05f36aba326d661fd93182d3875e13520e1b01c9..e4b4a700a89c15b2bb72397094ad1b7f0b16fd51 100644 (file)
@@ -6,7 +6,7 @@
 -- COPYING file in the source package for more information.
 --
 
-local urandom = assert(io.open("/dev/urandom", "r"));
+local urandom, urandom_err = io.open("/dev/urandom", "r");
 
 local function seed()
 end
@@ -15,6 +15,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;