Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CRYPTO_SCOPED_OPENSSL_TYPES_H_ | |
| 6 #define CRYPTO_SCOPED_OPENSSL_TYPES_H_ | |
| 7 | |
| 8 #include <openssl/bn.h> | |
| 9 #include <openssl/dsa.h> | |
| 10 #include <openssl/ec.h> | |
| 11 #include <openssl/ecdsa.h> | |
| 12 #include <openssl/evp.h> | |
| 13 #include <openssl/rsa.h> | |
| 14 | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 | |
| 17 namespace crypto { | |
| 18 | |
| 19 // Simple helper because scoped_ptr<> does not take function pointers as | |
| 20 // destructors. If/when Chromium switches to use STL's unique_ptr<>, this | |
| 21 // helper will be unnecessary, as unique_ptr<> does support function pointers. | |
| 22 template <typename Type, void (*Destroyer)(Type*)> | |
| 23 struct OpenSSLDestroyer { | |
| 24 void operator()(Type* ptr) const { | |
| 25 if (ptr) | |
|
eroman
2014/07/07 21:56:20
no need for this test, scoped_ptr<> only calls it
| |
| 26 Destroyer(ptr); | |
| 27 } | |
| 28 }; | |
| 29 | |
| 30 typedef scoped_ptr<BIGNUM, OpenSSLDestroyer<BIGNUM, BN_free> > ScopedBIGNUM; | |
| 31 typedef scoped_ptr<BIO, OpenSSLDestroyer<BIO, BIO_free_all> > ScopedBIO; | |
| 32 typedef scoped_ptr<DSA, OpenSSLDestroyer<DSA, DSA_free> > ScopedDSA; | |
| 33 typedef scoped_ptr<ECDSA_SIG, OpenSSLDestroyer<ECDSA_SIG, ECDSA_SIG_free> > | |
| 34 ScopedECDSA_SIG; | |
| 35 typedef scoped_ptr<EC_KEY, OpenSSLDestroyer<EC_KEY, EC_KEY_free> > ScopedEC_KEY; | |
| 36 typedef scoped_ptr<EVP_MD_CTX, | |
| 37 OpenSSLDestroyer<EVP_MD_CTX, EVP_MD_CTX_destroy> > | |
| 38 ScopedEVP_MD_CTX; | |
| 39 typedef scoped_ptr<EVP_PKEY, OpenSSLDestroyer<EVP_PKEY, EVP_PKEY_free> > | |
| 40 ScopedEVP_PKEY; | |
| 41 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
| |
| 42 | |
| 43 } // namespace crypto | |
| 44 | |
| 45 #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_ | |
| OLD | NEW |