diff options
author | daurnimator <quae@daurnimator.com> | 2016-01-03 08:14:17 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2016-01-04 19:05:42 +1100 |
commit | ae3506413067af8d209d16ffc10c2e7c99dc6bba (patch) | |
tree | 7dea07510644e5feea91c1ea4cb5ca8a5a7188b7 | |
parent | f5ceb7d11ffd98baa5fe06756370b60f2379195b (diff) | |
download | luaossl-ae3506413067af8d209d16ffc10c2e7c99dc6bba.tar.gz luaossl-ae3506413067af8d209d16ffc10c2e7c99dc6bba.tar.bz2 luaossl-ae3506413067af8d209d16ffc10c2e7c99dc6bba.zip |
bignum: Add fromBinary constructor
Closes #44
-rw-r--r-- | src/openssl.c | 12 |
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) { | |||
1598 | } /* bn_new() */ | 1598 | } /* bn_new() */ |
1599 | 1599 | ||
1600 | 1600 | ||
1601 | static int bn_fromBinary(lua_State *L) { | ||
1602 | size_t len; | ||
1603 | const char *s = luaL_checklstring(L, 1, &len); | ||
1604 | BIGNUM *bn = bn_push(L); | ||
1605 | if (!BN_bin2bn((const unsigned char*)s, len, bn)) { | ||
1606 | auxL_error(L, auxL_EOPENSSL, "bignum"); | ||
1607 | } | ||
1608 | return 1; | ||
1609 | } /* bn_fromBinary() */ | ||
1610 | |||
1611 | |||
1601 | static int bn_interpose(lua_State *L) { | 1612 | static int bn_interpose(lua_State *L) { |
1602 | return interpose(L, BIGNUM_CLASS); | 1613 | return interpose(L, BIGNUM_CLASS); |
1603 | } /* bn_interpose() */ | 1614 | } /* bn_interpose() */ |
@@ -2119,6 +2130,7 @@ static const luaL_Reg bn_metatable[] = { | |||
2119 | static const luaL_Reg bn_globals[] = { | 2130 | static const luaL_Reg bn_globals[] = { |
2120 | { "new", &bn_new }, | 2131 | { "new", &bn_new }, |
2121 | { "interpose", &bn_interpose }, | 2132 | { "interpose", &bn_interpose }, |
2133 | { "fromBinary", &bn_fromBinary }, | ||
2122 | { "generatePrime", &bn_generatePrime }, | 2134 | { "generatePrime", &bn_generatePrime }, |
2123 | { NULL, NULL }, | 2135 | { NULL, NULL }, |
2124 | }; | 2136 | }; |