Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2016-07-12 00:07:19 +0300
committerDavid Benjamin <davidben@google.com>2016-07-12 02:04:52 +0300
commit09feb0f3d95a2bc58ce0faaf14256d3bd30f52a4 (patch)
treec5d03846c2bffc42b9ab9bd6b6e30e044d7962b6 /crypto
parent09eb655e5cb202878b831eadb30c92ab24960d4a (diff)
Move C++ helpers into |bssl| namespace.
We currently have the situation where the |tool| and |bssl_shim| code includes scoped_types.h from crypto/test and ssl/test. That's weird and shouldn't happen. Also, our C++ consumers might quite like to have access to the scoped types. Thus this change moves some of the template code to base.h and puts it all in a |bssl| namespace to prepare for scattering these types into their respective headers. In order that all the existing test code be able to access these types, it's all moved into the same namespace. Change-Id: I3207e29474dc5fcc344ace43119df26dae04eabb Reviewed-on: https://boringssl-review.googlesource.com/8730 Reviewed-by: David Benjamin <davidben@google.com>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/asn1/asn1_test.cc6
-rw-r--r--crypto/bio/bio_test.cc16
-rw-r--r--crypto/bn/bn_test.cc36
-rw-r--r--crypto/bytestring/bytestring_test.cc58
-rw-r--r--crypto/cipher/aead_test.cc10
-rw-r--r--crypto/cipher/cipher_test.cc6
-rw-r--r--crypto/cmac/cmac_test.cc6
-rw-r--r--crypto/curve25519/ed25519_test.cc6
-rw-r--r--crypto/curve25519/spake25519_test.cc12
-rw-r--r--crypto/dh/dh_test.cc41
-rw-r--r--crypto/digest/digest_test.cc10
-rw-r--r--crypto/ec/ec_test.cc20
-rw-r--r--crypto/ecdsa/ecdsa_test.cc21
-rw-r--r--crypto/evp/evp_extra_test.cc10
-rw-r--r--crypto/evp/evp_test.cc10
-rw-r--r--crypto/hmac/hmac_test.cc6
-rw-r--r--crypto/newhope/newhope_statistical_test.cc8
-rw-r--r--crypto/newhope/newhope_test.cc12
-rw-r--r--crypto/newhope/newhope_vectors_test.cc6
-rw-r--r--crypto/pkcs8/pkcs12_test.cc12
-rw-r--r--crypto/pkcs8/pkcs8_test.cc8
-rw-r--r--crypto/poly1305/poly1305_test.cc6
-rw-r--r--crypto/rsa/rsa_test.cc50
-rw-r--r--crypto/test/file_test.cc4
-rw-r--r--crypto/test/file_test.h5
-rw-r--r--crypto/test/scoped_types.h136
-rw-r--r--crypto/x509/x509_test.cc12
27 files changed, 299 insertions, 234 deletions
diff --git a/crypto/asn1/asn1_test.cc b/crypto/asn1/asn1_test.cc
index 8b024427..e3e310bd 100644
--- a/crypto/asn1/asn1_test.cc
+++ b/crypto/asn1/asn1_test.cc
@@ -21,6 +21,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
// kTag128 is an ASN.1 structure with a universal tag with number 128.
static const uint8_t kTag128[] = {
0x1f, 0x81, 0x00, 0x01, 0x00,
@@ -69,10 +71,12 @@ static bool TestLargeTags() {
return true;
}
+} // namespace bssl
+
int main() {
CRYPTO_library_init();
- if (!TestLargeTags()) {
+ if (!bssl::TestLargeTags()) {
return 1;
}
diff --git a/crypto/bio/bio_test.cc b/crypto/bio/bio_test.cc
index f2eb20ba..e7c061eb 100644
--- a/crypto/bio/bio_test.cc
+++ b/crypto/bio/bio_test.cc
@@ -43,6 +43,8 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
#include "../test/scoped_types.h"
+namespace bssl {
+
#if !defined(OPENSSL_WINDOWS)
static int closesocket(int sock) {
return close(sock);
@@ -339,7 +341,7 @@ static bool ReadASN1(bool should_succeed, const uint8_t *data, size_t data_len,
if (!ok) {
out = nullptr;
}
- ScopedOpenSSLBytes out_storage(out);
+ ScopedBytes out_storage(out);
if (should_succeed != (ok == 1)) {
return false;
@@ -369,7 +371,7 @@ static bool TestASN1() {
static const size_t kLargePayloadLen = 8000;
static const uint8_t kLargePrefix[] = {0x30, 0x82, kLargePayloadLen >> 8,
kLargePayloadLen & 0xff};
- ScopedOpenSSLBytes large(reinterpret_cast<uint8_t *>(
+ ScopedBytes large(reinterpret_cast<uint8_t *>(
OPENSSL_malloc(sizeof(kLargePrefix) + kLargePayloadLen)));
if (!large) {
return false;
@@ -410,6 +412,8 @@ static bool TestASN1() {
return true;
}
+} // namespace bssl
+
int main(void) {
CRYPTO_library_init();
@@ -428,10 +432,10 @@ int main(void) {
}
#endif
- if (!TestSocketConnect() ||
- !TestPrintf() ||
- !TestZeroCopyBioPairs() ||
- !TestASN1()) {
+ if (!bssl::TestSocketConnect() ||
+ !bssl::TestPrintf() ||
+ !bssl::TestZeroCopyBioPairs() ||
+ !bssl::TestASN1()) {
return 1;
}
diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc
index 3405cbdc..3028745c 100644
--- a/crypto/bn/bn_test.cc
+++ b/crypto/bn/bn_test.cc
@@ -90,6 +90,8 @@
#include "../crypto/test/test_util.h"
+namespace bssl {
+
static int HexToBIGNUM(ScopedBIGNUM *out, const char *in) {
BIGNUM *raw = NULL;
int ret = BN_hex2bn(&raw, in);
@@ -132,8 +134,8 @@ static bool ExpectBIGNUMsEqual(FileTest *t, const char *operation,
return true;
}
- ScopedOpenSSLString expected_str(BN_bn2hex(expected));
- ScopedOpenSSLString actual_str(BN_bn2hex(actual));
+ ScopedString expected_str(BN_bn2hex(expected));
+ ScopedString actual_str(BN_bn2hex(actual));
if (!expected_str || !actual_str) {
return false;
}
@@ -997,7 +999,7 @@ static bool TestASN1() {
CBB_cleanup(&cbb);
return false;
}
- ScopedOpenSSLBytes delete_der(der);
+ ScopedBytes delete_der(der);
if (der_len != test.der_len ||
memcmp(der, reinterpret_cast<const uint8_t*>(test.der), der_len) != 0) {
fprintf(stderr, "Bad serialization.\n");
@@ -1263,6 +1265,8 @@ static bool TestSmallPrime(BN_CTX *ctx) {
return true;
}
+} // namespace bssl
+
int main(int argc, char *argv[]) {
CRYPTO_library_init();
@@ -1271,24 +1275,24 @@ int main(int argc, char *argv[]) {
return 1;
}
- ScopedBN_CTX ctx(BN_CTX_new());
+ bssl::ScopedBN_CTX ctx(BN_CTX_new());
if (!ctx) {
return 1;
}
- if (!TestBN2BinPadded(ctx.get()) ||
- !TestDec2BN(ctx.get()) ||
- !TestHex2BN(ctx.get()) ||
- !TestASC2BN(ctx.get()) ||
- !TestMPI() ||
- !TestRand() ||
- !TestASN1() ||
- !TestNegativeZero(ctx.get()) ||
- !TestBadModulus(ctx.get()) ||
- !TestExpModZero() ||
- !TestSmallPrime(ctx.get())) {
+ if (!bssl::TestBN2BinPadded(ctx.get()) ||
+ !bssl::TestDec2BN(ctx.get()) ||
+ !bssl::TestHex2BN(ctx.get()) ||
+ !bssl::TestASC2BN(ctx.get()) ||
+ !bssl::TestMPI() ||
+ !bssl::TestRand() ||
+ !bssl::TestASN1() ||
+ !bssl::TestNegativeZero(ctx.get()) ||
+ !bssl::TestBadModulus(ctx.get()) ||
+ !bssl::TestExpModZero() ||
+ !bssl::TestSmallPrime(ctx.get())) {
return 1;
}
- return FileTestMain(RunTest, ctx.get(), argv[1]);
+ return bssl::FileTestMain(bssl::RunTest, ctx.get(), argv[1]);
}
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc
index 31ee51c4..95d9b85c 100644
--- a/crypto/bytestring/bytestring_test.cc
+++ b/crypto/bytestring/bytestring_test.cc
@@ -29,6 +29,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
static bool TestSkip() {
static const uint8_t kData[] = {1, 2, 3};
CBS data;
@@ -292,7 +294,7 @@ static bool TestCBBBasic() {
return false;
}
- ScopedOpenSSLBytes scoper(buf);
+ ScopedBytes scoper(buf);
return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
}
@@ -337,7 +339,7 @@ static bool TestCBBFinishChild() {
CBB_cleanup(&cbb);
return false;
}
- ScopedOpenSSLBytes scoper(out_buf);
+ ScopedBytes scoper(out_buf);
return out_size == 1 && out_buf[0] == 0;
}
@@ -370,7 +372,7 @@ static bool TestCBBPrefixed() {
return false;
}
- ScopedOpenSSLBytes scoper(buf);
+ ScopedBytes scoper(buf);
return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
}
@@ -410,7 +412,7 @@ static bool TestCBBDiscardChild() {
if (!CBB_finish(cbb.get(), &buf, &buf_len)) {
return false;
}
- ScopedOpenSSLBytes scoper(buf);
+ ScopedBytes scoper(buf);
static const uint8_t kExpected[] = {
0xaa,
@@ -456,7 +458,7 @@ static bool TestCBBMisuse() {
CBB_cleanup(&cbb);
return false;
}
- ScopedOpenSSLBytes scoper(buf);
+ ScopedBytes scoper(buf);
if (buf_len != 3 ||
memcmp(buf, "\x01\x01\x02", 3) != 0) {
@@ -480,7 +482,7 @@ static bool TestCBBASN1() {
CBB_cleanup(&cbb);
return false;
}
- ScopedOpenSSLBytes scoper(buf);
+ ScopedBytes scoper(buf);
if (buf_len != sizeof(kExpected) || memcmp(buf, kExpected, buf_len) != 0) {
return false;
@@ -555,7 +557,7 @@ static bool DoBerConvert(const char *name,
fprintf(stderr, "%s: CBS_asn1_ber_to_der failed.\n", name);
return false;
}
- ScopedOpenSSLBytes scoper(out);
+ ScopedBytes scoper(out);
if (out == NULL) {
if (ber_len != der_len ||
@@ -668,7 +670,7 @@ static bool TestImplicitString() {
int ok = CBS_get_asn1_implicit_string(&in, &out, &storage,
CBS_ASN1_CONTEXT_SPECIFIC | 0,
CBS_ASN1_OCTETSTRING);
- ScopedOpenSSLBytes scoper(storage);
+ ScopedBytes scoper(storage);
if (static_cast<bool>(ok) != test.ok) {
fprintf(stderr, "CBS_get_asn1_implicit_string unexpectedly %s\n",
@@ -747,7 +749,7 @@ static bool TestASN1Uint64() {
CBB_cleanup(&cbb);
return false;
}
- ScopedOpenSSLBytes scoper(out);
+ ScopedBytes scoper(out);
if (len != test->encoding_len || memcmp(out, test->encoding, len) != 0) {
return false;
}
@@ -797,27 +799,29 @@ static bool TestCBBReserve() {
return true;
}
+} // namespace bssl
+
int main(void) {
CRYPTO_library_init();
- if (!TestSkip() ||
- !TestGetUint() ||
- !TestGetPrefixed() ||
- !TestGetPrefixedBad() ||
- !TestGetASN1() ||
- !TestCBBBasic() ||
- !TestCBBFixed() ||
- !TestCBBFinishChild() ||
- !TestCBBMisuse() ||
- !TestCBBPrefixed() ||
- !TestCBBDiscardChild() ||
- !TestCBBASN1() ||
- !TestBerConvert() ||
- !TestImplicitString() ||
- !TestASN1Uint64() ||
- !TestGetOptionalASN1Bool() ||
- !TestZero() ||
- !TestCBBReserve()) {
+ if (!bssl::TestSkip() ||
+ !bssl::TestGetUint() ||
+ !bssl::TestGetPrefixed() ||
+ !bssl::TestGetPrefixedBad() ||
+ !bssl::TestGetASN1() ||
+ !bssl::TestCBBBasic() ||
+ !bssl::TestCBBFixed() ||
+ !bssl::TestCBBFinishChild() ||
+ !bssl::TestCBBMisuse() ||
+ !bssl::TestCBBPrefixed() ||
+ !bssl::TestCBBDiscardChild() ||
+ !bssl::TestCBBASN1() ||
+ !bssl::TestBerConvert() ||
+ !bssl::TestImplicitString() ||
+ !bssl::TestASN1Uint64() ||
+ !bssl::TestGetOptionalASN1Bool() ||
+ !bssl::TestZero() ||
+ !bssl::TestCBBReserve()) {
return 1;
}
diff --git a/crypto/cipher/aead_test.cc b/crypto/cipher/aead_test.cc
index 8bad93f5..cf0f24a6 100644
--- a/crypto/cipher/aead_test.cc
+++ b/crypto/cipher/aead_test.cc
@@ -25,6 +25,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
// This program tests an AEAD against a series of test vectors from a file,
// using the FileTest format. As an example, here's a valid test case:
//
@@ -327,7 +329,7 @@ static const struct KnownAEAD kAEADs[] = {
{ "", NULL, false },
};
-int main(int argc, char **argv) {
+static int Main(int argc, char **argv) {
CRYPTO_library_init();
if (argc != 3) {
@@ -360,3 +362,9 @@ int main(int argc, char **argv) {
return FileTestMain(TestAEAD, const_cast<EVP_AEAD*>(aead), argv[2]);
}
+
+} // namespace bssl
+
+int main(int argc, char **argv) {
+ return bssl::Main(argc, argv);
+}
diff --git a/crypto/cipher/cipher_test.cc b/crypto/cipher/cipher_test.cc
index fa384c69..221eb67e 100644
--- a/crypto/cipher/cipher_test.cc
+++ b/crypto/cipher/cipher_test.cc
@@ -65,6 +65,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
static const EVP_CIPHER *GetCipher(const std::string &name) {
if (name == "DES-CBC") {
return EVP_des_cbc();
@@ -284,6 +286,8 @@ static bool TestCipher(FileTest *t, void *arg) {
return true;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
CRYPTO_library_init();
@@ -292,5 +296,5 @@ int main(int argc, char **argv) {
return 1;
}
- return FileTestMain(TestCipher, nullptr, argv[1]);
+ return bssl::FileTestMain(bssl::TestCipher, nullptr, argv[1]);
}
diff --git a/crypto/cmac/cmac_test.cc b/crypto/cmac/cmac_test.cc
index 2496f2a9..11b7ad69 100644
--- a/crypto/cmac/cmac_test.cc
+++ b/crypto/cmac/cmac_test.cc
@@ -22,6 +22,8 @@
#include "../test/test_util.h"
+namespace bssl {
+
static void dump(const uint8_t *got, const uint8_t *want, size_t len) {
hexdump(stderr, "got :", got, len);
hexdump(stderr, "want:", want, len);
@@ -141,8 +143,10 @@ static int rfc_4493_test_vectors(void) {
return 1;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
- if (!rfc_4493_test_vectors()) {
+ if (!bssl::rfc_4493_test_vectors()) {
return 1;
}
diff --git a/crypto/curve25519/ed25519_test.cc b/crypto/curve25519/ed25519_test.cc
index 1b6a0b61..3c08cc9a 100644
--- a/crypto/curve25519/ed25519_test.cc
+++ b/crypto/curve25519/ed25519_test.cc
@@ -20,6 +20,8 @@
#include "../test/file_test.h"
+namespace bssl {
+
static bool TestSignature(FileTest *t, void *arg) {
std::vector<uint8_t> private_key, public_key, message, expected_signature;
if (!t->GetBytes(&private_key, "PRIV") ||
@@ -53,11 +55,13 @@ static bool TestSignature(FileTest *t, void *arg) {
return true;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "%s <test input.txt>\n", argv[0]);
return 1;
}
- return FileTestMain(TestSignature, nullptr, argv[1]);
+ return bssl::FileTestMain(bssl::TestSignature, nullptr, argv[1]);
}
diff --git a/crypto/curve25519/spake25519_test.cc b/crypto/curve25519/spake25519_test.cc
index d97a8602..b8742ed9 100644
--- a/crypto/curve25519/spake25519_test.cc
+++ b/crypto/curve25519/spake25519_test.cc
@@ -22,6 +22,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
struct SPAKE2Run {
bool Run() {
ScopedSPAKE2_CTX alice(SPAKE2_CTX_new(
@@ -154,13 +156,15 @@ static bool TestCorruptMessages() {
return true;
}
+} // namespace bssl
+
/* TODO(agl): add tests with fixed vectors once SPAKE2 is nailed down. */
int main(int argc, char **argv) {
- if (!TestSPAKE2() ||
- !TestWrongPassword() ||
- !TestWrongNames() ||
- !TestCorruptMessages()) {
+ if (!bssl::TestSPAKE2() ||
+ !bssl::TestWrongPassword() ||
+ !bssl::TestWrongNames() ||
+ !bssl::TestCorruptMessages()) {
return 1;
}
diff --git a/crypto/dh/dh_test.cc b/crypto/dh/dh_test.cc
index 1c244283..8fe496c9 100644
--- a/crypto/dh/dh_test.cc
+++ b/crypto/dh/dh_test.cc
@@ -71,25 +71,7 @@
#include "../test/scoped_types.h"
-static bool RunBasicTests();
-static bool RunRFC5114Tests();
-static bool TestBadY();
-static bool TestASN1();
-
-int main(int argc, char *argv[]) {
- CRYPTO_library_init();
-
- if (!RunBasicTests() ||
- !RunRFC5114Tests() ||
- !TestBadY() ||
- !TestASN1()) {
- ERR_print_errors_fp(stderr);
- return 1;
- }
-
- printf("PASS\n");
- return 0;
-}
+namespace bssl {
static int GenerateCallback(int p, int n, BN_GENCB *arg) {
char c = '*';
@@ -575,7 +557,7 @@ static bool TestASN1() {
!CBB_finish(cbb.get(), &der, &der_len)) {
return false;
}
- ScopedOpenSSLBytes free_der(der);
+ ScopedBytes free_der(der);
if (der_len != sizeof(kParams) || memcmp(der, kParams, der_len) != 0) {
return false;
}
@@ -617,10 +599,27 @@ static bool TestASN1() {
!CBB_finish(cbb.get(), &der, &der_len)) {
return false;
}
- ScopedOpenSSLBytes free_der2(der);
+ ScopedBytes free_der2(der);
if (der_len != sizeof(kParamsDSA) || memcmp(der, kParamsDSA, der_len) != 0) {
return false;
}
return true;
}
+
+} // namespace bssl
+
+int main(int argc, char *argv[]) {
+ CRYPTO_library_init();
+
+ if (!bssl::RunBasicTests() ||
+ !bssl::RunRFC5114Tests() ||
+ !bssl::TestBadY() ||
+ !bssl::TestASN1()) {
+ ERR_print_errors_fp(stderr);
+ return 1;
+ }
+
+ printf("PASS\n");
+ return 0;
+}
diff --git a/crypto/digest/digest_test.cc b/crypto/digest/digest_test.cc
index 39ceaffc..32d12d24 100644
--- a/crypto/digest/digest_test.cc
+++ b/crypto/digest/digest_test.cc
@@ -26,6 +26,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
struct MD {
// name is the name of the digest.
const char* name;
@@ -243,7 +245,7 @@ static int TestGetters() {
return true;
}
-int main(void) {
+static int Main() {
CRYPTO_library_init();
for (size_t i = 0; i < sizeof(kTestVectors) / sizeof(kTestVectors[0]); i++) {
@@ -260,3 +262,9 @@ int main(void) {
printf("PASS\n");
return 0;
}
+
+} // namespace bssl
+
+int main() {
+ return bssl::Main();
+}
diff --git a/crypto/ec/ec_test.cc b/crypto/ec/ec_test.cc
index 23befeb2..864cd499 100644
--- a/crypto/ec/ec_test.cc
+++ b/crypto/ec/ec_test.cc
@@ -26,6 +26,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
// kECKeyWithoutPublic is an ECPrivateKey with the optional publicKey field
// omitted.
static const uint8_t kECKeyWithoutPublic[] = {
@@ -161,8 +163,8 @@ static bool Testd2i_ECPrivateKey() {
fprintf(stderr, "Failed to get public key in affine coordinates.\n");
return false;
}
- ScopedOpenSSLString x_hex(BN_bn2hex(x.get()));
- ScopedOpenSSLString y_hex(BN_bn2hex(y.get()));
+ ScopedString x_hex(BN_bn2hex(x.get()));
+ ScopedString y_hex(BN_bn2hex(y.get()));
if (!x_hex || !y_hex) {
return false;
}
@@ -471,15 +473,17 @@ static bool ForEachCurve(bool (*test_func)(int nid)) {
return true;
}
+} // namespace bssl
+
int main(void) {
CRYPTO_library_init();
- if (!Testd2i_ECPrivateKey() ||
- !TestZeroPadding() ||
- !TestSpecifiedCurve() ||
- !ForEachCurve(TestSetAffine) ||
- !ForEachCurve(TestAddingEqualPoints) ||
- !TestArbitraryCurve()) {
+ if (!bssl::Testd2i_ECPrivateKey() ||
+ !bssl::TestZeroPadding() ||
+ !bssl::TestSpecifiedCurve() ||
+ !bssl::ForEachCurve(bssl::TestSetAffine) ||
+ !bssl::ForEachCurve(bssl::TestAddingEqualPoints) ||
+ !bssl::TestArbitraryCurve()) {
fprintf(stderr, "failed\n");
return 1;
}
diff --git a/crypto/ecdsa/ecdsa_test.cc b/crypto/ecdsa/ecdsa_test.cc
index 8d7827df..ad2325b6 100644
--- a/crypto/ecdsa/ecdsa_test.cc
+++ b/crypto/ecdsa/ecdsa_test.cc
@@ -64,6 +64,9 @@
#include "../test/scoped_types.h"
+
+namespace bssl {
+
enum Api {
kEncodedApi,
kRawApi,
@@ -82,7 +85,7 @@ static bool VerifyECDSASig(Api api, const uint8_t *digest,
if (!ECDSA_SIG_to_bytes(&der, &der_len, ecdsa_sig)) {
return false;
}
- ScopedOpenSSLBytes delete_der(der);
+ ScopedBytes delete_der(der);
actual_result = ECDSA_verify(0, digest, digest_len, der, der_len, eckey);
break;
}
@@ -328,7 +331,7 @@ static bool TestECDSA_SIG_max_len(size_t order_len) {
if (!ECDSA_SIG_to_bytes(&der, &der_len, sig.get())) {
return false;
}
- ScopedOpenSSLBytes delete_der(der);
+ ScopedBytes delete_der(der);
size_t max_len = ECDSA_SIG_max_len(order_len);
if (max_len != der_len) {
@@ -340,6 +343,8 @@ static bool TestECDSA_SIG_max_len(size_t order_len) {
return true;
}
+} // namespace bssl
+
static size_t BitsToBytes(size_t bits) {
return (bits / 8) + (7 + (bits % 8)) / 8;
}
@@ -347,12 +352,12 @@ static size_t BitsToBytes(size_t bits) {
int main(void) {
CRYPTO_library_init();
- if (!TestBuiltin(stdout) ||
- !TestECDSA_SIG_max_len(BitsToBytes(224)) ||
- !TestECDSA_SIG_max_len(BitsToBytes(256)) ||
- !TestECDSA_SIG_max_len(BitsToBytes(384)) ||
- !TestECDSA_SIG_max_len(BitsToBytes(521)) ||
- !TestECDSA_SIG_max_len(BitsToBytes(10000))) {
+ if (!bssl::TestBuiltin(stdout) ||
+ !bssl::TestECDSA_SIG_max_len(BitsToBytes(224)) ||
+ !bssl::TestECDSA_SIG_max_len(BitsToBytes(256)) ||
+ !bssl::TestECDSA_SIG_max_len(BitsToBytes(384)) ||
+ !bssl::TestECDSA_SIG_max_len(BitsToBytes(521)) ||
+ !bssl::TestECDSA_SIG_max_len(BitsToBytes(10000))) {
printf("\nECDSA test failed\n");
ERR_print_errors_fp(stdout);
return 1;
diff --git a/crypto/evp/evp_extra_test.cc b/crypto/evp/evp_extra_test.cc
index 9bc36ad8..2253c56b 100644
--- a/crypto/evp/evp_extra_test.cc
+++ b/crypto/evp/evp_extra_test.cc
@@ -30,6 +30,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
// kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
// should never use this key anywhere but in an example.
static const uint8_t kExampleRSAKeyDER[] = {
@@ -671,7 +673,7 @@ static bool Testd2i_PrivateKey(void) {
return true;
}
-int main(void) {
+static int Main() {
CRYPTO_library_init();
if (!TestEVP_DigestSignInit()) {
@@ -719,3 +721,9 @@ int main(void) {
printf("PASS\n");
return 0;
}
+
+} // namespace bssl
+
+int main() {
+ return bssl::Main();
+}
diff --git a/crypto/evp/evp_test.cc b/crypto/evp/evp_test.cc
index b01d1e47..9b8a6839 100644
--- a/crypto/evp/evp_test.cc
+++ b/crypto/evp/evp_test.cc
@@ -77,6 +77,8 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
#include "../test/scoped_types.h"
+namespace bssl {
+
// evp_test dispatches between multiple test types. PrivateKey tests take a key
// name parameter and single block, decode it as a PEM private key, and save it
// under that key name. Decrypt, Sign, and Verify tests take a previously
@@ -149,7 +151,7 @@ static bool ImportKey(FileTest *t, KeyMap *key_map,
!CBB_finish(cbb.get(), &der, &der_len)) {
return false;
}
- ScopedOpenSSLBytes free_der(der);
+ ScopedBytes free_der(der);
std::vector<uint8_t> output = input;
if (t->HasAttribute("Output") &&
@@ -253,6 +255,8 @@ static bool TestEVP(FileTest *t, void *arg) {
return true;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
CRYPTO_library_init();
if (argc != 2) {
@@ -260,6 +264,6 @@ int main(int argc, char **argv) {
return 1;
}
- KeyMap map;
- return FileTestMain(TestEVP, &map, argv[1]);
+ bssl::KeyMap map;
+ return bssl::FileTestMain(bssl::TestEVP, &map, argv[1]);
}
diff --git a/crypto/hmac/hmac_test.cc b/crypto/hmac/hmac_test.cc
index da390ef8..ba84cc22 100644
--- a/crypto/hmac/hmac_test.cc
+++ b/crypto/hmac/hmac_test.cc
@@ -68,6 +68,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
static const EVP_MD *GetDigest(const std::string &name) {
if (name == "MD5") {
return EVP_md5();
@@ -152,6 +154,8 @@ static bool TestHMAC(FileTest *t, void *arg) {
return true;
}
+} // namespace bssl
+
int main(int argc, char *argv[]) {
CRYPTO_library_init();
@@ -160,5 +164,5 @@ int main(int argc, char *argv[]) {
return 1;
}
- return FileTestMain(TestHMAC, nullptr, argv[1]);
+ return bssl::FileTestMain(bssl::TestHMAC, nullptr, argv[1]);
}
diff --git a/crypto/newhope/newhope_statistical_test.cc b/crypto/newhope/newhope_statistical_test.cc
index 44fac48a..d3a54430 100644
--- a/crypto/newhope/newhope_statistical_test.cc
+++ b/crypto/newhope/newhope_statistical_test.cc
@@ -25,6 +25,8 @@
#include "internal.h"
+namespace bssl {
+
static const unsigned kNumTests = 1000;
static bool TestNoise(void) {
@@ -146,9 +148,11 @@ static bool TestKeys(void) {
return true;
}
+} // namespace bssl
+
int main(void) {
- if (!TestKeys() ||
- !TestNoise()) {
+ if (!bssl::TestKeys() ||
+ !bssl::TestNoise()) {
return 1;
}
printf("PASS\n");
diff --git a/crypto/newhope/newhope_test.cc b/crypto/newhope/newhope_test.cc
index 6637393f..d94eee8f 100644
--- a/crypto/newhope/newhope_test.cc
+++ b/crypto/newhope/newhope_test.cc
@@ -23,6 +23,8 @@
#include "internal.h"
+namespace bssl {
+
// Set to 10 for quick execution. Tested up to 1,000,000.
static const int kNumTests = 10;
@@ -128,11 +130,13 @@ static bool TestInvalidAcceptMsg(void) {
return true;
}
+} // namespace bssl
+
int main(void) {
- for (int i = 0; i < kNumTests; i++) {
- if (!TestKeys() ||
- !TestInvalidSK() ||
- !TestInvalidAcceptMsg()) {
+ for (int i = 0; i < bssl::kNumTests; i++) {
+ if (!bssl::TestKeys() ||
+ !bssl::TestInvalidSK() ||
+ !bssl::TestInvalidAcceptMsg()) {
return 1;
}
}
diff --git a/crypto/newhope/newhope_vectors_test.cc b/crypto/newhope/newhope_vectors_test.cc
index fe84cd4b..691d693b 100644
--- a/crypto/newhope/newhope_vectors_test.cc
+++ b/crypto/newhope/newhope_vectors_test.cc
@@ -24,6 +24,8 @@
#include "internal.h"
+namespace bssl {
+
static bool TestNewhope(FileTest *t, void *arg) {
ScopedNEWHOPE_POLY a(NEWHOPE_POLY_new());
ScopedNEWHOPE_POLY s(NEWHOPE_POLY_new()), sp(NEWHOPE_POLY_new());
@@ -110,6 +112,8 @@ static bool TestNewhope(FileTest *t, void *arg) {
}
}
+} // namespace bssl
+
int main(int argc, char **argv) {
CRYPTO_library_init();
@@ -118,5 +122,5 @@ int main(int argc, char **argv) {
return 1;
}
- return FileTestMain(TestNewhope, nullptr, argv[1]);
+ return bssl::FileTestMain(bssl::TestNewhope, nullptr, argv[1]);
}
diff --git a/crypto/pkcs8/pkcs12_test.cc b/crypto/pkcs8/pkcs12_test.cc
index 17bcd273..10694446 100644
--- a/crypto/pkcs8/pkcs12_test.cc
+++ b/crypto/pkcs8/pkcs12_test.cc
@@ -681,6 +681,8 @@ static const uint8_t kWindows[] = {
0xfe, 0x3a, 0x66, 0x47, 0x40, 0x49, 0x02, 0x02, 0x07, 0xd0,
};
+namespace bssl {
+
static const char kPassword[] = "foo";
static bool Test(const char *name, const uint8_t *der, size_t der_len) {
@@ -755,13 +757,15 @@ static bool TestCompat(const uint8_t *der, size_t der_len) {
return true;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
CRYPTO_library_init();
- if (!Test("OpenSSL", kOpenSSL, sizeof(kOpenSSL)) ||
- !Test("NSS", kNSS, sizeof(kNSS)) ||
- !Test("Windows", kWindows, sizeof(kWindows)) ||
- !TestCompat(kWindows, sizeof(kWindows))) {
+ if (!bssl::Test("OpenSSL", kOpenSSL, sizeof(kOpenSSL)) ||
+ !bssl::Test("NSS", kNSS, sizeof(kNSS)) ||
+ !bssl::Test("Windows", kWindows, sizeof(kWindows)) ||
+ !bssl::TestCompat(kWindows, sizeof(kWindows))) {
return 1;
}
diff --git a/crypto/pkcs8/pkcs8_test.cc b/crypto/pkcs8/pkcs8_test.cc
index 7a88ddf4..e54a6997 100644
--- a/crypto/pkcs8/pkcs8_test.cc
+++ b/crypto/pkcs8/pkcs8_test.cc
@@ -62,7 +62,9 @@ static const uint8_t kDER[] = {
0xd6, 0x2d,
};
-static bool test(const uint8_t *der, size_t der_len) {
+namespace bssl {
+
+static bool Test(const uint8_t *der, size_t der_len) {
const uint8_t *data = der;
ScopedX509_SIG sig(d2i_X509_SIG(NULL, &data, der_len));
if (sig.get() == NULL || data != der + der_len) {
@@ -81,8 +83,10 @@ static bool test(const uint8_t *der, size_t der_len) {
return true;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
- if (!test(kDER, sizeof(kDER))) {
+ if (!bssl::Test(kDER, sizeof(kDER))) {
return 1;
}
diff --git a/crypto/poly1305/poly1305_test.cc b/crypto/poly1305/poly1305_test.cc
index 2c25e93b..a3272250 100644
--- a/crypto/poly1305/poly1305_test.cc
+++ b/crypto/poly1305/poly1305_test.cc
@@ -24,6 +24,8 @@
#include "../test/file_test.h"
+namespace bssl {
+
static bool TestSIMD(FileTest *t, unsigned excess,
const std::vector<uint8_t> &key,
const std::vector<uint8_t> &in,
@@ -119,6 +121,8 @@ static bool TestPoly1305(FileTest *t, void *arg) {
return true;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
CRYPTO_library_init();
@@ -127,5 +131,5 @@ int main(int argc, char **argv) {
return 1;
}
- return FileTestMain(TestPoly1305, nullptr, argv[1]);
+ return bssl::FileTestMain(bssl::TestPoly1305, nullptr, argv[1]);
}
diff --git a/crypto/rsa/rsa_test.cc b/crypto/rsa/rsa_test.cc
index 62177a4c..5307f2cb 100644
--- a/crypto/rsa/rsa_test.cc
+++ b/crypto/rsa/rsa_test.cc
@@ -523,6 +523,8 @@ static const uint8_t kExponent1RSAKey[] = {
0xdd, 0x02, 0x01, 0x01,
};
+namespace bssl {
+
static bool TestRSA(const uint8_t *der, size_t der_len,
const uint8_t *oaep_ciphertext,
size_t oaep_ciphertext_len) {
@@ -855,7 +857,7 @@ static bool TestASN1() {
if (!RSA_private_key_to_bytes(&der, &der_len, rsa.get())) {
return false;
}
- ScopedOpenSSLBytes delete_der(der);
+ ScopedBytes delete_der(der);
if (der_len != sizeof(kKey1) - 1 || memcmp(der, kKey1, der_len) != 0) {
return false;
}
@@ -878,7 +880,7 @@ static bool TestASN1() {
if (!RSA_public_key_to_bytes(&der2, &der2_len, rsa.get())) {
return false;
}
- ScopedOpenSSLBytes delete_der2(der2);
+ ScopedBytes delete_der2(der2);
if (der_len != der2_len || memcmp(der, der2, der_len) != 0) {
return false;
}
@@ -922,30 +924,32 @@ static bool TestBadExponent() {
return true;
}
+} // namespace bssl
+
int main(int argc, char *argv[]) {
CRYPTO_library_init();
- if (!TestRSA(kKey1, sizeof(kKey1) - 1, kOAEPCiphertext1,
- sizeof(kOAEPCiphertext1) - 1) ||
- !TestRSA(kKey2, sizeof(kKey2) - 1, kOAEPCiphertext2,
- sizeof(kOAEPCiphertext2) - 1) ||
- !TestRSA(kKey3, sizeof(kKey3) - 1, kOAEPCiphertext3,
- sizeof(kOAEPCiphertext3) - 1) ||
- !TestOnlyDGiven() ||
- !TestRecoverCRTParams() ||
- !TestBadKey() ||
- !TestMultiPrimeKey(2, kTwoPrimeKey, sizeof(kTwoPrimeKey) - 1,
- kTwoPrimeEncryptedMessage,
- sizeof(kTwoPrimeEncryptedMessage)) ||
- !TestMultiPrimeKey(3, kThreePrimeKey, sizeof(kThreePrimeKey) - 1,
- kThreePrimeEncryptedMessage,
- sizeof(kThreePrimeEncryptedMessage)) ||
- !TestMultiPrimeKey(6, kSixPrimeKey, sizeof(kSixPrimeKey) - 1,
- kSixPrimeEncryptedMessage,
- sizeof(kSixPrimeEncryptedMessage)) ||
- !TestMultiPrimeKeygen() ||
- !TestASN1() ||
- !TestBadExponent()) {
+ if (!bssl::TestRSA(kKey1, sizeof(kKey1) - 1, kOAEPCiphertext1,
+ sizeof(kOAEPCiphertext1) - 1) ||
+ !bssl::TestRSA(kKey2, sizeof(kKey2) - 1, kOAEPCiphertext2,
+ sizeof(kOAEPCiphertext2) - 1) ||
+ !bssl::TestRSA(kKey3, sizeof(kKey3) - 1, kOAEPCiphertext3,
+ sizeof(kOAEPCiphertext3) - 1) ||
+ !bssl::TestOnlyDGiven() ||
+ !bssl::TestRecoverCRTParams() ||
+ !bssl::TestBadKey() ||
+ !bssl::TestMultiPrimeKey(2, kTwoPrimeKey, sizeof(kTwoPrimeKey) - 1,
+ kTwoPrimeEncryptedMessage,
+ sizeof(kTwoPrimeEncryptedMessage)) ||
+ !bssl::TestMultiPrimeKey(3, kThreePrimeKey, sizeof(kThreePrimeKey) - 1,
+ kThreePrimeEncryptedMessage,
+ sizeof(kThreePrimeEncryptedMessage)) ||
+ !bssl::TestMultiPrimeKey(6, kSixPrimeKey, sizeof(kSixPrimeKey) - 1,
+ kSixPrimeEncryptedMessage,
+ sizeof(kSixPrimeEncryptedMessage)) ||
+ !bssl::TestMultiPrimeKeygen() ||
+ !bssl::TestASN1() ||
+ !bssl::TestBadExponent()) {
return 1;
}
diff --git a/crypto/test/file_test.cc b/crypto/test/file_test.cc
index d684aa09..7e99316d 100644
--- a/crypto/test/file_test.cc
+++ b/crypto/test/file_test.cc
@@ -25,6 +25,8 @@
#include <openssl/err.h>
+namespace bssl {
+
FileTest::FileTest(const char *path) {
file_ = fopen(path, "r");
if (file_ == nullptr) {
@@ -300,3 +302,5 @@ int FileTestMain(bool (*run_test)(FileTest *t, void *arg), void *arg,
printf("PASS\n");
return 0;
}
+
+} // namespace bssl
diff --git a/crypto/test/file_test.h b/crypto/test/file_test.h
index a8591277..447b1ee6 100644
--- a/crypto/test/file_test.h
+++ b/crypto/test/file_test.h
@@ -30,6 +30,9 @@ OPENSSL_MSVC_PRAGMA(warning(disable: 4702))
OPENSSL_MSVC_PRAGMA(warning(pop))
+
+namespace bssl {
+
// File-based test framework.
//
// This module provides a file-based test framework. The file format is based on
@@ -153,5 +156,7 @@ class FileTest {
int FileTestMain(bool (*run_test)(FileTest *t, void *arg), void *arg,
const char *path);
+} // namespace bssl
+
#endif /* OPENSSL_HEADER_CRYPTO_TEST_FILE_TEST_H */
diff --git a/crypto/test/scoped_types.h b/crypto/test/scoped_types.h
index 2a2c3713..7e4a48e8 100644
--- a/crypto/test/scoped_types.h
+++ b/crypto/test/scoped_types.h
@@ -15,6 +15,8 @@
#ifndef OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
#define OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
+#include <openssl/base.h>
+
#include <stdint.h>
#include <stdio.h>
@@ -40,28 +42,7 @@
#include <openssl/stack.h>
#include <openssl/x509.h>
-
-template<typename T, void (*func)(T*)>
-struct OpenSSLDeleter {
- void operator()(T *obj) {
- func(obj);
- }
-};
-
-template<typename StackType, typename T, void (*func)(T*)>
-struct OpenSSLStackDeleter {
- void operator()(StackType *obj) {
- sk_pop_free(reinterpret_cast<_STACK*>(obj),
- reinterpret_cast<void (*)(void *)>(func));
- }
-};
-
-template<typename T>
-struct OpenSSLFree {
- void operator()(T *buf) {
- OPENSSL_free(buf);
- }
-};
+namespace bssl {
struct FileCloser {
void operator()(FILE *file) {
@@ -69,77 +50,48 @@ struct FileCloser {
}
};
-template<typename T, void (*func)(T*)>
-using ScopedOpenSSLType = std::unique_ptr<T, OpenSSLDeleter<T, func>>;
-
-template<typename StackType, typename T, void (*func)(T*)>
-using ScopedOpenSSLStack =
- std::unique_ptr<StackType, OpenSSLStackDeleter<StackType, T, func>>;
-
-template<typename T, typename CleanupRet, void (*init_func)(T*),
- CleanupRet (*cleanup_func)(T*)>
-class ScopedOpenSSLContext {
- public:
- ScopedOpenSSLContext() {
- init_func(&ctx_);
- }
- ~ScopedOpenSSLContext() {
- cleanup_func(&ctx_);
- }
-
- T *get() { return &ctx_; }
- const T *get() const { return &ctx_; }
-
- void Reset() {
- cleanup_func(&ctx_);
- init_func(&ctx_);
- }
-
- private:
- T ctx_;
-};
-
-using ScopedASN1_TYPE = ScopedOpenSSLType<ASN1_TYPE, ASN1_TYPE_free>;
-using ScopedBIO = ScopedOpenSSLType<BIO, BIO_vfree>;
-using ScopedBIGNUM = ScopedOpenSSLType<BIGNUM, BN_free>;
-using ScopedBN_CTX = ScopedOpenSSLType<BN_CTX, BN_CTX_free>;
-using ScopedBN_MONT_CTX = ScopedOpenSSLType<BN_MONT_CTX, BN_MONT_CTX_free>;
-using ScopedCMAC_CTX = ScopedOpenSSLType<CMAC_CTX, CMAC_CTX_free>;
-using ScopedDH = ScopedOpenSSLType<DH, DH_free>;
-using ScopedECDSA_SIG = ScopedOpenSSLType<ECDSA_SIG, ECDSA_SIG_free>;
-using ScopedEC_GROUP = ScopedOpenSSLType<EC_GROUP, EC_GROUP_free>;
-using ScopedEC_KEY = ScopedOpenSSLType<EC_KEY, EC_KEY_free>;
-using ScopedEC_POINT = ScopedOpenSSLType<EC_POINT, EC_POINT_free>;
-using ScopedEVP_PKEY = ScopedOpenSSLType<EVP_PKEY, EVP_PKEY_free>;
-using ScopedEVP_PKEY_CTX = ScopedOpenSSLType<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
-using ScopedNEWHOPE_POLY = ScopedOpenSSLType<NEWHOPE_POLY, NEWHOPE_POLY_free>;
-using ScopedPKCS8_PRIV_KEY_INFO = ScopedOpenSSLType<PKCS8_PRIV_KEY_INFO,
- PKCS8_PRIV_KEY_INFO_free>;
-using ScopedPKCS12 = ScopedOpenSSLType<PKCS12, PKCS12_free>;
-using ScopedSPAKE2_CTX = ScopedOpenSSLType<SPAKE2_CTX, SPAKE2_CTX_free>;
-using ScopedRSA = ScopedOpenSSLType<RSA, RSA_free>;
-using ScopedX509 = ScopedOpenSSLType<X509, X509_free>;
-using ScopedX509_ALGOR = ScopedOpenSSLType<X509_ALGOR, X509_ALGOR_free>;
-using ScopedX509_SIG = ScopedOpenSSLType<X509_SIG, X509_SIG_free>;
-using ScopedX509_STORE_CTX = ScopedOpenSSLType<X509_STORE_CTX, X509_STORE_CTX_free>;
-
-using ScopedX509Stack = ScopedOpenSSLStack<STACK_OF(X509), X509, X509_free>;
-
-using ScopedCBB = ScopedOpenSSLContext<CBB, void, CBB_zero, CBB_cleanup>;
-using ScopedEVP_AEAD_CTX = ScopedOpenSSLContext<EVP_AEAD_CTX, void,
- EVP_AEAD_CTX_zero,
- EVP_AEAD_CTX_cleanup>;
-using ScopedEVP_CIPHER_CTX = ScopedOpenSSLContext<EVP_CIPHER_CTX, int,
- EVP_CIPHER_CTX_init,
- EVP_CIPHER_CTX_cleanup>;
-using ScopedEVP_MD_CTX = ScopedOpenSSLContext<EVP_MD_CTX, int, EVP_MD_CTX_init,
- EVP_MD_CTX_cleanup>;
-using ScopedHMAC_CTX = ScopedOpenSSLContext<HMAC_CTX, void, HMAC_CTX_init,
- HMAC_CTX_cleanup>;
-
-using ScopedOpenSSLBytes = std::unique_ptr<uint8_t, OpenSSLFree<uint8_t>>;
-using ScopedOpenSSLString = std::unique_ptr<char, OpenSSLFree<char>>;
+using ScopedASN1_TYPE = ScopedType<ASN1_TYPE, ASN1_TYPE_free>;
+using ScopedBIO = ScopedType<BIO, BIO_vfree>;
+using ScopedBIGNUM = ScopedType<BIGNUM, BN_free>;
+using ScopedBN_CTX = ScopedType<BN_CTX, BN_CTX_free>;
+using ScopedBN_MONT_CTX = ScopedType<BN_MONT_CTX, BN_MONT_CTX_free>;
+using ScopedCMAC_CTX = ScopedType<CMAC_CTX, CMAC_CTX_free>;
+using ScopedDH = ScopedType<DH, DH_free>;
+using ScopedECDSA_SIG = ScopedType<ECDSA_SIG, ECDSA_SIG_free>;
+using ScopedEC_GROUP = ScopedType<EC_GROUP, EC_GROUP_free>;
+using ScopedEC_KEY = ScopedType<EC_KEY, EC_KEY_free>;
+using ScopedEC_POINT = ScopedType<EC_POINT, EC_POINT_free>;
+using ScopedEVP_PKEY = ScopedType<EVP_PKEY, EVP_PKEY_free>;
+using ScopedEVP_PKEY_CTX = ScopedType<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
+using ScopedNEWHOPE_POLY = ScopedType<NEWHOPE_POLY, NEWHOPE_POLY_free>;
+using ScopedPKCS8_PRIV_KEY_INFO =
+ ScopedType<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free>;
+using ScopedPKCS12 = ScopedType<PKCS12, PKCS12_free>;
+using ScopedSPAKE2_CTX = ScopedType<SPAKE2_CTX, SPAKE2_CTX_free>;
+using ScopedRSA = ScopedType<RSA, RSA_free>;
+using ScopedX509 = ScopedType<X509, X509_free>;
+using ScopedX509_ALGOR = ScopedType<X509_ALGOR, X509_ALGOR_free>;
+using ScopedX509_SIG = ScopedType<X509_SIG, X509_SIG_free>;
+using ScopedX509_STORE_CTX = ScopedType<X509_STORE_CTX, X509_STORE_CTX_free>;
+
+using ScopedX509Stack = ScopedStack<STACK_OF(X509), X509, X509_free>;
+
+using ScopedCBB = ScopedContext<CBB, void, CBB_zero, CBB_cleanup>;
+using ScopedEVP_AEAD_CTX =
+ ScopedContext<EVP_AEAD_CTX, void, EVP_AEAD_CTX_zero, EVP_AEAD_CTX_cleanup>;
+using ScopedEVP_CIPHER_CTX =
+ ScopedContext<EVP_CIPHER_CTX, int, EVP_CIPHER_CTX_init,
+ EVP_CIPHER_CTX_cleanup>;
+using ScopedEVP_MD_CTX =
+ ScopedContext<EVP_MD_CTX, int, EVP_MD_CTX_init, EVP_MD_CTX_cleanup>;
+using ScopedHMAC_CTX =
+ ScopedContext<HMAC_CTX, void, HMAC_CTX_init, HMAC_CTX_cleanup>;
+
+using ScopedBytes = std::unique_ptr<uint8_t, Free<uint8_t>>;
+using ScopedString = std::unique_ptr<char, Free<char>>;
using ScopedFILE = std::unique_ptr<FILE, FileCloser>;
+} // namespace bssl
+
#endif // OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
diff --git a/crypto/x509/x509_test.cc b/crypto/x509/x509_test.cc
index 650163a8..cb28df70 100644
--- a/crypto/x509/x509_test.cc
+++ b/crypto/x509/x509_test.cc
@@ -27,6 +27,8 @@
#include "../test/scoped_types.h"
+namespace bssl {
+
static const char kCrossSigningRootPEM[] =
"-----BEGIN CERTIFICATE-----\n"
"MIICcTCCAdqgAwIBAgIIagJHiPvE0MowDQYJKoZIhvcNAQELBQAwPDEaMBgGA1UE\n"
@@ -457,13 +459,15 @@ static bool TestSignCtx() {
return true;
}
+} // namespace bssl
+
int main(int argc, char **argv) {
CRYPTO_library_init();
- if (!TestVerify() ||
- !TestPSS() ||
- !TestBadPSSParameters() ||
- !TestSignCtx()) {
+ if (!bssl::TestVerify() ||
+ !bssl::TestPSS() ||
+ !bssl::TestBadPSSParameters() ||
+ !bssl::TestSignCtx()) {
return 1;
}