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.

PR-URL: https://github.com/nodejs/node/pull/34287
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Daniel Bevenius authored and Myles Borins committed 2020-07-16 17:09:08 -04:00
1 parent d865be4cab
commit ec876eecc0
1 file changed
+11 -15
+11 -15
View File
@@ -386,31 +386,27 @@ Local<Value> ToV8Value(Environment* env, const BIOPointer& bio) {
return ret.FromMaybe(Local<Value>());
}
MaybeLocal<Value> GetCipherName(
Environment* env,
const SSL_CIPHER* cipher) {
MaybeLocal<Value> 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<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) {
if (cipher == nullptr)
return Undefined(env->isolate());
return OneByteString(env->isolate(), SSL_CIPHER_standard_name(cipher));
return GetCipherValue(env, cipher, SSL_CIPHER_standard_name);
}
MaybeLocal<Value> GetCipherVersion(
Environment* env,
const SSL_CIPHER* cipher) {
if (cipher == nullptr)
return Undefined(env->isolate());
return OneByteString(env->isolate(), SSL_CIPHER_get_version(cipher));
MaybeLocal<Value> GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) {
return GetCipherValue(env, cipher, SSL_CIPHER_get_version);
}
StackOfX509 CloneSSLCerts(X509Pointer&& cert,