aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar william <william+macosx@25thandclement.com> 2015-06-04 12:25:44 -0700
committerLibravatarLibravatar william <william+macosx@25thandclement.com> 2015-06-04 12:25:44 -0700
commit969207b3c5926ac33ce6cb8685ae3b0616d27176 (patch)
treeb9ce5b617334e86324aae0ed6f684cc0cf883206 /src
parent86c88410aab446a9e385080b95fbd1825223cade (diff)
downloadluaossl-969207b3c5926ac33ce6cb8685ae3b0616d27176.tar.gz
luaossl-969207b3c5926ac33ce6cb8685ae3b0616d27176.tar.bz2
luaossl-969207b3c5926ac33ce6cb8685ae3b0616d27176.zip
update x509:getPublicKeyDigest to take optional digest type
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 8e95622..646e2ae 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -3722,18 +3722,22 @@ static int xc_setPublicKey(lua_State *L) {
static int xc_getPublicKeyDigest(lua_State *L) {
- ASN1_BIT_STRING *pk = ((X509 *) checksimple(L, 1, X509_CERT_CLASS))->cert_info->key->public_key;
-
+ ASN1_BIT_STRING *pk = ((X509 *)checksimple(L, 1, X509_CERT_CLASS))->cert_info->key->public_key;
+ const char *id = luaL_optstring(L, 2, "sha1");
+ const EVP_MD *md;
unsigned char digest[EVP_MAX_MD_SIZE];
unsigned int len;
- if (!EVP_Digest(pk->data, pk->length, digest, &len, EVP_sha1(), NULL))
+ if (!(md = EVP_get_digestbyname(id)))
+ return luaL_error(L, "x509.cert:getPublicKeyDigest: %s: invalid digest type", id);
+
+ if (!EVP_Digest(pk->data, pk->length, digest, &len, md, NULL))
return auxL_error(L, auxL_EOPENSSL, "x509.cert:getPublicKeyDigest");
- lua_pushlstring(L, (char *) digest, len);
+ lua_pushlstring(L, (char *)digest, len);
return 1;
-} /* xc_setPublicKeyDigest() */
+} /* xc_getPublicKeyDigest() */
static const EVP_MD *xc_signature(lua_State *L, int index, EVP_PKEY *key) {