@@ -1636,25 +1636,28 @@ static void AddFingerprintDigest(const unsigned char* md,
1636
1636
}
1637
1637
}
1638
1638
1639
+
1639
1640
static MaybeLocal<Object> ECPointToBuffer (Environment* env,
1640
1641
const EC_GROUP* group,
1641
1642
const EC_POINT* point,
1642
- point_conversion_form_t form) {
1643
+ point_conversion_form_t form,
1644
+ const char ** error) {
1643
1645
size_t len = EC_POINT_point2oct (group, point, form, nullptr , 0 , nullptr );
1644
1646
if (len == 0 ) {
1645
- env-> ThrowError ( " Failed to get public key length" ) ;
1647
+ if (error != nullptr ) *error = " Failed to get public key length" ;
1646
1648
return MaybeLocal<Object>();
1647
1649
}
1648
1650
MallocedBuffer<unsigned char > buf (
1649
1651
len, env->isolate ()->GetArrayBufferAllocator ());
1650
1652
len = EC_POINT_point2oct (group, point, form, buf.data , buf.size , nullptr );
1651
1653
if (len == 0 ) {
1652
- env-> ThrowError ( " Failed to get public key" ) ;
1654
+ if (error != nullptr ) *error = " Failed to get public key" ;
1653
1655
return MaybeLocal<Object>();
1654
1656
}
1655
1657
return Buffer::New (env, buf.release (), len);
1656
1658
}
1657
1659
1660
+
1658
1661
static Local<Object> X509ToObject (Environment* env, X509* cert) {
1659
1662
EscapableHandleScope scope (env->isolate ());
1660
1663
Local<Context> context = env->context ();
@@ -1772,10 +1775,11 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
1772
1775
}
1773
1776
1774
1777
const EC_POINT* pubkey = EC_KEY_get0_public_key (ec.get ());
1775
- if (pubkey != nullptr ) {
1776
- Local<Object> buf =
1777
- ECPointToBuffer (env, group, pubkey, EC_KEY_get_conv_form (ec.get ()))
1778
- .ToLocalChecked ();
1778
+ Local<Object> buf;
1779
+ if (pubkey != nullptr &&
1780
+ ECPointToBuffer (
1781
+ env, group, pubkey, EC_KEY_get_conv_form (ec.get ()), nullptr )
1782
+ .ToLocal (&buf)) {
1779
1783
info->Set (context, env->pubkey_string (), buf).FromJust ();
1780
1784
}
1781
1785
@@ -4566,6 +4570,7 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
4566
4570
ECDH* ecdh;
4567
4571
ASSIGN_OR_RETURN_UNWRAP (&ecdh, args.Holder ());
4568
4572
4573
+ const EC_GROUP* group = EC_KEY_get0_group (ecdh->key_ .get ());
4569
4574
const EC_POINT* pub = EC_KEY_get0_public_key (ecdh->key_ .get ());
4570
4575
if (pub == nullptr )
4571
4576
return env->ThrowError (" Failed to get ECDH public key" );
@@ -4574,10 +4579,11 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
4574
4579
uint32_t val = args[0 ].As <Uint32>()->Value ();
4575
4580
point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
4576
4581
4577
- MaybeLocal<Object> buf =
4578
- ECPointToBuffer (env, EC_KEY_get0_group (ecdh->key_ .get ()), pub, form);
4579
- if (buf.IsEmpty ()) return ;
4580
- args.GetReturnValue ().Set (buf.ToLocalChecked ());
4582
+ const char * error;
4583
+ Local<Object> buf;
4584
+ if (!ECPointToBuffer (env, group, pub, form, &error).ToLocal (&buf))
4585
+ return env->ThrowError (error);
4586
+ args.GetReturnValue ().Set (buf);
4581
4587
}
4582
4588
4583
4589
@@ -5185,9 +5191,11 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) {
5185
5191
uint32_t val = args[2 ].As <Uint32>()->Value ();
5186
5192
point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
5187
5193
5188
- MaybeLocal<Object> buf = ECPointToBuffer (env, group.get (), pub.get (), form);
5189
- if (buf.IsEmpty ()) return ;
5190
- args.GetReturnValue ().Set (buf.ToLocalChecked ());
5194
+ const char * error;
5195
+ Local<Object> buf;
5196
+ if (!ECPointToBuffer (env, group.get (), pub.get (), form, &error).ToLocal (&buf))
5197
+ return env->ThrowError (error);
5198
+ args.GetReturnValue ().Set (buf);
5191
5199
}
5192
5200
5193
5201
0 commit comments