Use scopers a little more.
Change-Id: I51e5a7dac3ceffc41d3a7a57157a11258e65bc42 Reviewed-on: https://boringssl-review.googlesource.com/11721 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
be941d4659
commit
a7f56f0bfb
@ -1024,14 +1024,12 @@ static bool TestASN1() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test the value serializes correctly.
|
// Test the value serializes correctly.
|
||||||
CBB cbb;
|
bssl::ScopedCBB cbb;
|
||||||
uint8_t *der;
|
uint8_t *der;
|
||||||
size_t der_len;
|
size_t der_len;
|
||||||
CBB_zero(&cbb);
|
if (!CBB_init(cbb.get(), 0) ||
|
||||||
if (!CBB_init(&cbb, 0) ||
|
!BN_marshal_asn1(cbb.get(), bn.get()) ||
|
||||||
!BN_marshal_asn1(&cbb, bn.get()) ||
|
!CBB_finish(cbb.get(), &der, &der_len)) {
|
||||||
!CBB_finish(&cbb, &der, &der_len)) {
|
|
||||||
CBB_cleanup(&cbb);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bssl::UniquePtr<uint8_t> delete_der(der);
|
bssl::UniquePtr<uint8_t> delete_der(der);
|
||||||
@ -1114,16 +1112,13 @@ static bool TestASN1() {
|
|||||||
if (!bn) {
|
if (!bn) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CBB cbb;
|
bssl::ScopedCBB cbb;
|
||||||
CBB_zero(&cbb);
|
if (!CBB_init(cbb.get(), 0) ||
|
||||||
if (!CBB_init(&cbb, 0) ||
|
BN_marshal_asn1(cbb.get(), bn.get())) {
|
||||||
BN_marshal_asn1(&cbb, bn.get())) {
|
|
||||||
fprintf(stderr, "Serialized negative number.\n");
|
fprintf(stderr, "Serialized negative number.\n");
|
||||||
CBB_cleanup(&cbb);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ERR_clear_error();
|
ERR_clear_error();
|
||||||
CBB_cleanup(&cbb);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -382,9 +382,10 @@ static bssl::UniquePtr<EVP_PKEY> PrivateKeyFromPEM(const char *pem) {
|
|||||||
PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
|
PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// CertsToStack converts a vector of |X509*| to an OpenSSL STACK_OF(X509*),
|
// CertsToStack converts a vector of |X509*| to an OpenSSL STACK_OF(X509),
|
||||||
// bumping the reference counts for each certificate in question.
|
// bumping the reference counts for each certificate in question.
|
||||||
static STACK_OF(X509)* CertsToStack(const std::vector<X509*> &certs) {
|
static bssl::UniquePtr<STACK_OF(X509)> CertsToStack(
|
||||||
|
const std::vector<X509 *> &certs) {
|
||||||
bssl::UniquePtr<STACK_OF(X509)> stack(sk_X509_new_null());
|
bssl::UniquePtr<STACK_OF(X509)> stack(sk_X509_new_null());
|
||||||
if (!stack) {
|
if (!stack) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -396,12 +397,13 @@ static STACK_OF(X509)* CertsToStack(const std::vector<X509*> &certs) {
|
|||||||
X509_up_ref(cert);
|
X509_up_ref(cert);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack.release();
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRLsToStack converts a vector of |X509_CRL*| to an OpenSSL STACK_OF(X509_CRL*),
|
// CRLsToStack converts a vector of |X509_CRL*| to an OpenSSL
|
||||||
// bumping the reference counts for each CRL in question.
|
// STACK_OF(X509_CRL), bumping the reference counts for each CRL in question.
|
||||||
static STACK_OF(X509_CRL)* CRLsToStack(const std::vector<X509_CRL*> &crls) {
|
static bssl::UniquePtr<STACK_OF(X509_CRL)> CRLsToStack(
|
||||||
|
const std::vector<X509_CRL *> &crls) {
|
||||||
bssl::UniquePtr<STACK_OF(X509_CRL)> stack(sk_X509_CRL_new_null());
|
bssl::UniquePtr<STACK_OF(X509_CRL)> stack(sk_X509_CRL_new_null());
|
||||||
if (!stack) {
|
if (!stack) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -413,7 +415,7 @@ static STACK_OF(X509_CRL)* CRLsToStack(const std::vector<X509_CRL*> &crls) {
|
|||||||
X509_CRL_up_ref(crl);
|
X509_CRL_up_ref(crl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack.release();
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Verify(X509 *leaf, const std::vector<X509 *> &roots,
|
static int Verify(X509 *leaf, const std::vector<X509 *> &roots,
|
||||||
|
Loading…
Reference in New Issue
Block a user