Software /
code /
prosody
Comparison
util/random.lua @ 10016:af8c514e5cf7 0.11
util.random: Throw different error for EOL condition
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 May 2019 08:52:21 +0200 |
parent | 10015:8297408db58b |
child | 12446:e54b8a5e35ad |
comparison
equal
deleted
inserted
replaced
10015:8297408db58b | 10016:af8c514e5cf7 |
---|---|
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): "..tostring(err)); | 17 if err then |
18 error("Unable to retrieve data from secure random number generator (/dev/urandom): "..tostring(err)); | |
19 else | |
20 error("Secure random number generator (/dev/urandom) returned an end-of-file condition"); | |
21 end | |
18 end | 22 end |
19 return data; | 23 return data; |
20 end | 24 end |
21 | 25 |
22 if not urandom then | 26 if not urandom then |