@@ -1613,24 +1613,27 @@ static void AddFingerprintDigest(const unsigned char* md,
1613
1613
}
1614
1614
}
1615
1615
1616
+
1616
1617
static MaybeLocal<Object> ECPointToBuffer (Environment* env,
1617
1618
const EC_GROUP* group,
1618
1619
const EC_POINT* point,
1619
- point_conversion_form_t form) {
1620
+ point_conversion_form_t form,
1621
+ const char ** error) {
1620
1622
size_t len = EC_POINT_point2oct (group, point, form, nullptr , 0 , nullptr );
1621
1623
if (len == 0 ) {
1622
- env-> ThrowError ( " Failed to get public key length" ) ;
1624
+ if (error != nullptr ) *error = " Failed to get public key length" ;
1623
1625
return MaybeLocal<Object>();
1624
1626
}
1625
1627
MallocedBuffer<unsigned char > buf (len);
1626
1628
len = EC_POINT_point2oct (group, point, form, buf.data , buf.size , nullptr );
1627
1629
if (len == 0 ) {
1628
- env-> ThrowError ( " Failed to get public key" ) ;
1630
+ if (error != nullptr ) *error = " Failed to get public key" ;
1629
1631
return MaybeLocal<Object>();
1630
1632
}
1631
1633
return Buffer::New (env, buf.release (), len);
1632
1634
}
1633
1635
1636
+
1634
1637
static Local<Object> X509ToObject (Environment* env, X509* cert) {
1635
1638
EscapableHandleScope scope (env->isolate ());
1636
1639
Local<Context> context = env->context ();
@@ -1748,10 +1751,11 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
1748
1751
}
1749
1752
1750
1753
const EC_POINT* pubkey = EC_KEY_get0_public_key (ec.get ());
1751
- if (pubkey != nullptr ) {
1752
- Local<Object> buf =
1753
- ECPointToBuffer (env, group, pubkey, EC_KEY_get_conv_form (ec.get ()))
1754
- .ToLocalChecked ();
1754
+ Local<Object> buf;
1755
+ if (pubkey != nullptr &&
1756
+ ECPointToBuffer (
1757
+ env, group, pubkey, EC_KEY_get_conv_form (ec.get ()), nullptr )
1758
+ .ToLocal (&buf)) {
1755
1759
info->Set (context, env->pubkey_string (), buf).FromJust ();
1756
1760
}
1757
1761
@@ -5248,6 +5252,7 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
5248
5252
ECDH* ecdh;
5249
5253
ASSIGN_OR_RETURN_UNWRAP (&ecdh, args.Holder ());
5250
5254
5255
+ const EC_GROUP* group = EC_KEY_get0_group (ecdh->key_ .get ());
5251
5256
const EC_POINT* pub = EC_KEY_get0_public_key (ecdh->key_ .get ());
5252
5257
if (pub == nullptr )
5253
5258
return env->ThrowError (" Failed to get ECDH public key" );
@@ -5256,10 +5261,11 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
5256
5261
uint32_t val = args[0 ].As <Uint32>()->Value ();
5257
5262
point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
5258
5263
5259
- MaybeLocal<Object> buf =
5260
- ECPointToBuffer (env, EC_KEY_get0_group (ecdh->key_ .get ()), pub, form);
5261
- if (buf.IsEmpty ()) return ;
5262
- args.GetReturnValue ().Set (buf.ToLocalChecked ());
5264
+ const char * error;
5265
+ Local<Object> buf;
5266
+ if (!ECPointToBuffer (env, group, pub, form, &error).ToLocal (&buf))
5267
+ return env->ThrowError (error);
5268
+ args.GetReturnValue ().Set (buf);
5263
5269
}
5264
5270
5265
5271
@@ -6147,9 +6153,11 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) {
6147
6153
uint32_t val = args[2 ].As <Uint32>()->Value ();
6148
6154
point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
6149
6155
6150
- MaybeLocal<Object> buf = ECPointToBuffer (env, group.get (), pub.get (), form);
6151
- if (buf.IsEmpty ()) return ;
6152
- args.GetReturnValue ().Set (buf.ToLocalChecked ());
6156
+ const char * error;
6157
+ Local<Object> buf;
6158
+ if (!ECPointToBuffer (env, group.get (), pub.get (), form, &error).ToLocal (&buf))
6159
+ return env->ThrowError (error);
6160
+ args.GetReturnValue ().Set (buf);
6153
6161
}
6154
6162
6155
6163
0 commit comments