aboutsummaryrefslogtreecommitdiffstats
path: root/src/openssl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/openssl.c')
-rw-r--r--src/openssl.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/openssl.c b/src/openssl.c
index e5f0cd4..a34a8cf 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1221,6 +1221,9 @@ static _Bool auxL_newclass(lua_State *L, const char *name, const auxL_Reg *metho
_Bool fresh = auxL_newmetatable(L, name, reset);
int n;
+ if (!reset && !fresh)
+ return fresh;
+
auxL_setfuncs(L, metamethods, 0);
if ((n = auxL_liblen(methods))) {
@@ -3249,8 +3252,6 @@ static int pk_new(lua_State *L) {
/* #1 table or key; if key, #2 format and #3 type */
lua_settop(L, 3);
- ud = prepsimple(L, PKEY_CLASS);
-
if (lua_istable(L, 1) || lua_isnil(L, 1)) {
int type = EVP_PKEY_RSA;
unsigned bits = 1024;
@@ -3292,7 +3293,7 @@ static int pk_new(lua_State *L) {
bits = (unsigned)n;
}
- if (!getfield(L, 1, "exp")) {
+ if (getfield(L, 1, "exp")) {
exp = checkbig(L, -1);
} else {
/* default to 65537 */
@@ -3327,6 +3328,8 @@ static int pk_new(lua_State *L) {
}
creat:
+ ud = prepsimple(L, PKEY_CLASS);
+
if (!(*ud = EVP_PKEY_new()))
return auxL_error(L, auxL_EOPENSSL, "pkey.new");
@@ -3467,6 +3470,8 @@ creat:
data = luaL_checklstring(L, 1, &len);
+ ud = prepsimple(L, PKEY_CLASS);
+
if (!(bio = BIO_new_mem_buf((void *)data, len)))
return auxL_error(L, auxL_EOPENSSL, "pkey.new");
@@ -5639,11 +5644,7 @@ static int xc_digest(lua_State *L) {
luaL_Buffer B;
unsigned i;
-#if LUA_VERSION_NUM < 502
- luaL_buffinit(L, &B);
-#else
luaL_buffinitsize(L, &B, 2 * len);
-#endif
for (i = 0; i < len; i++) {
luaL_addchar(&B, x[0x0f & (md[i] >> 4)]);
@@ -8903,19 +8904,9 @@ static int ssl_getClientRandom(lua_State *L) {
unsigned char *out;
len = SSL_get_client_random(ssl, NULL, 0);
-#if LUA_VERSION_NUM < 502
- if (LUAL_BUFFERSIZE < len)
- luaL_error(L, "ssl:getClientRandom: LUAL_BUFFERSIZE(%d) < SSL_get_client_random(ssl, NULL, 0)", (int)LUAL_BUFFERSIZE, (int)len);
- luaL_buffinit(L, &B);
- out = (unsigned char*)luaL_prepbuffer(&B);
- len = SSL_get_client_random(ssl, out, len);
- luaL_addsize(&B, len);
- luaL_pushresult(&B);
-#else
out = (unsigned char*)luaL_buffinitsize(L, &B, len);
len = SSL_get_client_random(ssl, out, len);
luaL_pushresultsize(&B, len);
-#endif
return 1;
} /* ssl_getClientRandom() */