Revert scoped_types.h change.
This reverts commits:
8d79ed67407e433d80ebc8d3aa080e8ce16e6eb7
19fdcb523402ed13ab798cf811fb0119e3e7b104
8d79ed67407e433d80ebc8d3aa080e8ce16e6eb7
Because WebRTC (at least) includes our headers in an extern "C" block,
which precludes having any C++ in them.
Change-Id: Ia849f43795a40034cbd45b22ea680b51aab28b2d
diff --git a/crypto/asn1/asn1_test.cc b/crypto/asn1/asn1_test.cc
index 86dd02a..e3e310b 100644
--- a/crypto/asn1/asn1_test.cc
+++ b/crypto/asn1/asn1_test.cc
@@ -18,6 +18,8 @@
#include <openssl/crypto.h>
#include <openssl/err.h>
+#include "../test/scoped_types.h"
+
namespace bssl {
diff --git a/crypto/bio/bio_test.cc b/crypto/bio/bio_test.cc
index cd56e62..e7c061e 100644
--- a/crypto/bio/bio_test.cc
+++ b/crypto/bio/bio_test.cc
@@ -40,6 +40,8 @@
#include <algorithm>
+#include "../test/scoped_types.h"
+
namespace bssl {
diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc
index 67ab924..3028745 100644
--- a/crypto/bn/bn_test.cc
+++ b/crypto/bn/bn_test.cc
@@ -81,12 +81,12 @@
#include <utility>
#include <openssl/bn.h>
-#include <openssl/bytestring.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/mem.h>
#include "../crypto/test/file_test.h"
+#include "../crypto/test/scoped_types.h"
#include "../crypto/test/test_util.h"
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc
index 39ac0ae..95d9b85 100644
--- a/crypto/bytestring/bytestring_test.cc
+++ b/crypto/bytestring/bytestring_test.cc
@@ -26,6 +26,7 @@
#include <openssl/bytestring.h>
#include "internal.h"
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/cipher/aead_test.cc b/crypto/cipher/aead_test.cc
index 70b84ab..cf0f24a 100644
--- a/crypto/cipher/aead_test.cc
+++ b/crypto/cipher/aead_test.cc
@@ -22,6 +22,7 @@
#include <openssl/err.h>
#include "../test/file_test.h"
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/cipher/cipher_test.cc b/crypto/cipher/cipher_test.cc
index beaef2c..221eb67 100644
--- a/crypto/cipher/cipher_test.cc
+++ b/crypto/cipher/cipher_test.cc
@@ -62,6 +62,7 @@
#include <openssl/err.h>
#include "../test/file_test.h"
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/cmac/cmac_test.cc b/crypto/cmac/cmac_test.cc
index 7b42129..11b7ad6 100644
--- a/crypto/cmac/cmac_test.cc
+++ b/crypto/cmac/cmac_test.cc
@@ -17,9 +17,8 @@
#include <algorithm>
#include <openssl/cmac.h>
-#include <openssl/evp.h>
-#include <openssl/mem.h>
+#include "../test/scoped_types.h"
#include "../test/test_util.h"
diff --git a/crypto/curve25519/spake25519_test.cc b/crypto/curve25519/spake25519_test.cc
index ee7e0fb..b8742ed 100644
--- a/crypto/curve25519/spake25519_test.cc
+++ b/crypto/curve25519/spake25519_test.cc
@@ -19,6 +19,7 @@
#include <string.h>
#include <openssl/curve25519.h>
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/dh/dh_test.cc b/crypto/dh/dh_test.cc
index 9cf76f6..8fe496c 100644
--- a/crypto/dh/dh_test.cc
+++ b/crypto/dh/dh_test.cc
@@ -68,6 +68,7 @@
#include <openssl/mem.h>
#include "internal.h"
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/digest/digest_test.cc b/crypto/digest/digest_test.cc
index c390913..32d12d2 100644
--- a/crypto/digest/digest_test.cc
+++ b/crypto/digest/digest_test.cc
@@ -23,6 +23,8 @@
#include <openssl/md5.h>
#include <openssl/sha.h>
+#include "../test/scoped_types.h"
+
namespace bssl {
diff --git a/crypto/ec/ec_test.cc b/crypto/ec/ec_test.cc
index 7572434..864cd49 100644
--- a/crypto/ec/ec_test.cc
+++ b/crypto/ec/ec_test.cc
@@ -17,13 +17,13 @@
#include <vector>
-#include <openssl/bn.h>
#include <openssl/bytestring.h>
#include <openssl/crypto.h>
#include <openssl/ec_key.h>
#include <openssl/err.h>
#include <openssl/mem.h>
-#include <openssl/obj.h>
+
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/ecdsa/ecdsa_test.cc b/crypto/ecdsa/ecdsa_test.cc
index 6b42d4e..ad2325b 100644
--- a/crypto/ecdsa/ecdsa_test.cc
+++ b/crypto/ecdsa/ecdsa_test.cc
@@ -62,6 +62,8 @@
#include <openssl/nid.h>
#include <openssl/rand.h>
+#include "../test/scoped_types.h"
+
namespace bssl {
diff --git a/crypto/evp/evp_extra_test.cc b/crypto/evp/evp_extra_test.cc
index 750da75..2253c56 100644
--- a/crypto/evp/evp_extra_test.cc
+++ b/crypto/evp/evp_extra_test.cc
@@ -25,9 +25,10 @@
#include <openssl/digest.h>
#include <openssl/err.h>
#include <openssl/evp.h>
-#include <openssl/pkcs8.h>
#include <openssl/rsa.h>
+#include "../test/scoped_types.h"
+
namespace bssl {
diff --git a/crypto/evp/evp_test.cc b/crypto/evp/evp_test.cc
index a20c6a6..9b8a683 100644
--- a/crypto/evp/evp_test.cc
+++ b/crypto/evp/evp_test.cc
@@ -74,6 +74,7 @@
#include <openssl/err.h>
#include "../test/file_test.h"
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/hmac/hmac_test.cc b/crypto/hmac/hmac_test.cc
index 9f76495..ba84cc2 100644
--- a/crypto/hmac/hmac_test.cc
+++ b/crypto/hmac/hmac_test.cc
@@ -65,6 +65,7 @@
#include <openssl/hmac.h>
#include "../test/file_test.h"
+#include "../test/scoped_types.h"
namespace bssl {
diff --git a/crypto/newhope/newhope_statistical_test.cc b/crypto/newhope/newhope_statistical_test.cc
index 1344506..d3a5443 100644
--- a/crypto/newhope/newhope_statistical_test.cc
+++ b/crypto/newhope/newhope_statistical_test.cc
@@ -21,6 +21,7 @@
#include <openssl/crypto.h>
#include <openssl/rand.h>
+#include "../test/scoped_types.h"
#include "internal.h"
diff --git a/crypto/newhope/newhope_test.cc b/crypto/newhope/newhope_test.cc
index c127d4f..d94eee8 100644
--- a/crypto/newhope/newhope_test.cc
+++ b/crypto/newhope/newhope_test.cc
@@ -19,6 +19,7 @@
#include <openssl/crypto.h>
#include <openssl/rand.h>
+#include "../test/scoped_types.h"
#include "internal.h"
diff --git a/crypto/newhope/newhope_vectors_test.cc b/crypto/newhope/newhope_vectors_test.cc
index a3398fa..691d693 100644
--- a/crypto/newhope/newhope_vectors_test.cc
+++ b/crypto/newhope/newhope_vectors_test.cc
@@ -20,6 +20,7 @@
#include <openssl/rand.h>
#include "../test/file_test.h"
+#include "../test/scoped_types.h"
#include "internal.h"
diff --git a/crypto/pkcs8/pkcs12_test.cc b/crypto/pkcs8/pkcs12_test.cc
index 2c4adc4..1069444 100644
--- a/crypto/pkcs8/pkcs12_test.cc
+++ b/crypto/pkcs8/pkcs12_test.cc
@@ -23,6 +23,8 @@
#include <openssl/stack.h>
#include <openssl/x509.h>
+#include "../test/scoped_types.h"
+
/* kPKCS12DER contains sample PKCS#12 data generated by OpenSSL with:
* openssl pkcs12 -export -inkey key.pem -in cacert.pem */
diff --git a/crypto/pkcs8/pkcs8_test.cc b/crypto/pkcs8/pkcs8_test.cc
index b58461f..e54a699 100644
--- a/crypto/pkcs8/pkcs8_test.cc
+++ b/crypto/pkcs8/pkcs8_test.cc
@@ -21,6 +21,8 @@
#include <openssl/pkcs8.h>
#include <openssl/x509.h>
+#include "../test/scoped_types.h"
+
/* kDER is a PKCS#8 encrypted private key. It was generated with:
*
diff --git a/crypto/rsa/rsa_test.cc b/crypto/rsa/rsa_test.cc
index 698eb92..5307f2c 100644
--- a/crypto/rsa/rsa_test.cc
+++ b/crypto/rsa/rsa_test.cc
@@ -65,6 +65,8 @@
#include <openssl/err.h>
#include <openssl/nid.h>
+#include "../test/scoped_types.h"
+
// kPlaintext is a sample plaintext.
static const uint8_t kPlaintext[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
diff --git a/crypto/test/scoped_types.h b/crypto/test/scoped_types.h
new file mode 100644
index 0000000..7e4a48e
--- /dev/null
+++ b/crypto/test/scoped_types.h
@@ -0,0 +1,97 @@
+/* Copyright (c) 2015, Google Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+#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>
+
+#include <memory>
+
+#include <openssl/aead.h>
+#include <openssl/asn1.h>
+#include <openssl/bio.h>
+#include <openssl/bn.h>
+#include <openssl/bytestring.h>
+#include <openssl/cmac.h>
+#include <openssl/curve25519.h>
+#include <openssl/dh.h>
+#include <openssl/ecdsa.h>
+#include <openssl/ec.h>
+#include <openssl/ec_key.h>
+#include <openssl/evp.h>
+#include <openssl/hmac.h>
+#include <openssl/mem.h>
+#include <openssl/newhope.h>
+#include <openssl/pkcs8.h>
+#include <openssl/rsa.h>
+#include <openssl/stack.h>
+#include <openssl/x509.h>
+
+namespace bssl {
+
+struct FileCloser {
+ void operator()(FILE *file) {
+ fclose(file);
+ }
+};
+
+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 41221ce..cb28df7 100644
--- a/crypto/x509/x509_test.cc
+++ b/crypto/x509/x509_test.cc
@@ -24,6 +24,8 @@
#include <openssl/pem.h>
#include <openssl/x509.h>
+#include "../test/scoped_types.h"
+
namespace bssl {