Skip to content

Commit 2be8aca

Browse files
tniessenRafaelGSS
authored andcommitted
src: simplify ECDH::GetCurves()
There is no need to explicitly branch based on num_curves or on the return value of the second call to EC_get_builtin_curves. Remove unnecessary branches and replace the loop with a functional transform. PR-URL: #44309 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 1b50ff2 commit 2be8aca

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/crypto/crypto_ec.cc

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,14 @@ void ECDH::RegisterExternalReferences(ExternalReferenceRegistry* registry) {
109109
void ECDH::GetCurves(const FunctionCallbackInfo<Value>& args) {
110110
Environment* env = Environment::GetCurrent(args);
111111
const size_t num_curves = EC_get_builtin_curves(nullptr, 0);
112-
113-
if (num_curves) {
114-
std::vector<EC_builtin_curve> curves(num_curves);
115-
116-
if (EC_get_builtin_curves(curves.data(), num_curves)) {
117-
std::vector<Local<Value>> arr(num_curves);
118-
119-
for (size_t i = 0; i < num_curves; i++)
120-
arr[i] = OneByteString(env->isolate(), OBJ_nid2sn(curves[i].nid));
121-
122-
args.GetReturnValue().Set(
123-
Array::New(env->isolate(), arr.data(), arr.size()));
124-
return;
125-
}
126-
}
127-
128-
args.GetReturnValue().Set(Array::New(env->isolate()));
112+
std::vector<EC_builtin_curve> curves(num_curves);
113+
CHECK_EQ(EC_get_builtin_curves(curves.data(), num_curves), num_curves);
114+
115+
std::vector<Local<Value>> arr(num_curves);
116+
std::transform(curves.begin(), curves.end(), arr.begin(), [env](auto& curve) {
117+
return OneByteString(env->isolate(), OBJ_nid2sn(curve.nid));
118+
});
119+
args.GetReturnValue().Set(Array::New(env->isolate(), arr.data(), arr.size()));
129120
}
130121

131122
ECDH::ECDH(Environment* env, Local<Object> wrap, ECKeyPointer&& key)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy