diff options
author | william <william+macosx@25thandclement.com> | 2015-06-04 12:00:57 -0700 |
---|---|---|
committer | william <william+macosx@25thandclement.com> | 2015-06-04 12:00:57 -0700 |
commit | 5b33312d64d8cf001c0063d876e6e80f367b9173 (patch) | |
tree | 0c79a6727e02cf8a6e4f4e1cd99d96cb3bf6251e /src | |
parent | fde13cd3149f1e5d040a5e248bea820492b7cece (diff) | |
parent | 919cf75aa17ff885382a4dd234fc7a168c4e0972 (diff) | |
download | luaossl-5b33312d64d8cf001c0063d876e6e80f367b9173.tar.gz luaossl-5b33312d64d8cf001c0063d876e6e80f367b9173.tar.bz2 luaossl-5b33312d64d8cf001c0063d876e6e80f367b9173.zip |
Merge branch 'key-id' of git://github.com/kunkku/luaossl into kunkku-key-id
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c index a93c96c..8e95622 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -3721,6 +3721,21 @@ static int xc_setPublicKey(lua_State *L) { } /* xc_setPublicKey() */ +static int xc_getPublicKeyDigest(lua_State *L) { + ASN1_BIT_STRING *pk = ((X509 *) checksimple(L, 1, X509_CERT_CLASS))->cert_info->key->public_key; + + unsigned char digest[EVP_MAX_MD_SIZE]; + unsigned int len; + + if (!EVP_Digest(pk->data, pk->length, digest, &len, EVP_sha1(), NULL)) + return auxL_error(L, auxL_EOPENSSL, "x509.cert:getPublicKeyDigest"); + + lua_pushlstring(L, (char *) digest, len); + + return 1; +} /* xc_setPublicKeyDigest() */ + + static const EVP_MD *xc_signature(lua_State *L, int index, EVP_PKEY *key) { const char *id; const EVP_MD *md; @@ -3881,6 +3896,7 @@ static const luaL_Reg xc_methods[] = { { "isIssuedBy", &xc_isIssuedBy }, { "getPublicKey", &xc_getPublicKey }, { "setPublicKey", &xc_setPublicKey }, + { "getPublicKeyDigest", &xc_getPublicKeyDigest }, { "sign", &xc_sign }, { "text", &xc_text }, { "tostring", &xc__tostring }, |