aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar William Ahern <william@25thandClement.com> 2015-12-17 15:46:39 +0800
committerLibravatarLibravatar William Ahern <william@25thandClement.com> 2015-12-17 15:46:39 +0800
commitc092552bf4a650c18f31b0cdb035606318aac66b (patch)
treec806d4a38ef5e7aa9271b5d8ea9a112b8698b687
parenta7063a8467c4c0db8eb8f9b1c9e6c9f33c3f664f (diff)
parentc85830f814aeebd98a471f2a0fc6e5848714ecbf (diff)
downloadluaossl-c092552bf4a650c18f31b0cdb035606318aac66b.tar.gz
luaossl-c092552bf4a650c18f31b0cdb035606318aac66b.tar.bz2
luaossl-c092552bf4a650c18f31b0cdb035606318aac66b.zip
Merge branch 'bn-tobin' of git://github.com/daurnimator/luaossl into daurnimator-bn-tobin
-rw-r--r--src/openssl.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 69115ce..4da28ef 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;
@@ -1898,6 +1908,7 @@ static int bn__tostring(lua_State *L) {
static const luaL_Reg bn_methods[] = {
+ { "tobin", &bn_tobin },
{ NULL, NULL },
};