Index: crypto/scoped_openssl_types.h |
diff --git a/crypto/scoped_openssl_types.h b/crypto/scoped_openssl_types.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6105091396ad17facfb6df5dedad6eb41e706ce1 |
--- /dev/null |
+++ b/crypto/scoped_openssl_types.h |
@@ -0,0 +1,45 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CRYPTO_SCOPED_OPENSSL_TYPES_H_ |
+#define CRYPTO_SCOPED_OPENSSL_TYPES_H_ |
+ |
+#include <openssl/bn.h> |
+#include <openssl/dsa.h> |
+#include <openssl/ec.h> |
+#include <openssl/ecdsa.h> |
+#include <openssl/evp.h> |
+#include <openssl/rsa.h> |
+ |
+#include "base/memory/scoped_ptr.h" |
+ |
+namespace crypto { |
+ |
+// Simple helper because scoped_ptr<> does not take function pointers as |
+// destructors. If/when Chromium switches to use STL's unique_ptr<>, this |
+// helper will be unnecessary, as unique_ptr<> does support function pointers. |
+template <typename Type, void (*Destroyer)(Type*)> |
+struct OpenSSLDestroyer { |
+ void operator()(Type* ptr) const { |
+ if (ptr) |
eroman
2014/07/07 21:56:20
no need for this test, scoped_ptr<> only calls it
|
+ Destroyer(ptr); |
+ } |
+}; |
+ |
+typedef scoped_ptr<BIGNUM, OpenSSLDestroyer<BIGNUM, BN_free> > ScopedBIGNUM; |
+typedef scoped_ptr<BIO, OpenSSLDestroyer<BIO, BIO_free_all> > ScopedBIO; |
+typedef scoped_ptr<DSA, OpenSSLDestroyer<DSA, DSA_free> > ScopedDSA; |
+typedef scoped_ptr<ECDSA_SIG, OpenSSLDestroyer<ECDSA_SIG, ECDSA_SIG_free> > |
+ ScopedECDSA_SIG; |
+typedef scoped_ptr<EC_KEY, OpenSSLDestroyer<EC_KEY, EC_KEY_free> > ScopedEC_KEY; |
+typedef scoped_ptr<EVP_MD_CTX, |
+ OpenSSLDestroyer<EVP_MD_CTX, EVP_MD_CTX_destroy> > |
+ ScopedEVP_MD_CTX; |
+typedef scoped_ptr<EVP_PKEY, OpenSSLDestroyer<EVP_PKEY, EVP_PKEY_free> > |
+ ScopedEVP_PKEY; |
+typedef scoped_ptr<RSA, OpenSSLDestroyer<RSA, RSA_free> > ScopedRSA; |
wtc
2014/07/02 20:13:13
Nit: The criteria for which typedefs get to be def
Ryan Sleevi
2014/07/02 20:16:29
Similar to ScopedNSS/ScopedCAPI, this only defines
wtc
2014/07/02 20:21:59
Yes. (I see that you already explained this criter
|
+ |
+} // namespace crypto |
+ |
+#endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_ |