From 96ec1db6a4891f9e99492c4fd3e760856619d3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Thu, 11 Jul 2024 13:50:50 +0000 Subject: [PATCH] src: avoid strcmp in ImportJWKAsymmetricKey Use std::string_view and its operator== instead of calling strcmp on a const char*. --- src/crypto/crypto_keys.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index d9bfe3ba3faa61..35474c31bfc2e3 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -509,16 +509,17 @@ Maybe ExportJWKAsymmetricKey(Environment* env, std::shared_ptr ImportJWKAsymmetricKey( Environment* env, Local jwk, - const char* kty, + std::string_view kty, const FunctionCallbackInfo& 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(); }