@@ -1640,24 +1640,27 @@ static void AddFingerprintDigest(const unsigned char* md,
1640
1640
}
1641
1641
}
1642
1642
1643
+
1643
1644
static MaybeLocal<Object> ECPointToBuffer (Environment* env,
1644
1645
const EC_GROUP* group,
1645
1646
const EC_POINT* point,
1646
- point_conversion_form_t form) {
1647
+ point_conversion_form_t form,
1648
+ const char ** error) {
1647
1649
size_t len = EC_POINT_point2oct (group, point, form, nullptr , 0 , nullptr );
1648
1650
if (len == 0 ) {
1649
- env-> ThrowError ( " Failed to get public key length" ) ;
1651
+ if (error != nullptr ) *error = " Failed to get public key length" ;
1650
1652
return MaybeLocal<Object>();
1651
1653
}
1652
1654
MallocedBuffer<unsigned char > buf (len);
1653
1655
len = EC_POINT_point2oct (group, point, form, buf.data , buf.size , nullptr );
1654
1656
if (len == 0 ) {
1655
- env-> ThrowError ( " Failed to get public key" ) ;
1657
+ if (error != nullptr ) *error = " Failed to get public key" ;
1656
1658
return MaybeLocal<Object>();
1657
1659
}
1658
1660
return Buffer::New (env, buf.release (), len);
1659
1661
}
1660
1662
1663
+
1661
1664
static Local<Object> X509ToObject (Environment* env, X509* cert) {
1662
1665
EscapableHandleScope scope (env->isolate ());
1663
1666
Local<Context> context = env->context ();
@@ -1775,10 +1778,11 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
1775
1778
}
1776
1779
1777
1780
const EC_POINT* pubkey = EC_KEY_get0_public_key (ec.get ());
1778
- if (pubkey != nullptr ) {
1779
- Local<Object> buf =
1780
- ECPointToBuffer (env, group, pubkey, EC_KEY_get_conv_form (ec.get ()))
1781
- .ToLocalChecked ();
1781
+ Local<Object> buf;
1782
+ if (pubkey != nullptr &&
1783
+ ECPointToBuffer (
1784
+ env, group, pubkey, EC_KEY_get_conv_form (ec.get ()), nullptr )
1785
+ .ToLocal (&buf)) {
1782
1786
info->Set (context, env->pubkey_string (), buf).FromJust ();
1783
1787
}
1784
1788
@@ -5275,6 +5279,7 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
5275
5279
ECDH* ecdh;
5276
5280
ASSIGN_OR_RETURN_UNWRAP (&ecdh, args.Holder ());
5277
5281
5282
+ const EC_GROUP* group = EC_KEY_get0_group (ecdh->key_ .get ());
5278
5283
const EC_POINT* pub = EC_KEY_get0_public_key (ecdh->key_ .get ());
5279
5284
if (pub == nullptr )
5280
5285
return env->ThrowError (" Failed to get ECDH public key" );
@@ -5283,10 +5288,11 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
5283
5288
uint32_t val = args[0 ].As <Uint32>()->Value ();
5284
5289
point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
5285
5290
5286
- MaybeLocal<Object> buf =
5287
- ECPointToBuffer (env, EC_KEY_get0_group (ecdh->key_ .get ()), pub, form);
5288
- if (buf.IsEmpty ()) return ;
5289
- args.GetReturnValue ().Set (buf.ToLocalChecked ());
5291
+ const char * error;
5292
+ Local<Object> buf;
5293
+ if (!ECPointToBuffer (env, group, pub, form, &error).ToLocal (&buf))
5294
+ return env->ThrowError (error);
5295
+ args.GetReturnValue ().Set (buf);
5290
5296
}
5291
5297
5292
5298
@@ -6174,9 +6180,11 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) {
6174
6180
uint32_t val = args[2 ].As <Uint32>()->Value ();
6175
6181
point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
6176
6182
6177
- MaybeLocal<Object> buf = ECPointToBuffer (env, group.get (), pub.get (), form);
6178
- if (buf.IsEmpty ()) return ;
6179
- args.GetReturnValue ().Set (buf.ToLocalChecked ());
6183
+ const char * error;
6184
+ Local<Object> buf;
6185
+ if (!ECPointToBuffer (env, group.get (), pub.get (), form, &error).ToLocal (&buf))
6186
+ return env->ThrowError (error);
6187
+ args.GetReturnValue ().Set (buf);
6180
6188
}
6181
6189
6182
6190
0 commit comments