From 845411a6dd8033631a9ff0478034c0d45e869e29 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 3b35ee1ff7ba8a..d82c5510d6658a 100644 --- a/src/node_crypto_common.cc +++ b/src/node_crypto_common.cc @@ -385,31 +385,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,