Software / code / prosody
Comparison
util/random.lua @ 7116:ecba5fee4867
Merge 0.10->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 01 Feb 2016 21:28:07 +0000 |
| parent | 7114:51cf09bb74eb |
| child | 7187:3d2c2f0809ee |
comparison
equal
deleted
inserted
replaced
| 7113:ecebc821225d | 7116:ecba5fee4867 |
|---|---|
| 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 }; |