diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 0aaf00436666d1..0b172e40ee766b 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -314,28 +314,17 @@ bool Set( return !target->Set(context, name, value).IsNothing(); } -MaybeLocal GetCipherValue(Environment* env, - const SSL_CIPHER* cipher, - const char* (*getstr)(const SSL_CIPHER* cipher)) { +template +MaybeLocal GetCipherValue(Environment* env, const SSL_CIPHER* cipher) { if (cipher == nullptr) return Undefined(env->isolate()); return OneByteString(env->isolate(), getstr(cipher)); } -MaybeLocal GetCipherName(Environment* env, const SSL_CIPHER* cipher) { - return GetCipherValue(env, cipher, SSL_CIPHER_get_name); -} - -MaybeLocal GetCipherStandardName( - Environment* env, - const SSL_CIPHER* cipher) { - return GetCipherValue(env, cipher, SSL_CIPHER_standard_name); -} - -MaybeLocal GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) { - return GetCipherValue(env, cipher, SSL_CIPHER_get_version); -} +constexpr auto GetCipherName = GetCipherValue; +constexpr auto GetCipherStandardName = GetCipherValue; +constexpr auto GetCipherVersion = GetCipherValue; StackOfX509 CloneSSLCerts(X509Pointer&& cert, const STACK_OF(X509)* const ssl_certs) { @@ -1052,18 +1041,10 @@ static MaybeLocal GetX509NameObject(Environment* env, X509* cert) { return result; } -MaybeLocal GetCipherName(Environment* env, const SSLPointer& ssl) { - return GetCipherName(env, SSL_get_current_cipher(ssl.get())); -} - -MaybeLocal GetCipherStandardName( - Environment* env, - const SSLPointer& ssl) { - return GetCipherStandardName(env, SSL_get_current_cipher(ssl.get())); -} - -MaybeLocal GetCipherVersion(Environment* env, const SSLPointer& ssl) { - return GetCipherVersion(env, SSL_get_current_cipher(ssl.get())); +template (*Get)(Environment* env, const SSL_CIPHER* cipher)> +MaybeLocal GetCurrentCipherValue(Environment* env, + const SSLPointer& ssl) { + return Get(env, SSL_get_current_cipher(ssl.get())); } MaybeLocal GetClientHelloCiphers( @@ -1109,15 +1090,15 @@ MaybeLocal GetCipherInfo(Environment* env, const SSLPointer& ssl) { if (!Set(env->context(), info, env->name_string(), - GetCipherName(env, ssl)) || + GetCurrentCipherValue(env, ssl)) || !Set(env->context(), info, env->standard_name_string(), - GetCipherStandardName(env, ssl)) || + GetCurrentCipherValue(env, ssl)) || !Set(env->context(), info, env->version_string(), - GetCipherVersion(env, ssl))) { + GetCurrentCipherValue(env, ssl))) { return MaybeLocal(); } diff --git a/src/crypto/crypto_common.h b/src/crypto/crypto_common.h index 7843f8acd1c5d5..792760e9707328 100644 --- a/src/crypto/crypto_common.h +++ b/src/crypto/crypto_common.h @@ -74,18 +74,6 @@ v8::MaybeLocal GetValidationErrorCode(Environment* env, int err); v8::MaybeLocal GetCert(Environment* env, const SSLPointer& ssl); -v8::MaybeLocal GetCipherName( - Environment* env, - const SSLPointer& ssl); - -v8::MaybeLocal GetCipherStandardName( - Environment* env, - const SSLPointer& ssl); - -v8::MaybeLocal GetCipherVersion( - Environment* env, - const SSLPointer& ssl); - v8::MaybeLocal GetCipherInfo( Environment* env, const SSLPointer& ssl);