Skip to content

Commit 3901c7f

Browse files
danbevaddaleax
authored andcommitted
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: #34287 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 513ad14 commit 3901c7f

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/node_crypto_common.cc

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -385,31 +385,27 @@ Local<Value> ToV8Value(Environment* env, const BIOPointer& bio) {
385385
return ret.FromMaybe(Local<Value>());
386386
}
387387

388-
MaybeLocal<Value> GetCipherName(
389-
Environment* env,
390-
const SSL_CIPHER* cipher) {
388+
MaybeLocal<Value> GetCipherValue(Environment* env,
389+
const SSL_CIPHER* cipher,
390+
const char* (*getstr)(const SSL_CIPHER* cipher)) {
391391
if (cipher == nullptr)
392392
return Undefined(env->isolate());
393393

394-
return OneByteString(env->isolate(), SSL_CIPHER_get_name(cipher));
394+
return OneByteString(env->isolate(), getstr(cipher));
395395
}
396396

397-
MaybeLocal<Value> GetCipherStandardName(
398-
Environment* env,
399-
const SSL_CIPHER* cipher) {
400-
if (cipher == nullptr)
401-
return Undefined(env->isolate());
402-
403-
return OneByteString(env->isolate(), SSL_CIPHER_standard_name(cipher));
397+
MaybeLocal<Value> GetCipherName(Environment* env, const SSL_CIPHER* cipher) {
398+
return GetCipherValue(env, cipher, SSL_CIPHER_get_name);
404399
}
405400

406-
MaybeLocal<Value> GetCipherVersion(
401+
MaybeLocal<Value> GetCipherStandardName(
407402
Environment* env,
408403
const SSL_CIPHER* cipher) {
409-
if (cipher == nullptr)
410-
return Undefined(env->isolate());
404+
return GetCipherValue(env, cipher, SSL_CIPHER_standard_name);
405+
}
411406

412-
return OneByteString(env->isolate(), SSL_CIPHER_get_version(cipher));
407+
MaybeLocal<Value> GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) {
408+
return GetCipherValue(env, cipher, SSL_CIPHER_get_version);
413409
}
414410

415411
StackOfX509 CloneSSLCerts(X509Pointer&& cert,

0 commit comments

Comments
 (0)