From 75411fe25a467c59950363ac42c4cbbaf21d0ffd 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 b1efcbe55fa898..721c400af8ea82 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 296ae541a3e68f..19a5c06664512b 100644 --- a/src/crypto/crypto_hmac.cc +++ b/src/crypto/crypto_hmac.cc @@ -70,7 +70,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 = ""; } @@ -187,7 +188,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 97007527efd564..c79e384febafdc 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -333,7 +333,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 c4483a71744e35..d5214f2a533c47 100644 --- a/src/crypto/crypto_sig.cc +++ b/src/crypto/crypto_sig.cc @@ -648,7 +648,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(); } }