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

Side by Side Diff: crypto/scoped_openssl_types.h

Issue 1870233002: Convert crypto to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « crypto/scoped_nss_types.h ('k') | crypto/scoped_test_system_nss_key_slot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/mem.h> 14 #include <openssl/mem.h>
15 #include <openssl/rsa.h> 15 #include <openssl/rsa.h>
16 #include <stdint.h> 16 #include <stdint.h>
17 17
18 #include "base/memory/scoped_ptr.h" 18 #include <memory>
19 19
20 namespace crypto { 20 namespace crypto {
21 21
22 // Simplistic helper that wraps a call to a deleter function. In a C++11 world, 22 // Simplistic helper that wraps a call to a deleter function. In a C++11 world,
23 // this would be std::function<>. An alternative would be to re-use 23 // this would be std::function<>. An alternative would be to re-use
24 // base::internal::RunnableAdapter<>, but that's far too heavy weight. 24 // base::internal::RunnableAdapter<>, but that's far too heavy weight.
25 template <typename Type, void (*Destroyer)(Type*)> 25 template <typename Type, void (*Destroyer)(Type*)>
26 struct OpenSSLDestroyer { 26 struct OpenSSLDestroyer {
27 void operator()(Type* ptr) const { Destroyer(ptr); } 27 void operator()(Type* ptr) const { Destroyer(ptr); }
28 }; 28 };
29 29
30 template <typename PointerType, void (*Destroyer)(PointerType*)> 30 template <typename PointerType, void (*Destroyer)(PointerType*)>
31 using ScopedOpenSSL = 31 using ScopedOpenSSL =
32 scoped_ptr<PointerType, OpenSSLDestroyer<PointerType, Destroyer>>; 32 std::unique_ptr<PointerType, OpenSSLDestroyer<PointerType, Destroyer>>;
33 33
34 struct OpenSSLFree { 34 struct OpenSSLFree {
35 void operator()(uint8_t* ptr) const { OPENSSL_free(ptr); } 35 void operator()(uint8_t* ptr) const { OPENSSL_free(ptr); }
36 }; 36 };
37 37
38 // Several typedefs are provided for crypto-specific primitives, for 38 // Several typedefs are provided for crypto-specific primitives, for
39 // short-hand and prevalence. Note that OpenSSL types related to X.509 are 39 // short-hand and prevalence. Note that OpenSSL types related to X.509 are
40 // intentionally not included, as crypto/ does not generally deal with 40 // intentionally not included, as crypto/ does not generally deal with
41 // certificates or PKI. 41 // certificates or PKI.
42 using ScopedBIGNUM = ScopedOpenSSL<BIGNUM, BN_free>; 42 using ScopedBIGNUM = ScopedOpenSSL<BIGNUM, BN_free>;
43 using ScopedEC_Key = ScopedOpenSSL<EC_KEY, EC_KEY_free>; 43 using ScopedEC_Key = ScopedOpenSSL<EC_KEY, EC_KEY_free>;
44 using ScopedBIO = ScopedOpenSSL<BIO, BIO_free_all>; 44 using ScopedBIO = ScopedOpenSSL<BIO, BIO_free_all>;
45 using ScopedDSA = ScopedOpenSSL<DSA, DSA_free>; 45 using ScopedDSA = ScopedOpenSSL<DSA, DSA_free>;
46 using ScopedECDSA_SIG = ScopedOpenSSL<ECDSA_SIG, ECDSA_SIG_free>; 46 using ScopedECDSA_SIG = ScopedOpenSSL<ECDSA_SIG, ECDSA_SIG_free>;
47 using ScopedEC_GROUP = ScopedOpenSSL<EC_GROUP, EC_GROUP_free>; 47 using ScopedEC_GROUP = ScopedOpenSSL<EC_GROUP, EC_GROUP_free>;
48 using ScopedEC_KEY = ScopedOpenSSL<EC_KEY, EC_KEY_free>; 48 using ScopedEC_KEY = ScopedOpenSSL<EC_KEY, EC_KEY_free>;
49 using ScopedEC_POINT = ScopedOpenSSL<EC_POINT, EC_POINT_free>; 49 using ScopedEC_POINT = ScopedOpenSSL<EC_POINT, EC_POINT_free>;
50 using ScopedEVP_MD_CTX = ScopedOpenSSL<EVP_MD_CTX, EVP_MD_CTX_destroy>; 50 using ScopedEVP_MD_CTX = ScopedOpenSSL<EVP_MD_CTX, EVP_MD_CTX_destroy>;
51 using ScopedEVP_PKEY = ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free>; 51 using ScopedEVP_PKEY = ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free>;
52 using ScopedEVP_PKEY_CTX = ScopedOpenSSL<EVP_PKEY_CTX, EVP_PKEY_CTX_free>; 52 using ScopedEVP_PKEY_CTX = ScopedOpenSSL<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
53 using ScopedRSA = ScopedOpenSSL<RSA, RSA_free>; 53 using ScopedRSA = ScopedOpenSSL<RSA, RSA_free>;
54 54
55 // The bytes must have been allocated with OPENSSL_malloc. 55 // The bytes must have been allocated with OPENSSL_malloc.
56 using ScopedOpenSSLBytes = scoped_ptr<uint8_t, OpenSSLFree>; 56 using ScopedOpenSSLBytes = std::unique_ptr<uint8_t, OpenSSLFree>;
57 57
58 } // namespace crypto 58 } // namespace crypto
59 59
60 #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_ 60 #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_
OLDNEW
« no previous file with comments | « crypto/scoped_nss_types.h ('k') | crypto/scoped_test_system_nss_key_slot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698