Skip to content

Commit

Permalink
src: combine GetCurveASN1Name and GetCurveNistName
Browse files Browse the repository at this point in the history
PR-URL: #42118
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
tniessen authored and sxa committed Mar 7, 2022
1 parent f0558d8 commit 4c9f2b5
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,17 +434,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()));
}

Expand Down Expand Up @@ -1425,11 +1419,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 {
Expand Down

0 comments on commit 4c9f2b5

Please sign in to comment.