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 <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d865be4 commit ec876ee

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
@@ -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-
const SSL_CIPHER* cipher) {
389+
MaybeLocal<Value> GetCipherValue(Environment* env,
390+
const SSL_CIPHER* cipher,
391+
const char* (*getstr)(const SSL_CIPHER* cipher)) {
392392
if (cipher == nullptr)
393393
return Undefined(env->isolate());
394394

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

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

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

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

416412
StackOfX509 CloneSSLCerts(X509Pointer&& cert,

0 commit comments

Comments
 (0)