@@ -5041,20 +5041,18 @@ static AllocatedBuffer ConvertSignatureToP1363(Environment* env,
50415041 const unsigned char * sig_data =
50425042 reinterpret_cast <unsigned char *>(signature.data ());
50435043
5044- ECDSA_SIG* asn1_sig = d2i_ECDSA_SIG (nullptr , &sig_data, signature.size ());
5045- if (asn1_sig == nullptr )
5044+ ECDSASigPointer asn1_sig ( d2i_ECDSA_SIG (nullptr , &sig_data, signature.size () ));
5045+ if (! asn1_sig)
50465046 return AllocatedBuffer ();
50475047
50485048 AllocatedBuffer buf = env->AllocateManaged (2 * n);
50495049 unsigned char * data = reinterpret_cast <unsigned char *>(buf.data ());
50505050
5051- const BIGNUM* r = ECDSA_SIG_get0_r (asn1_sig);
5052- const BIGNUM* s = ECDSA_SIG_get0_s (asn1_sig);
5051+ const BIGNUM* r = ECDSA_SIG_get0_r (asn1_sig. get () );
5052+ const BIGNUM* s = ECDSA_SIG_get0_s (asn1_sig. get () );
50535053 CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (r, data, n)));
50545054 CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (s, data + n, n)));
50555055
5056- ECDSA_SIG_free (asn1_sig);
5057-
50585056 return buf;
50595057}
50605058
@@ -5071,19 +5069,18 @@ static ByteSource ConvertSignatureToDER(
50715069 if (signature.length () != 2 * n)
50725070 return ByteSource ();
50735071
5074- ECDSA_SIG* asn1_sig = ECDSA_SIG_new ();
5075- CHECK_NOT_NULL (asn1_sig);
5072+ ECDSASigPointer asn1_sig ( ECDSA_SIG_new () );
5073+ CHECK (asn1_sig);
50765074 BIGNUM* r = BN_new ();
50775075 CHECK_NOT_NULL (r);
50785076 BIGNUM* s = BN_new ();
50795077 CHECK_NOT_NULL (s);
50805078 CHECK_EQ (r, BN_bin2bn (sig_data, n, r));
50815079 CHECK_EQ (s, BN_bin2bn (sig_data + n, n, s));
5082- CHECK_EQ (1 , ECDSA_SIG_set0 (asn1_sig, r, s));
5080+ CHECK_EQ (1 , ECDSA_SIG_set0 (asn1_sig. get () , r, s));
50835081
50845082 unsigned char * data = nullptr ;
5085- int len = i2d_ECDSA_SIG (asn1_sig, &data);
5086- ECDSA_SIG_free (asn1_sig);
5083+ int len = i2d_ECDSA_SIG (asn1_sig.get (), &data);
50875084
50885085 if (len <= 0 )
50895086 return ByteSource ();
0 commit comments