Skip to content

Commit

Permalink
crypto: add digest name to INVALID_DIGEST errors
Browse files Browse the repository at this point in the history
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: #44468
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
tniessen authored and RafaelGSS committed Sep 7, 2022
1 parent 05006ed commit c868e36
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/crypto/crypto_hkdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Maybe<bool> 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<bool>();
}

Expand Down
5 changes: 3 additions & 2 deletions src/crypto/crypto_hmac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}
Expand Down Expand Up @@ -189,7 +190,7 @@ Maybe<bool> 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<bool>();
}

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_rsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Maybe<bool> 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<bool>();
}

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_sig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ Maybe<bool> 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<bool>();
}
}
Expand Down

0 comments on commit c868e36

Please sign in to comment.