Merge pull request #140 from apreiml/fix

make sure we got enough random bytes
This commit is contained in:
Bram 2019-07-30 00:40:58 +02:00 committed by GitHub
commit d40bfe438f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,7 +36,11 @@ end
-- Efficient function to get a random string -- Efficient function to get a random string
function random_string() function random_string()
local random_bytes = io.open("/dev/urandom"):read(64); local length = 64
local random_bytes = io.open("/dev/urandom"):read(length);
if string.len(random_bytes) ~= length then
error("Not enough random bytes read")
end
return tohex(random_bytes); return tohex(random_bytes);
end end