From 62d63e77c54472cdb2254fcf11ec9516e1385b56 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 10 Jul 2020 06:34:21 +0200 Subject: [PATCH 1/2] src: add GetCipherValue function 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. --- 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..af56727398fbc4 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, + std::function getstr) { 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, From a1b206d907ba5178c80a99078e7b5bca640400d9 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 10 Jul 2020 12:26:03 +0200 Subject: [PATCH 2/2] squash!: use function pointer instead of std::function --- src/node_crypto_common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_crypto_common.cc b/src/node_crypto_common.cc index af56727398fbc4..713e79b0c92cb3 100644 --- a/src/node_crypto_common.cc +++ b/src/node_crypto_common.cc @@ -388,7 +388,7 @@ Local ToV8Value(Environment* env, const BIOPointer& bio) { MaybeLocal GetCipherValue(Environment* env, const SSL_CIPHER* cipher, - std::function getstr) { + const char* (*getstr)(const SSL_CIPHER* cipher)) { if (cipher == nullptr) return Undefined(env->isolate());