Software /
code /
prosody
Comparison
util-src/crand.c @ 7826:7702ce682427
util.crand: Raise hard errors
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 20 Jan 2017 12:23:55 +0100 |
parent | 7825:1dfa5847d49e |
child | 7829:1fb477d19fdd |
comparison
equal
deleted
inserted
replaced
7825:1dfa5847d49e | 7826:7702ce682427 |
---|---|
48 | 48 |
49 #if defined(WITH_GETRANDOM) | 49 #if defined(WITH_GETRANDOM) |
50 ret = getrandom(buf, len, 0); | 50 ret = getrandom(buf, len, 0); |
51 | 51 |
52 if(ret < 0) { | 52 if(ret < 0) { |
53 lua_pushnil(L); | |
54 lua_pushstring(L, strerror(errno)); | 53 lua_pushstring(L, strerror(errno)); |
55 lua_pushinteger(L, errno); | 54 return lua_error(L); |
56 return 3; | |
57 } | 55 } |
58 | 56 |
59 #elif defined(WITH_ARC4RANDOM) | 57 #elif defined(WITH_ARC4RANDOM) |
60 arc4random_buf(buf, len); | 58 arc4random_buf(buf, len); |
61 ret = len; | 59 ret = len; |
63 ret = RAND_bytes(buf, len); | 61 ret = RAND_bytes(buf, len); |
64 | 62 |
65 if(ret == 1) { | 63 if(ret == 1) { |
66 ret = len; | 64 ret = len; |
67 } else { | 65 } else { |
68 lua_pushnil(L); | 66 lua_pushstring(L, "RAND_bytes() failed"); |
69 lua_pushstring(L, "failed"); | 67 return lua_error(L); |
70 /* lua_pushinteger(L, ERR_get_error()); */ | |
71 return 2; | |
72 } | 68 } |
73 | 69 |
74 #endif | 70 #endif |
75 | 71 |
76 lua_pushlstring(L, buf, ret); | 72 lua_pushlstring(L, buf, ret); |