From 4c9f2b5d83a8115e8851ac127e598d236e04812f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 27 Feb 2022 15:24:52 +0100 Subject: [PATCH] src: combine GetCurveASN1Name and GetCurveNistName PR-URL: https://github.com/nodejs/node/pull/42118 Reviewed-By: Filip Skokan Reviewed-By: Darshan Sen --- src/crypto/crypto_common.cc | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index f3497f8ee008a7..468a0892132b14 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -434,17 +434,11 @@ void AddFingerprintDigest( } } -MaybeLocal GetCurveASN1Name(Environment* env, const int nid) { - const char* nist = OBJ_nid2sn(nid); - return nist != nullptr ? - MaybeLocal(OneByteString(env->isolate(), nist)) : - MaybeLocal(Undefined(env->isolate())); -} - -MaybeLocal GetCurveNistName(Environment* env, const int nid) { - const char* nist = EC_curve_nid2nist(nid); - return nist != nullptr ? - MaybeLocal(OneByteString(env->isolate(), nist)) : +template +MaybeLocal GetCurveName(Environment* env, const int nid) { + const char* name = nid2string(nid); + return name != nullptr ? + MaybeLocal(OneByteString(env->isolate(), name)) : MaybeLocal(Undefined(env->isolate())); } @@ -1425,11 +1419,11 @@ MaybeLocal X509ToObject( if (!Set(context, info, env->asn1curve_string(), - GetCurveASN1Name(env, nid)) || + GetCurveName(env, nid)) || !Set(context, info, env->nistcurve_string(), - GetCurveNistName(env, nid))) { + GetCurveName(env, nid))) { return MaybeLocal(); } } else {