aboutsummaryrefslogtreecommitdiffstats
path: root/util-src
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-07-02 11:51:24 +0100
committerMatthew Wild <mwild1@gmail.com>2022-07-02 11:51:24 +0100
commitd7b32f1b71f4806081a99c37296f316942fc03ac (patch)
treee9f14b439ae3f6d3529348cc0b086411d8ee2ed1 /util-src
parentba282f10702985ba67b97930ea946524fcce701e (diff)
downloadprosody-d7b32f1b71f4806081a99c37296f316942fc03ac.tar.gz
prosody-d7b32f1b71f4806081a99c37296f316942fc03ac.zip
util.crypto: Friendlier error message on incorrect key types
Diffstat (limited to 'util-src')
-rw-r--r--util-src/crypto.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/util-src/crypto.c b/util-src/crypto.c
index 49461a7e..f2192ce2 100644
--- a/util-src/crypto.c
+++ b/util-src/crypto.c
@@ -45,6 +45,8 @@ MANAGED_POINTER_ALLOCATOR(new_managed_EVP_MD_CTX, EVP_MD_CTX*, EVP_MD_CTX_new, E
MANAGED_POINTER_ALLOCATOR(new_managed_BIO_s_mem, BIO*, new_memory_BIO, BIO_free)
MANAGED_POINTER_ALLOCATOR(new_managed_EVP_CIPHER_CTX, EVP_CIPHER_CTX*, EVP_CIPHER_CTX_new, EVP_CIPHER_CTX_free)
+#define CRYPTO_KEY_TYPE_ERR "unexpected key type: got '%s', expected '%s'"
+
static EVP_PKEY* pkey_from_arg(lua_State *L, int idx, const int type, const int require_private) {
EVP_PKEY *pkey = *(EVP_PKEY**)luaL_checkudata(L, idx, PKEY_MT_TAG);
int got_type;
@@ -54,7 +56,10 @@ static EVP_PKEY* pkey_from_arg(lua_State *L, int idx, const int type, const int
lua_getfield(L, -1, "type");
got_type = lua_tointeger(L, -1);
if(got_type != type) {
- luaL_argerror(L, idx, "unexpected key type");
+ const char *got_key_type_name = OBJ_nid2sn(got_type);
+ const char *want_key_type_name = OBJ_nid2sn(type);
+ lua_pushfstring(L, CRYPTO_KEY_TYPE_ERR, got_key_type_name, want_key_type_name);
+ luaL_argerror(L, idx, lua_tostring(L, -1));
}
lua_pop(L, 1);
}