@@ -1636,25 +1636,28 @@ static void AddFingerprintDigest(const unsigned char* md,
16361636 }
16371637}
16381638
1639+
16391640static MaybeLocal<Object> ECPointToBuffer (Environment* env,
16401641 const EC_GROUP* group,
16411642 const EC_POINT* point,
1642- point_conversion_form_t form) {
1643+ point_conversion_form_t form,
1644+ const char ** error) {
16431645 size_t len = EC_POINT_point2oct (group, point, form, nullptr , 0 , nullptr );
16441646 if (len == 0 ) {
1645- env-> ThrowError ( " Failed to get public key length" ) ;
1647+ if (error != nullptr ) *error = " Failed to get public key length" ;
16461648 return MaybeLocal<Object>();
16471649 }
16481650 MallocedBuffer<unsigned char > buf (
16491651 len, env->isolate ()->GetArrayBufferAllocator ());
16501652 len = EC_POINT_point2oct (group, point, form, buf.data , buf.size , nullptr );
16511653 if (len == 0 ) {
1652- env-> ThrowError ( " Failed to get public key" ) ;
1654+ if (error != nullptr ) *error = " Failed to get public key" ;
16531655 return MaybeLocal<Object>();
16541656 }
16551657 return Buffer::New (env, buf.release (), len);
16561658}
16571659
1660+
16581661static Local<Object> X509ToObject (Environment* env, X509* cert) {
16591662 EscapableHandleScope scope (env->isolate ());
16601663 Local<Context> context = env->context ();
@@ -1772,10 +1775,11 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
17721775 }
17731776
17741777 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)) {
17791783 info->Set (context, env->pubkey_string (), buf).FromJust ();
17801784 }
17811785
@@ -4566,6 +4570,7 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
45664570 ECDH* ecdh;
45674571 ASSIGN_OR_RETURN_UNWRAP (&ecdh, args.Holder ());
45684572
4573+ const EC_GROUP* group = EC_KEY_get0_group (ecdh->key_ .get ());
45694574 const EC_POINT* pub = EC_KEY_get0_public_key (ecdh->key_ .get ());
45704575 if (pub == nullptr )
45714576 return env->ThrowError (" Failed to get ECDH public key" );
@@ -4574,10 +4579,11 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
45744579 uint32_t val = args[0 ].As <Uint32>()->Value ();
45754580 point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
45764581
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);
45814587}
45824588
45834589
@@ -5185,9 +5191,11 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) {
51855191 uint32_t val = args[2 ].As <Uint32>()->Value ();
51865192 point_conversion_form_t form = static_cast <point_conversion_form_t >(val);
51875193
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);
51915199}
51925200
51935201
0 commit comments