@@ -5038,20 +5038,18 @@ static AllocatedBuffer ConvertSignatureToP1363(Environment* env,
5038
5038
const unsigned char * sig_data =
5039
5039
reinterpret_cast <unsigned char *>(signature.data ());
5040
5040
5041
- ECDSA_SIG* asn1_sig = d2i_ECDSA_SIG (nullptr , &sig_data, signature.size ());
5042
- if (asn1_sig == nullptr )
5041
+ ECDSASigPointer asn1_sig ( d2i_ECDSA_SIG (nullptr , &sig_data, signature.size () ));
5042
+ if (! asn1_sig)
5043
5043
return AllocatedBuffer ();
5044
5044
5045
5045
AllocatedBuffer buf = env->AllocateManaged (2 * n);
5046
5046
unsigned char * data = reinterpret_cast <unsigned char *>(buf.data ());
5047
5047
5048
- const BIGNUM* r = ECDSA_SIG_get0_r (asn1_sig);
5049
- const BIGNUM* s = ECDSA_SIG_get0_s (asn1_sig);
5048
+ const BIGNUM* r = ECDSA_SIG_get0_r (asn1_sig. get () );
5049
+ const BIGNUM* s = ECDSA_SIG_get0_s (asn1_sig. get () );
5050
5050
CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (r, data, n)));
5051
5051
CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (s, data + n, n)));
5052
5052
5053
- ECDSA_SIG_free (asn1_sig);
5054
-
5055
5053
return buf;
5056
5054
}
5057
5055
@@ -5068,19 +5066,18 @@ static ByteSource ConvertSignatureToDER(
5068
5066
if (signature.length () != 2 * n)
5069
5067
return ByteSource ();
5070
5068
5071
- ECDSA_SIG* asn1_sig = ECDSA_SIG_new ();
5072
- CHECK_NOT_NULL (asn1_sig);
5069
+ ECDSASigPointer asn1_sig ( ECDSA_SIG_new () );
5070
+ CHECK (asn1_sig);
5073
5071
BIGNUM* r = BN_new ();
5074
5072
CHECK_NOT_NULL (r);
5075
5073
BIGNUM* s = BN_new ();
5076
5074
CHECK_NOT_NULL (s);
5077
5075
CHECK_EQ (r, BN_bin2bn (sig_data, n, r));
5078
5076
CHECK_EQ (s, BN_bin2bn (sig_data + n, n, s));
5079
- CHECK_EQ (1 , ECDSA_SIG_set0 (asn1_sig, r, s));
5077
+ CHECK_EQ (1 , ECDSA_SIG_set0 (asn1_sig. get () , r, s));
5080
5078
5081
5079
unsigned char * data = nullptr ;
5082
- int len = i2d_ECDSA_SIG (asn1_sig, &data);
5083
- ECDSA_SIG_free (asn1_sig);
5080
+ int len = i2d_ECDSA_SIG (asn1_sig.get (), &data);
5084
5081
5085
5082
if (len <= 0 )
5086
5083
return ByteSource ();
0 commit comments