Skip to content

Commit

Permalink
src: avoid strcmp in ImportJWKAsymmetricKey
Browse files Browse the repository at this point in the history
Do not unnecessarily resolve the Utf8Value into a const char* just to
then use strcmp. Instead, just take a reference to the Utf8Value and use
its operator==.
  • Loading branch information
tniessen committed Jul 11, 2024
1 parent 9791836 commit 8ae7af2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,16 @@ Maybe<bool> ExportJWKAsymmetricKey(
std::shared_ptr<KeyObjectData> ImportJWKAsymmetricKey(
Environment* env,
Local<Object> jwk,
const char* kty,
const Utf8Value& kty,
const FunctionCallbackInfo<Value>& args,
unsigned int offset) {
if (strcmp(kty, "RSA") == 0) {
if (kty == "RSA") {
return ImportJWKRsaKey(env, jwk, args, offset);
} else if (strcmp(kty, "EC") == 0) {
} else if (kty == "EC") {
return ImportJWKEcKey(env, jwk, args, offset);
}

THROW_ERR_CRYPTO_INVALID_JWK(env, "%s is not a supported JWK key type", kty);
THROW_ERR_CRYPTO_INVALID_JWK(env, "%s is not a supported JWK key type", *kty);
return std::shared_ptr<KeyObjectData>();
}

Expand Down Expand Up @@ -1040,7 +1040,7 @@ void KeyObjectHandle::InitJWK(const FunctionCallbackInfo<Value>& args) {
return;
}
} else {
key->data_ = ImportJWKAsymmetricKey(env, input, *kty_string, args, 1);
key->data_ = ImportJWKAsymmetricKey(env, input, kty_string, args, 1);
if (!key->data_) {
// ImportJWKAsymmetricKey is responsible for throwing an appropriate error
return;
Expand Down

0 comments on commit 8ae7af2

Please sign in to comment.