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 <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
tniessen authored and targos committed Sep 16, 2022
1 parent c4a1a60 commit 75411fe
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 @@ -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 = "";
}
Expand Down Expand Up @@ -187,7 +188,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 @@ -333,7 +333,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 @@ -648,7 +648,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 75411fe

Please sign in to comment.