From f3ad306fb8c4874e620f4fb8838c9edc94930c9a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 10 Jul 2020 06:34:21 +0200 Subject: [PATCH] src: add GetCipherValue function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit extracts the code that is the same in GetCipherName, GetCipherStandardName, and GetCipherVersion into function named GetCipherValue. The motivation for this change is to improve readabilty by removing the duplicated code. PR-URL: https://github.com/nodejs/node/pull/34287 Reviewed-By: Ben Noordhuis Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- src/node_crypto_common.cc | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/node_crypto_common.cc b/src/node_crypto_common.cc index d88074dfe83c53..713e79b0c92cb3 100644 --- a/src/node_crypto_common.cc +++ b/src/node_crypto_common.cc @@ -386,31 +386,27 @@ Local ToV8Value(Environment* env, const BIOPointer& bio) { return ret.FromMaybe(Local()); } -MaybeLocal GetCipherName( - Environment* env, - const SSL_CIPHER* cipher) { +MaybeLocal GetCipherValue(Environment* env, + const SSL_CIPHER* cipher, + const char* (*getstr)(const SSL_CIPHER* cipher)) { if (cipher == nullptr) return Undefined(env->isolate()); - return OneByteString(env->isolate(), SSL_CIPHER_get_name(cipher)); + return OneByteString(env->isolate(), getstr(cipher)); } -MaybeLocal GetCipherStandardName( - Environment* env, - const SSL_CIPHER* cipher) { - if (cipher == nullptr) - return Undefined(env->isolate()); - - return OneByteString(env->isolate(), SSL_CIPHER_standard_name(cipher)); +MaybeLocal GetCipherName(Environment* env, const SSL_CIPHER* cipher) { + return GetCipherValue(env, cipher, SSL_CIPHER_get_name); } -MaybeLocal GetCipherVersion( +MaybeLocal GetCipherStandardName( Environment* env, const SSL_CIPHER* cipher) { - if (cipher == nullptr) - return Undefined(env->isolate()); + return GetCipherValue(env, cipher, SSL_CIPHER_standard_name); +} - return OneByteString(env->isolate(), SSL_CIPHER_get_version(cipher)); +MaybeLocal GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) { + return GetCipherValue(env, cipher, SSL_CIPHER_get_version); } StackOfX509 CloneSSLCerts(X509Pointer&& cert,