@@ -1613,24 +1613,27 @@ static void AddFingerprintDigest(const unsigned char* md,
16131613 }
16141614}
16151615
1616+
16161617static MaybeLocal<Object> ECPointToBuffer (Environment* env,
16171618 const EC_GROUP* group,
16181619 const EC_POINT* point,
1619- point_conversion_form_t form) {
1620+ point_conversion_form_t form,
1621+ const char ** error) {
16201622 size_t len = EC_POINT_point2oct (group, point, form, nullptr , 0 , nullptr );
16211623 if (len == 0 ) {
1622- env-> ThrowError ( " Failed to get public key length" ) ;
1624+ if (error != nullptr ) *error = " Failed to get public key length" ;
16231625 return MaybeLocal<Object>();
16241626 }
16251627 MallocedBuffer<unsigned char > buf (len);
16261628 len = EC_POINT_point2oct (group, point, form, buf.data , buf.size , nullptr );
16271629 if (len == 0 ) {
1628- env-> ThrowError ( " Failed to get public key" ) ;
1630+ if (error != nullptr ) *error = " Failed to get public key" ;
16291631 return MaybeLocal<Object>();
16301632 }
16311633 return Buffer::New (env, buf.release (), len);
16321634}
16331635
1636+
16341637static Local<Object> X509ToObject (Environment* env, X509* cert) {
16351638 EscapableHandleScope scope (env->isolate ());
16361639 Local<Context> context = env->context ();
@@ -1748,10 +1751,11 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
17481751 }
17491752
17501753 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)) {
17551759 info->Set (context, env->pubkey_string (), buf).FromJust ();
17561760 }
17571761
@@ -5248,6 +5252,7 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
52485252 ECDH* ecdh;
52495253 ASSIGN_OR_RETURN_UNWRAP (&ecdh, args.Holder ());
52505254
5255+ const EC_GROUP* group = EC_KEY_get0_group (ecdh->key_ .get ());
52515256 const EC_POINT* pub = EC_KEY_get0_public_key (ecdh->key_ .get ());
52525257 if (pub == nullptr )
52535258 return env->ThrowError (" Failed to get ECDH public key" );
@@ -5256,10 +5261,11 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
52565261 uint32_t val = args[0 ].As <Uint32>()->Value ();
52575262 point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
52585263
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);
52635269}
52645270
52655271
@@ -6147,9 +6153,11 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) {
61476153 uint32_t val = args[2 ].As <Uint32>()->Value ();
61486154 point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
61496155
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);
61536161}
61546162
61556163
0 commit comments