Skip to content

Commit

Permalink
src: avoid strcmp in ImportJWKAsymmetricKey
Browse files Browse the repository at this point in the history
Use std::string_view and its operator== instead of calling strcmp on a
const char*.

PR-URL: #53813
Reviewed-By: Yagiz Nizipli <[email protected]>
  • Loading branch information
tniessen authored and marco-ippolito committed Aug 19, 2024
1 parent 25e59ae commit acaf5dd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,17 @@ Maybe<void> ExportJWKAsymmetricKey(Environment* env,
std::shared_ptr<KeyObjectData> ImportJWKAsymmetricKey(
Environment* env,
Local<Object> jwk,
const char* kty,
std::string_view 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.data());
return std::shared_ptr<KeyObjectData>();
}

Expand Down

0 comments on commit acaf5dd

Please sign in to comment.