From 810df538a8b3a4462b04cdb610eb34f83e17e8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 3 Sep 2022 01:48:27 +0200 Subject: [PATCH] crypto: add digest name to INVALID_DIGEST errors We already do this in some places. This adds the digest name to remaining uses of ERR_CRYPTO_INVALID_DIGEST except for one occurrence in crypto_sig.cc that would require significant refactoring due to the unusual error handling there. PR-URL: https://github.com/nodejs/node/pull/44468 Reviewed-By: Filip Skokan Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca --- src/crypto/crypto_hkdf.cc | 2 +- src/crypto/crypto_hmac.cc | 5 +++-- src/crypto/crypto_rsa.cc | 2 +- src/crypto/crypto_sig.cc | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/crypto/crypto_hkdf.cc b/src/crypto/crypto_hkdf.cc index 081a930e69f3c4..43bf8a93505bb7 100644 --- a/src/crypto/crypto_hkdf.cc +++ b/src/crypto/crypto_hkdf.cc @@ -58,7 +58,7 @@ Maybe HKDFTraits::AdditionalConfig( Utf8Value hash(env->isolate(), args[offset]); params->digest = EVP_get_digestbyname(*hash); if (params->digest == nullptr) { - THROW_ERR_CRYPTO_INVALID_DIGEST(env); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *hash); return Nothing(); } diff --git a/src/crypto/crypto_hmac.cc b/src/crypto/crypto_hmac.cc index 2e1c97ce48036d..ed78e21f118a18 100644 --- a/src/crypto/crypto_hmac.cc +++ b/src/crypto/crypto_hmac.cc @@ -72,7 +72,8 @@ void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) { const EVP_MD* md = EVP_get_digestbyname(hash_type); if (md == nullptr) - return THROW_ERR_CRYPTO_INVALID_DIGEST(env()); + return THROW_ERR_CRYPTO_INVALID_DIGEST( + env(), "Invalid digest: %s", hash_type); if (key_len == 0) { key = ""; } @@ -189,7 +190,7 @@ Maybe HmacTraits::AdditionalConfig( Utf8Value digest(env->isolate(), args[offset + 1]); params->digest = EVP_get_digestbyname(*digest); if (params->digest == nullptr) { - THROW_ERR_CRYPTO_INVALID_DIGEST(env); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest); return Nothing(); } diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index e55c9555305373..ec339e5635d419 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -328,7 +328,7 @@ Maybe RSACipherTraits::AdditionalConfig( params->digest = EVP_get_digestbyname(*digest); if (params->digest == nullptr) { - THROW_ERR_CRYPTO_INVALID_DIGEST(env); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest); return Nothing(); } diff --git a/src/crypto/crypto_sig.cc b/src/crypto/crypto_sig.cc index 72f98788d17539..92188911b35a4d 100644 --- a/src/crypto/crypto_sig.cc +++ b/src/crypto/crypto_sig.cc @@ -647,7 +647,7 @@ Maybe SignTraits::AdditionalConfig( Utf8Value digest(env->isolate(), args[offset + 6]); params->digest = EVP_get_digestbyname(*digest); if (params->digest == nullptr) { - THROW_ERR_CRYPTO_INVALID_DIGEST(env); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest); return Nothing(); } }