Comparison

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
comparison
equal deleted inserted replaced
7112:bd29742fa1ba 7114:51cf09bb74eb
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 local urandom = assert(io.open("/dev/urandom", "r")); 9 local urandom, urandom_err = io.open("/dev/urandom", "r");
10 10
11 local function seed() 11 local function seed()
12 end 12 end
13 13
14 local function bytes(n) 14 local function bytes(n)
15 return urandom:read(n); 15 return urandom:read(n);
16 end 16 end
17 17
18 if not urandom then
19 function bytes()
20 error("Unable to obtain a secure random number generator, please see https://prosody.im/doc/random ("..urandom_err..")");
21 end
22 end
23
18 return { 24 return {
19 seed = seed; 25 seed = seed;
20 bytes = bytes; 26 bytes = bytes;
21 }; 27 };