Skip to content

Commit

Permalink
src: add GetCipherValue function
Browse files Browse the repository at this point in the history
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: #34287
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
danbev authored and MylesBorins committed Jul 16, 2020
1 parent d865be4 commit ec876ee
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/node_crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> GetCipherStandardName(
Environment* env,
const SSL_CIPHER* cipher) {
if (cipher == nullptr)
return Undefined(env->isolate());

return OneByteString(env->isolate(), SSL_CIPHER_standard_name(cipher));
MaybeLocal<Value> GetCipherName(Environment* env, const SSL_CIPHER* cipher) {
return GetCipherValue(env, cipher, SSL_CIPHER_get_name);
}

MaybeLocal<Value> GetCipherVersion(
MaybeLocal<Value> 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<Value> GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) {
return GetCipherValue(env, cipher, SSL_CIPHER_get_version);
}

StackOfX509 CloneSSLCerts(X509Pointer&& cert,
Expand Down

0 comments on commit ec876ee

Please sign in to comment.