From ae3506413067af8d209d16ffc10c2e7c99dc6bba Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 3 Jan 2016 08:14:17 +1100 Subject: bignum: Add fromBinary constructor Closes #44 --- src/openssl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/openssl.c b/src/openssl.c index 82f3298..0a444c8 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -1598,6 +1598,17 @@ static int bn_new(lua_State *L) { } /* bn_new() */ +static int bn_fromBinary(lua_State *L) { + size_t len; + const char *s = luaL_checklstring(L, 1, &len); + BIGNUM *bn = bn_push(L); + if (!BN_bin2bn((const unsigned char*)s, len, bn)) { + auxL_error(L, auxL_EOPENSSL, "bignum"); + } + return 1; +} /* bn_fromBinary() */ + + static int bn_interpose(lua_State *L) { return interpose(L, BIGNUM_CLASS); } /* bn_interpose() */ @@ -2119,6 +2130,7 @@ static const luaL_Reg bn_metatable[] = { static const luaL_Reg bn_globals[] = { { "new", &bn_new }, { "interpose", &bn_interpose }, + { "fromBinary", &bn_fromBinary }, { "generatePrime", &bn_generatePrime }, { NULL, NULL }, }; -- cgit v1.2.3-59-g8ed1b