OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CRYPTO_SCOPED_OPENSSL_TYPES_H_ | 5 #ifndef CRYPTO_SCOPED_OPENSSL_TYPES_H_ |
6 #define CRYPTO_SCOPED_OPENSSL_TYPES_H_ | 6 #define CRYPTO_SCOPED_OPENSSL_TYPES_H_ |
7 | 7 |
8 #include <openssl/bio.h> | 8 #include <openssl/bio.h> |
9 #include <openssl/bn.h> | 9 #include <openssl/bn.h> |
10 #include <openssl/dsa.h> | 10 #include <openssl/dsa.h> |
11 #include <openssl/ec.h> | 11 #include <openssl/ec.h> |
12 #include <openssl/ecdsa.h> | 12 #include <openssl/ecdsa.h> |
13 #include <openssl/evp.h> | 13 #include <openssl/evp.h> |
14 #include <openssl/rsa.h> | 14 #include <openssl/rsa.h> |
15 | 15 |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 | 17 |
18 namespace crypto { | 18 namespace crypto { |
19 | 19 |
20 // Simplistic helper that wraps a call to a deleter function. In a C++11 world, | 20 // Simplistic helper that wraps a call to a deleter function. In a C++11 world, |
21 // this would be std::function<>. An alternative would be to re-use | 21 // this would be std::function<>. An alternative would be to re-use |
22 // base::internal::RunnableAdapter<>, but that's far too heavy weight. | 22 // base::internal::RunnableAdapter<>, but that's far too heavy weight. |
23 template <typename Type, void (*Destroyer)(Type*)> | 23 template <typename Type, void (*Destroyer)(Type*)> |
24 struct OpenSSLDestroyer { | 24 struct OpenSSLDestroyer { |
| 25 typedef void AllowSelfReset; |
25 void operator()(Type* ptr) const { Destroyer(ptr); } | 26 void operator()(Type* ptr) const { Destroyer(ptr); } |
26 }; | 27 }; |
27 | 28 |
28 template <typename PointerType, void (*Destroyer)(PointerType*)> | 29 template <typename PointerType, void (*Destroyer)(PointerType*)> |
29 struct ScopedOpenSSL { | 30 struct ScopedOpenSSL { |
30 typedef scoped_ptr<PointerType, OpenSSLDestroyer<PointerType, Destroyer> > | 31 typedef scoped_ptr<PointerType, OpenSSLDestroyer<PointerType, Destroyer> > |
31 Type; | 32 Type; |
32 }; | 33 }; |
33 | 34 |
34 struct OpenSSLFree { | 35 struct OpenSSLFree { |
(...skipping 14 matching lines...) Expand all Loading... |
49 typedef ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free>::Type ScopedEVP_PKEY; | 50 typedef ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free>::Type ScopedEVP_PKEY; |
50 typedef ScopedOpenSSL<EVP_PKEY_CTX, EVP_PKEY_CTX_free>::Type ScopedEVP_PKEY_CTX; | 51 typedef ScopedOpenSSL<EVP_PKEY_CTX, EVP_PKEY_CTX_free>::Type ScopedEVP_PKEY_CTX; |
51 typedef ScopedOpenSSL<RSA, RSA_free>::Type ScopedRSA; | 52 typedef ScopedOpenSSL<RSA, RSA_free>::Type ScopedRSA; |
52 | 53 |
53 // The bytes must have been allocated with OPENSSL_malloc. | 54 // The bytes must have been allocated with OPENSSL_malloc. |
54 typedef scoped_ptr<uint8_t, OpenSSLFree> ScopedOpenSSLBytes; | 55 typedef scoped_ptr<uint8_t, OpenSSLFree> ScopedOpenSSLBytes; |
55 | 56 |
56 } // namespace crypto | 57 } // namespace crypto |
57 | 58 |
58 #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_ | 59 #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_ |
OLD | NEW |