@@ -5835,7 +5835,7 @@ void VerifySpkac(const FunctionCallbackInfo<Value>& args) {
5835
5835
}
5836
5836
5837
5837
5838
- const char * ExportPublicKey (const char * data, int len) {
5838
+ char * ExportPublicKey (const char * data, int len, size_t * size ) {
5839
5839
char * buf = nullptr ;
5840
5840
EVP_PKEY* pkey = nullptr ;
5841
5841
NETSCAPE_SPKI* spki = nullptr ;
@@ -5855,12 +5855,12 @@ const char* ExportPublicKey(const char* data, int len) {
5855
5855
if (PEM_write_bio_PUBKEY (bio, pkey) <= 0 )
5856
5856
goto exit ;
5857
5857
5858
- BIO_write (bio, " \0 " , 1 );
5859
5858
BUF_MEM* ptr;
5860
5859
BIO_get_mem_ptr (bio, &ptr);
5861
5860
5862
- buf = new char [ptr->length ];
5863
- memcpy (buf, ptr->data , ptr->length );
5861
+ *size = ptr->length ;
5862
+ buf = Malloc (*size);
5863
+ memcpy (buf, ptr->data , *size);
5864
5864
5865
5865
exit :
5866
5866
if (pkey != nullptr )
@@ -5891,14 +5891,12 @@ void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
5891
5891
char * data = Buffer::Data (args[0 ]);
5892
5892
CHECK_NE (data, nullptr );
5893
5893
5894
- const char * pkey = ExportPublicKey (data, length);
5894
+ size_t pkey_size;
5895
+ char * pkey = ExportPublicKey (data, length, &pkey_size);
5895
5896
if (pkey == nullptr )
5896
5897
return args.GetReturnValue ().SetEmptyString ();
5897
5898
5898
- Local<Value> out = Encode (env->isolate (), pkey, strlen (pkey), BUFFER);
5899
-
5900
- delete[] pkey;
5901
-
5899
+ Local<Value> out = Buffer::New (env, pkey, pkey_size).ToLocalChecked ();
5902
5900
args.GetReturnValue ().Set (out);
5903
5901
}
5904
5902
0 commit comments