diff options
author | Tobias Nießen <tniessen@tnie.de> | 2022-05-24 14:59:55 +0300 |
---|---|---|
committer | Bryan English <bryan@bryanenglish.com> | 2022-05-30 19:33:54 +0300 |
commit | baa5d0005ad26c053a17b56a11a0c6912a2c9500 (patch) | |
tree | 3944fe7a8373ce9d864efb03f22e1d9f5e4d0c9f /src | |
parent | a07f5f28f31281c70095b0ff765e5930bad60c79 (diff) |
src: refactor GetCipherValue and related functions
Modernize and simplify GetCipherValue and its call sites.
PR-URL: https://github.com/nodejs/node/pull/43171
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/crypto/crypto_common.cc | 43 | ||||
-rw-r--r-- | src/crypto/crypto_common.h | 12 |
2 files changed, 12 insertions, 43 deletions
diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 0aaf0043666..0b172e40ee7 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<Value> GetCipherValue(Environment* env, - const SSL_CIPHER* cipher, - const char* (*getstr)(const SSL_CIPHER* cipher)) { +template <const char* (*getstr)(const SSL_CIPHER* cipher)> +MaybeLocal<Value> GetCipherValue(Environment* env, const SSL_CIPHER* cipher) { if (cipher == nullptr) return Undefined(env->isolate()); return OneByteString(env->isolate(), getstr(cipher)); } -MaybeLocal<Value> GetCipherName(Environment* env, const SSL_CIPHER* cipher) { - return GetCipherValue(env, cipher, SSL_CIPHER_get_name); -} - -MaybeLocal<Value> GetCipherStandardName( - Environment* env, - const SSL_CIPHER* cipher) { - return GetCipherValue(env, cipher, SSL_CIPHER_standard_name); -} - -MaybeLocal<Value> GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) { - return GetCipherValue(env, cipher, SSL_CIPHER_get_version); -} +constexpr auto GetCipherName = GetCipherValue<SSL_CIPHER_get_name>; +constexpr auto GetCipherStandardName = GetCipherValue<SSL_CIPHER_standard_name>; +constexpr auto GetCipherVersion = GetCipherValue<SSL_CIPHER_get_version>; StackOfX509 CloneSSLCerts(X509Pointer&& cert, const STACK_OF(X509)* const ssl_certs) { @@ -1052,18 +1041,10 @@ static MaybeLocal<Value> GetX509NameObject(Environment* env, X509* cert) { return result; } -MaybeLocal<Value> GetCipherName(Environment* env, const SSLPointer& ssl) { - return GetCipherName(env, SSL_get_current_cipher(ssl.get())); -} - -MaybeLocal<Value> GetCipherStandardName( - Environment* env, - const SSLPointer& ssl) { - return GetCipherStandardName(env, SSL_get_current_cipher(ssl.get())); -} - -MaybeLocal<Value> GetCipherVersion(Environment* env, const SSLPointer& ssl) { - return GetCipherVersion(env, SSL_get_current_cipher(ssl.get())); +template <MaybeLocal<Value> (*Get)(Environment* env, const SSL_CIPHER* cipher)> +MaybeLocal<Value> GetCurrentCipherValue(Environment* env, + const SSLPointer& ssl) { + return Get(env, SSL_get_current_cipher(ssl.get())); } MaybeLocal<Array> GetClientHelloCiphers( @@ -1109,15 +1090,15 @@ MaybeLocal<Object> GetCipherInfo(Environment* env, const SSLPointer& ssl) { if (!Set<Value>(env->context(), info, env->name_string(), - GetCipherName(env, ssl)) || + GetCurrentCipherValue<GetCipherName>(env, ssl)) || !Set<Value>(env->context(), info, env->standard_name_string(), - GetCipherStandardName(env, ssl)) || + GetCurrentCipherValue<GetCipherStandardName>(env, ssl)) || !Set<Value>(env->context(), info, env->version_string(), - GetCipherVersion(env, ssl))) { + GetCurrentCipherValue<GetCipherVersion>(env, ssl))) { return MaybeLocal<Object>(); } diff --git a/src/crypto/crypto_common.h b/src/crypto/crypto_common.h index 7843f8acd1c..792760e9707 100644 --- a/src/crypto/crypto_common.h +++ b/src/crypto/crypto_common.h @@ -74,18 +74,6 @@ v8::MaybeLocal<v8::Value> GetValidationErrorCode(Environment* env, int err); v8::MaybeLocal<v8::Value> GetCert(Environment* env, const SSLPointer& ssl); -v8::MaybeLocal<v8::Value> GetCipherName( - Environment* env, - const SSLPointer& ssl); - -v8::MaybeLocal<v8::Value> GetCipherStandardName( - Environment* env, - const SSLPointer& ssl); - -v8::MaybeLocal<v8::Value> GetCipherVersion( - Environment* env, - const SSLPointer& ssl); - v8::MaybeLocal<v8::Object> GetCipherInfo( Environment* env, const SSLPointer& ssl); |