@@ -5041,20 +5041,18 @@ static AllocatedBuffer ConvertSignatureToP1363(Environment* env,
5041
5041
const unsigned char * sig_data =
5042
5042
reinterpret_cast <unsigned char *>(signature.data ());
5043
5043
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)
5046
5046
return AllocatedBuffer ();
5047
5047
5048
5048
AllocatedBuffer buf = env->AllocateManaged (2 * n);
5049
5049
unsigned char * data = reinterpret_cast <unsigned char *>(buf.data ());
5050
5050
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 () );
5053
5053
CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (r, data, n)));
5054
5054
CHECK_EQ (n, static_cast <unsigned int >(BN_bn2binpad (s, data + n, n)));
5055
5055
5056
- ECDSA_SIG_free (asn1_sig);
5057
-
5058
5056
return buf;
5059
5057
}
5060
5058
@@ -5071,19 +5069,18 @@ static ByteSource ConvertSignatureToDER(
5071
5069
if (signature.length () != 2 * n)
5072
5070
return ByteSource ();
5073
5071
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);
5076
5074
BIGNUM* r = BN_new ();
5077
5075
CHECK_NOT_NULL (r);
5078
5076
BIGNUM* s = BN_new ();
5079
5077
CHECK_NOT_NULL (s);
5080
5078
CHECK_EQ (r, BN_bin2bn (sig_data, n, r));
5081
5079
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));
5083
5081
5084
5082
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);
5087
5084
5088
5085
if (len <= 0 )
5089
5086
return ByteSource ();
0 commit comments