Skip to content

Commit ec876ee

Browse files
danbevMylesBorins
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 d865be4 commit ec876ee

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

‎src/node_crypto_common.cc‎

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

389-
MaybeLocal<Value> GetCipherName(
390-
Environment* env,
391-
constSSL_CIPHER* cipher) {
389+
MaybeLocal<Value> GetCipherValue(Environment* env,
390+
constSSL_CIPHER* cipher,
391+
constchar* (*getstr)(constSSL_CIPHER* cipher)) {
392392
if (cipher == nullptr)
393393
returnUndefined(env->isolate());
394394

395-
returnOneByteString(env->isolate(), SSL_CIPHER_get_name(cipher));
395+
returnOneByteString(env->isolate(), getstr(cipher));
396396
}
397397

398-
MaybeLocal<Value> GetCipherStandardName(
399-
Environment* env,
400-
constSSL_CIPHER* cipher) {
401-
if (cipher == nullptr)
402-
returnUndefined(env->isolate());
403-
404-
returnOneByteString(env->isolate(), SSL_CIPHER_standard_name(cipher));
398+
MaybeLocal<Value> GetCipherName(Environment* env, constSSL_CIPHER* cipher) {
399+
returnGetCipherValue(env, cipher, SSL_CIPHER_get_name);
405400
}
406401

407-
MaybeLocal<Value> GetCipherVersion(
402+
MaybeLocal<Value> GetCipherStandardName(
408403
Environment* env,
409404
constSSL_CIPHER* cipher) {
410-
if (cipher == nullptr)
411-
returnUndefined(env->isolate());
405+
returnGetCipherValue(env, cipher, SSL_CIPHER_standard_name);
406+
}
412407

413-
returnOneByteString(env->isolate(), SSL_CIPHER_get_version(cipher));
408+
MaybeLocal<Value> GetCipherVersion(Environment* env, constSSL_CIPHER* cipher) {
409+
returnGetCipherValue(env, cipher, SSL_CIPHER_get_version);
414410
}
415411

416412
StackOfX509 CloneSSLCerts(X509Pointer&& cert,

0 commit comments

Comments
 (0)