Comparison

util/random.lua @ 10015:8297408db58b 0.11

util.random: Coerce error to string (thanks waqas) In theory this could happen in an EOF condition, which should be impossible with a read from /dev/urandom.
author Kim Alvefur <zash@zash.se>
date Sat, 18 May 2019 18:51:25 +0200
parent 10014:5d2f7144fa12
child 10016:af8c514e5cf7
comparison
equal deleted inserted replaced
10014:5d2f7144fa12 10015:8297408db58b
12 local urandom, urandom_err = io.open("/dev/urandom", "r"); 12 local urandom, urandom_err = io.open("/dev/urandom", "r");
13 13
14 local function bytes(n) 14 local function bytes(n)
15 local data, err = urandom:read(n); 15 local data, err = urandom:read(n);
16 if not data then 16 if not data then
17 error("Unable to retrieve data from secure random number generator (/dev/urandom): "..err); 17 error("Unable to retrieve data from secure random number generator (/dev/urandom): "..tostring(err));
18 end 18 end
19 return data; 19 return data;
20 end 20 end
21 21
22 if not urandom then 22 if not urandom then