Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: combine GetCurveASN1Name and GetCurveNistName #42118

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/crypto/crypto_common.cc
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