@@ -5039,20 +5039,18 @@ static AllocatedBuffer ConvertSignatureToP1363(Environment* env,
50395039 const unsigned char * sig_data =
50405040 reinterpret_cast <unsigned char *>(signature.data ());
50415041
5042- ECDSA_SIG* asn1_sig = d2i_ECDSA_SIG (nullptr , &sig_data, signature.size ());
5043- if (asn1_sig == nullptr )
5042+ ECDSASigPointer asn1_sig ( d2i_ECDSA_SIG (nullptr , &sig_data, signature.size () ));
5043+ if (! asn1_sig)
50445044 return AllocatedBuffer ();
50455045
50465046 AllocatedBuffer buf = env->AllocateManaged (2 * n);
50475047 unsigned char * data = reinterpret_cast <unsigned char *>(buf.data ());
50485048
5049- const BIGNUM* r = ECDSA_SIG_get0_r (asn1_sig);
5050- const BIGNUM* s = ECDSA_SIG_get0_s (asn1_sig);
5049+ const BIGNUM* r = ECDSA_SIG_get0_r (asn1_sig. get () );
5050+ const BIGNUM* s = ECDSA_SIG_get0_s (asn1_sig. get () );
50515051 CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (r, data, n)));
50525052 CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (s, data + n, n)));
50535053
5054- ECDSA_SIG_free (asn1_sig);
5055-
50565054 return buf;
50575055}
50585056
@@ -5069,19 +5067,18 @@ static ByteSource ConvertSignatureToDER(
50695067 if (signature.length () != 2 * n)
50705068 return ByteSource ();
50715069
5072- ECDSA_SIG* asn1_sig = ECDSA_SIG_new ();
5073- CHECK_NOT_NULL (asn1_sig);
5070+ ECDSASigPointer asn1_sig ( ECDSA_SIG_new () );
5071+ CHECK (asn1_sig);
50745072 BIGNUM* r = BN_new ();
50755073 CHECK_NOT_NULL (r);
50765074 BIGNUM* s = BN_new ();
50775075 CHECK_NOT_NULL (s);
50785076 CHECK_EQ (r, BN_bin2bn (sig_data, n, r));
50795077 CHECK_EQ (s, BN_bin2bn (sig_data + n, n, s));
5080- CHECK_EQ (1 , ECDSA_SIG_set0 (asn1_sig, r, s));
5078+ CHECK_EQ (1 , ECDSA_SIG_set0 (asn1_sig. get () , r, s));
50815079
50825080 unsigned char * data = nullptr ;
5083- int len = i2d_ECDSA_SIG (asn1_sig, &data);
5084- ECDSA_SIG_free (asn1_sig);
5081+ int len = i2d_ECDSA_SIG (asn1_sig.get (), &data);
50855082
50865083 if (len <= 0 )
50875084 return ByteSource ();
0 commit comments