aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-03 08:14:17 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-01-04 19:05:42 +1100
commitae3506413067af8d209d16ffc10c2e7c99dc6bba (patch)
tree7dea07510644e5feea91c1ea4cb5ca8a5a7188b7
parentf5ceb7d11ffd98baa5fe06756370b60f2379195b (diff)
downloadluaossl-ae3506413067af8d209d16ffc10c2e7c99dc6bba.tar.gz
luaossl-ae3506413067af8d209d16ffc10c2e7c99dc6bba.tar.bz2
luaossl-ae3506413067af8d209d16ffc10c2e7c99dc6bba.zip
bignum: Add fromBinary constructor
Closes #44
-rw-r--r--src/openssl.c12
1 files changed, 12 insertions, 0 deletions
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 },
};