Skip to content

Commit

Permalink
src: combine GetCurveASN1Name and GetCurveNistName
Browse files Browse the repository at this point in the history
  • Loading branch information
tniessen committed Feb 26, 2022
1 parent debd87c commit 9704e98
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 @@ -452,17 +452,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 @@ -1413,11 +1407,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 9704e98

Please sign in to comment.