summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2015-12-18 23:08:07 +1100
committerdaurnimator <quae@daurnimator.com>2015-12-21 19:32:54 +1100
commitdce3be261d53b6148e9f599e1a18aeae63e26ff4 (patch)
treecafc9115145cdd1e18fe485197a2d52828a6f0fa
parente1ccaebacd4e8f277222d2177e7c02fb31ea0bf2 (diff)
downloadluaossl-dce3be261d53b6148e9f599e1a18aeae63e26ff4.tar.gz
luaossl-dce3be261d53b6148e9f599e1a18aeae63e26ff4.tar.bz2
luaossl-dce3be261d53b6148e9f599e1a18aeae63e26ff4.zip
bignum: Add tohex function
-rw-r--r--src/openssl.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index cb74506..d6bec90 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1970,6 +1970,35 @@ sslerr:
1970} /* bn_todec() */ 1970} /* bn_todec() */
1971 1971
1972 1972
1973static int bn_tohex(lua_State *L) {
1974 BIGNUM *bn = checksimple(L, 1, BIGNUM_CLASS);
1975 char *txt = NULL;
1976 BIO *bio;
1977 BUF_MEM *buf;
1978
1979 if (!(txt = BN_bn2hex(bn)))
1980 goto sslerr;
1981
1982 /* use GC-visible BIO as temporary buffer */
1983 bio = getbio(L);
1984
1985 if (BIO_puts(bio, txt) < 0)
1986 goto sslerr;
1987
1988 OPENSSL_free(txt);
1989 txt = NULL;
1990
1991 BIO_get_mem_ptr(bio, &buf);
1992 lua_pushlstring(L, buf->data, buf->length);
1993
1994 return 1;
1995sslerr:
1996 OPENSSL_free(txt);
1997
1998 return auxL_error(L, auxL_EOPENSSL, "bignum:tohex");
1999} /* bn_tohex() */
2000
2001
1973static const luaL_Reg bn_methods[] = { 2002static const luaL_Reg bn_methods[] = {
1974 { "add", &bn__add }, 2003 { "add", &bn__add },
1975 { "sub", &bn__sub }, 2004 { "sub", &bn__sub },
@@ -1981,6 +2010,7 @@ static const luaL_Reg bn_methods[] = {
1981 { "shr", &bn__shr }, 2010 { "shr", &bn__shr },
1982 { "tobin", &bn_tobin }, 2011 { "tobin", &bn_tobin },
1983 { "todec", &bn_todec }, 2012 { "todec", &bn_todec },
2013 { "tohex", &bn_tohex },
1984 { NULL, NULL }, 2014 { NULL, NULL },
1985}; 2015};
1986 2016