summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2015-12-07 01:55:09 +1100
committerdaurnimator <quae@daurnimator.com>2015-12-07 02:24:21 +1100
commitc85830f814aeebd98a471f2a0fc6e5848714ecbf (patch)
tree32aa08cd8ec41221bb8e23e39db0eda2fb833e26
parent60fc10973eb348cb3d99d27f083437ddeab03f14 (diff)
downloadluaossl-c85830f814aeebd98a471f2a0fc6e5848714ecbf.tar.gz
luaossl-c85830f814aeebd98a471f2a0fc6e5848714ecbf.tar.bz2
luaossl-c85830f814aeebd98a471f2a0fc6e5848714ecbf.zip
Add :tobin method to bignums
-rw-r--r--src/openssl.c11
1 files changed, 11 insertions, 0 deletions
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) {
1753} /* getctx() */ 1753} /* getctx() */
1754 1754
1755 1755
1756static int bn_tobin(lua_State *L) {
1757 BIGNUM *bn = checksimple(L, 1, BIGNUM_CLASS);
1758 size_t len = BN_num_bytes(bn);
1759 unsigned char* dst = lua_newuserdata(L, len);
1760 BN_bn2bin(bn, dst);
1761 lua_pushlstring(L, dst, len);
1762 return 1;
1763} /* bn_tobin() */
1764
1765
1756static int bn__add(lua_State *L) { 1766static int bn__add(lua_State *L) {
1757 BIGNUM *r, *a, *b; 1767 BIGNUM *r, *a, *b;
1758 1768
@@ -1892,6 +1902,7 @@ static int bn__tostring(lua_State *L) {
1892 1902
1893 1903
1894static const luaL_Reg bn_methods[] = { 1904static const luaL_Reg bn_methods[] = {
1905 { "tobin", &bn_tobin },
1895 { NULL, NULL }, 1906 { NULL, NULL },
1896}; 1907};
1897 1908