Software /
code /
prosody
Comparison
util/random.lua @ 10014:5d2f7144fa12 0.11
util.random: Handle unlikely read errors from /dev/urandom (see #1313)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 18 May 2019 17:28:21 +0200 |
parent | 8243:292f61d9d30a |
child | 10015:8297408db58b |
comparison
equal
deleted
inserted
replaced
10013:62d8689beafb | 10014:5d2f7144fa12 |
---|---|
10 if ok then return crand; end | 10 if ok then return crand; end |
11 | 11 |
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 return urandom:read(n); | 15 local data, err = urandom:read(n); |
16 if not data then | |
17 error("Unable to retrieve data from secure random number generator (/dev/urandom): "..err); | |
18 end | |
19 return data; | |
16 end | 20 end |
17 | 21 |
18 if not urandom then | 22 if not urandom then |
19 function bytes() | 23 function bytes() |
20 error("Unable to obtain a secure random number generator, please see https://prosody.im/doc/random ("..urandom_err..")"); | 24 error("Unable to obtain a secure random number generator, please see https://prosody.im/doc/random ("..urandom_err..")"); |