Merge 0.10->trunk
[prosody.git] / util / random.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2014 Matthew Wild
3 -- Copyright (C) 2008-2014 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 local urandom, urandom_err = io.open("/dev/urandom", "r");
10
11 local function seed()
12 end
13
14 local function bytes(n)
15         return urandom:read(n);
16 end
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
24 return {
25         seed = seed;
26         bytes = bytes;
27 };