From c85830f814aeebd98a471f2a0fc6e5848714ecbf Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 7 Dec 2015 01:55:09 +1100 Subject: Add :tobin method to bignums --- src/openssl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index 9dbcda7..8fadb02 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -1753,6 +1753,16 @@ static BN_CTX *getctx(lua_State *L) { } /* getctx() */ +static int bn_tobin(lua_State *L) { + BIGNUM *bn = checksimple(L, 1, BIGNUM_CLASS); + size_t len = BN_num_bytes(bn); + unsigned char* dst = lua_newuserdata(L, len); + BN_bn2bin(bn, dst); + lua_pushlstring(L, dst, len); + return 1; +} /* bn_tobin() */ + + static int bn__add(lua_State *L) { BIGNUM *r, *a, *b; @@ -1892,6 +1902,7 @@ static int bn__tostring(lua_State *L) { static const luaL_Reg bn_methods[] = { + { "tobin", &bn_tobin }, { NULL, NULL }, }; -- cgit v1.2.3-59-g8ed1b