Diff

util/random.lua @ 7114:51cf09bb74eb

util.random: Restore friendlier error from 0.9/util.uuid
author Kim Alvefur <zash@zash.se>
date Sun, 31 Jan 2016 17:27:15 +0100
parent 7083:ac920b0f9eae
child 7187:3d2c2f0809ee
line wrap: on
line diff
--- a/util/random.lua	Fri Jan 29 14:52:38 2016 +0100
+++ b/util/random.lua	Sun Jan 31 17:27:15 2016 +0100
@@ -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 @@
 	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;