src: combine GetCurveASN1Name and GetCurveNistName

PR-URL: https://github.com/nodejs/node/pull/42118
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
pull/42145/head
Tobias Nießen 2022-02-27 15:24:52 +01:00 committed by GitHub
parent 0b5e8e01ab
commit 0f2ab70542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 13 deletions

View File

@ -438,17 +438,11 @@ void AddFingerprintDigest(
}
}
MaybeLocal<Value> GetCurveASN1Name(Environment* env, const int nid) {
const char* nist = OBJ_nid2sn(nid);
return nist != nullptr ?
MaybeLocal<Value>(OneByteString(env->isolate(), nist)) :
MaybeLocal<Value>(Undefined(env->isolate()));
}
MaybeLocal<Value> GetCurveNistName(Environment* env, const int nid) {
const char* nist = EC_curve_nid2nist(nid);
return nist != nullptr ?
MaybeLocal<Value>(OneByteString(env->isolate(), nist)) :
template <const char* (*nid2string)(int nid)>
MaybeLocal<Value> GetCurveName(Environment* env, const int nid) {
const char* name = nid2string(nid);
return name != nullptr ?
MaybeLocal<Value>(OneByteString(env->isolate(), name)) :
MaybeLocal<Value>(Undefined(env->isolate()));
}
@ -1393,11 +1387,11 @@ MaybeLocal<Object> X509ToObject(
if (!Set<Value>(context,
info,
env->asn1curve_string(),
GetCurveASN1Name(env, nid)) ||
GetCurveName<OBJ_nid2sn>(env, nid)) ||
!Set<Value>(context,
info,
env->nistcurve_string(),
GetCurveNistName(env, nid))) {
GetCurveName<EC_curve_nid2nist>(env, nid))) {
return MaybeLocal<Object>();
}
} else {