Replace Scoped* heap types with bssl::UniquePtr.
Unlike the Scoped* types, bssl::UniquePtr is available to C++ users, and
offered for a large variety of types. The 'extern "C++"' trick is used
to make the C++ bits digestible to C callers that wrap header files in
'extern "C"'.
Change-Id: Ifbca4c2997d6628e33028c7d7620c72aff0f862e
Reviewed-on: https://boringssl-review.googlesource.com/10521
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/dh/dh_test.cc b/crypto/dh/dh_test.cc
index b8bfe46..12984e6 100644
--- a/crypto/dh/dh_test.cc
+++ b/crypto/dh/dh_test.cc
@@ -64,11 +64,10 @@
#include <openssl/bn.h>
#include <openssl/c++/bytestring.h>
#include <openssl/crypto.h>
+#include <openssl/dh.h>
#include <openssl/err.h>
#include <openssl/mem.h>
-#include "../test/scoped_types.h"
-
namespace bssl {
static bool RunBasicTests();
@@ -115,7 +114,7 @@
static bool RunBasicTests() {
BN_GENCB cb;
BN_GENCB_set(&cb, &GenerateCallback, stdout);
- ScopedDH a(DH_new());
+ bssl::UniquePtr<DH> a(DH_new());
if (!a || !DH_generate_parameters_ex(a.get(), 64, DH_GENERATOR_5, &cb)) {
return false;
}
@@ -143,7 +142,7 @@
BN_print_fp(stdout, a->g);
printf("\n");
- ScopedDH b(DH_new());
+ bssl::UniquePtr<DH> b(DH_new());
if (!b) {
return false;
}
@@ -437,8 +436,8 @@
for (unsigned i = 0; i < sizeof(kRFCTestData) / sizeof(RFC5114TestData); i++) {
const RFC5114TestData *td = kRFCTestData + i;
/* Set up DH structures setting key components */
- ScopedDH dhA(td->get_param(nullptr));
- ScopedDH dhB(td->get_param(nullptr));
+ bssl::UniquePtr<DH> dhA(td->get_param(nullptr));
+ bssl::UniquePtr<DH> dhB(td->get_param(nullptr));
if (!dhA || !dhB) {
fprintf(stderr, "Initialisation error RFC5114 set %u\n", i + 1);
return false;
@@ -513,8 +512,8 @@
};
static bool TestBadY() {
- ScopedDH dh(DH_get_2048_224(nullptr));
- ScopedBIGNUM pub_key(
+ bssl::UniquePtr<DH> dh(DH_get_2048_224(nullptr));
+ bssl::UniquePtr<BIGNUM> pub_key(
BN_bin2bn(kRFC5114_2048_224BadY, sizeof(kRFC5114_2048_224BadY), nullptr));
if (!dh || !pub_key || !DH_generate_key(dh.get())) {
return false;
@@ -544,7 +543,7 @@
if (!BN_hex2bn(&hex_bn, hex)) {
return false;
}
- ScopedBIGNUM free_hex_bn(hex_bn);
+ bssl::UniquePtr<BIGNUM> free_hex_bn(hex_bn);
return BN_cmp(bn, hex_bn) == 0;
}
@@ -560,7 +559,7 @@
CBS cbs;
CBS_init(&cbs, kParams, sizeof(kParams));
- ScopedDH dh(DH_parse_parameters(&cbs));
+ bssl::UniquePtr<DH> dh(DH_parse_parameters(&cbs));
if (!dh || CBS_len(&cbs) != 0 ||
!BIGNUMEqualsHex(
dh->p,
@@ -577,7 +576,7 @@
!CBB_finish(cbb.get(), &der, &der_len)) {
return false;
}
- ScopedOpenSSLBytes free_der(der);
+ bssl::UniquePtr<uint8_t> free_der(der);
if (der_len != sizeof(kParams) || memcmp(der, kParams, der_len) != 0) {
return false;
}
@@ -619,7 +618,7 @@
!CBB_finish(cbb.get(), &der, &der_len)) {
return false;
}
- ScopedOpenSSLBytes free_der2(der);
+ bssl::UniquePtr<uint8_t> free_der2(der);
if (der_len != sizeof(kParamsDSA) || memcmp(der, kParamsDSA, der_len) != 0) {
return false;
}
@@ -628,7 +627,7 @@
}
static bool TestRFC3526() {
- ScopedBIGNUM bn(BN_get_rfc3526_prime_1536(nullptr));
+ bssl::UniquePtr<BIGNUM> bn(BN_get_rfc3526_prime_1536(nullptr));
if (!bn) {
return false;
}