diff options
author | William Ahern <william@25thandclement.com> | 2016-11-23 17:31:50 -0800 |
---|---|---|
committer | William Ahern <william@25thandclement.com> | 2016-11-23 17:31:50 -0800 |
commit | 8db6494d91ebead6a187fb1c8dd4d4027cd6b808 (patch) | |
tree | a8d843a3867720e03d630ea0b8c6176e9395881f | |
parent | 331ff8253f0fde3aaa9e47aa801613e35e6afcf7 (diff) | |
download | luaossl-63-evp_pkey_get_default_digest_nid-getPublicKeyDigest.tar.gz luaossl-63-evp_pkey_get_default_digest_nid-getPublicKeyDigest.tar.bz2 luaossl-63-evp_pkey_get_default_digest_nid-getPublicKeyDigest.zip |
auxS_todigest and auxL_optdigest depend on compat routines63-evp_pkey_get_default_digest_nid-getPublicKeyDigest
-rw-r--r-- | src/openssl.c | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/src/openssl.c b/src/openssl.c index 1803ebd..61185cf 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
@@ -739,22 +739,7 @@ static size_t auxS_obj2txt(void *dst, size_t lim, const ASN1_OBJECT *obj) { | |||
739 | return auxS_obj2id(dst, lim, obj); | 739 | return auxS_obj2id(dst, lim, obj); |
740 | } /* auxS_obj2txt() */ | 740 | } /* auxS_obj2txt() */ |
741 | 741 | ||
742 | static const EVP_MD *auxS_todigest(const char *name, EVP_PKEY *key, const EVP_MD *def) { | 742 | static const EVP_MD *auxS_todigest(const char *name, EVP_PKEY *key, const EVP_MD *def); |
743 | const EVP_MD *md; | ||
744 | int nid; | ||
745 | |||
746 | if (name) { | ||
747 | if ((md = EVP_get_digestbyname(name))) | ||
748 | return md; | ||
749 | } else if (key) { | ||
750 | if ((EVP_PKEY_get_default_digest_nid(key, &nid) > 0)) { | ||
751 | if ((md = EVP_get_digestbynid(nid))) | ||
752 | return md; | ||
753 | } | ||
754 | } | ||
755 | |||
756 | return def; | ||
757 | } /* auxS_todigest() */ | ||
758 | 743 | ||
759 | static _Bool auxS_isoid(const char *txt) { | 744 | static _Bool auxS_isoid(const char *txt) { |
760 | return (*txt >= '0' && *txt <= '9'); | 745 | return (*txt >= '0' && *txt <= '9'); |
@@ -1159,23 +1144,7 @@ static const char *auxL_pushnid(lua_State *L, int nid) { | |||
1159 | return lua_tostring(L, -1); | 1144 | return lua_tostring(L, -1); |
1160 | } /* auxL_pushnid() */ | 1145 | } /* auxL_pushnid() */ |
1161 | 1146 | ||
1162 | static const EVP_MD *auxL_optdigest(lua_State *L, int index, EVP_PKEY *key, const EVP_MD *def) { | 1147 | static const EVP_MD *auxL_optdigest(lua_State *L, int index, EVP_PKEY *key, const EVP_MD *def); |
1163 | const char *name = luaL_optstring(L, index, NULL); | ||
1164 | const EVP_MD *md; | ||
1165 | |||
1166 | if ((md = auxS_todigest(name, key, NULL))) | ||
1167 | return md; | ||
1168 | |||
1169 | if (name) { | ||
1170 | luaL_argerror(L, index, lua_pushfstring(L, "invalid digest type (%s)", name)); | ||
1171 | NOTREACHED; | ||
1172 | } else if (key) { | ||
1173 | luaL_argerror(L, index, lua_pushfstring(L, "no digest type for key type (%d)", EVP_PKEY_base_id(key))); | ||
1174 | NOTREACHED; | ||
1175 | } | ||
1176 | |||
1177 | return def; | ||
1178 | } /* auxL_optdigest() */ | ||
1179 | 1148 | ||
1180 | 1149 | ||
1181 | /* | 1150 | /* |
@@ -1757,6 +1726,53 @@ sslerr: | |||
1757 | 1726 | ||
1758 | 1727 | ||
1759 | /* | 1728 | /* |
1729 | * Auxiliary OpenSSL API routines (with dependencies on OpenSSL compat) | ||
1730 | * | ||
1731 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
1732 | |||
1733 | static const EVP_MD *auxS_todigest(const char *name, EVP_PKEY *key, const EVP_MD *def) { | ||
1734 | const EVP_MD *md; | ||
1735 | int nid; | ||
1736 | |||
1737 | if (name) { | ||
1738 | if ((md = EVP_get_digestbyname(name))) | ||
1739 | return md; | ||
1740 | } else if (key) { | ||
1741 | if ((EVP_PKEY_get_default_digest_nid(key, &nid) > 0)) { | ||
1742 | if ((md = EVP_get_digestbynid(nid))) | ||
1743 | return md; | ||
1744 | } | ||
1745 | } | ||
1746 | |||
1747 | return def; | ||
1748 | } /* auxS_todigest() */ | ||
1749 | |||
1750 | |||
1751 | /* | ||
1752 | * Auxiliary Lua API routines (with dependencies on OpenSSL compat) | ||
1753 | * | ||
1754 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
1755 | |||
1756 | static const EVP_MD *auxL_optdigest(lua_State *L, int index, EVP_PKEY *key, const EVP_MD *def) { | ||
1757 | const char *name = luaL_optstring(L, index, NULL); | ||
1758 | const EVP_MD *md; | ||
1759 | |||
1760 | if ((md = auxS_todigest(name, key, NULL))) | ||
1761 | return md; | ||
1762 | |||
1763 | if (name) { | ||
1764 | luaL_argerror(L, index, lua_pushfstring(L, "invalid digest type (%s)", name)); | ||
1765 | NOTREACHED; | ||
1766 | } else if (key) { | ||
1767 | luaL_argerror(L, index, lua_pushfstring(L, "no digest type for key type (%d)", EVP_PKEY_base_id(key))); | ||
1768 | NOTREACHED; | ||
1769 | } | ||
1770 | |||
1771 | return def; | ||
1772 | } /* auxL_optdigest() */ | ||
1773 | |||
1774 | |||
1775 | /* | ||
1760 | * External Application Data Hooks | 1776 | * External Application Data Hooks |
1761 | * | 1777 | * |
1762 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 1778 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |