Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1054)

Unified Diff: crypto/scoped_openssl_types.h

Issue 361193003: Eliminate ScopedOpenSSL in favour of scoped_ptr<> specializations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Android fixes Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698