From 77d38ec3be5030397f895fd19959a87a065fac14 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 30 May 2018 17:19:25 +1000 Subject: src/openssl.c: Add lua_isinteger path to bignum construction for Lua 5.3 --- src/openssl.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index b0fea04..5108713 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -2802,6 +2802,24 @@ static BIGNUM *(checkbig)(lua_State *L, int index, _Bool *lvalue) { bn = prepsimple(L, BIGNUM_CLASS); +#if LUA_VERSION_NUM >= 503 + if (lua_isinteger(L, index)) { + lua_Integer n = lua_tointeger(L, index); + auxL_Unsigned lu; + + if (!*bn && !(*bn = BN_new())) + auxL_error(L, auxL_EOPENSSL, "bignum"); + + neg = n < 0; + lu = neg ? (0 - n) : n; + + if (!BN_set_word(*bn, lu)) + auxL_error(L, auxL_EOPENSSL, "bignum"); + + if (neg) + BN_set_negative(*bn, 1); + } else +#endif if (!f2bn(bn, lua_tonumber(L, index))) auxL_error(L, auxL_EOPENSSL, "bignum"); -- cgit v1.2.3-59-g8ed1b