From acaf5dd1cd600e2fbe8d59035cc6281185ce3340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 22 Jul 2024 00:23:45 +0200 Subject: [PATCH] src: avoid strcmp in ImportJWKAsymmetricKey Use std::string_view and its operator== instead of calling strcmp on a const char*. PR-URL: https://github.com/nodejs/node/pull/53813 Reviewed-By: Yagiz Nizipli --- 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 836ae11ff27a5f..ce28ec8f37a5e4 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(); }