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

Side by Side Diff: crypto/scoped_openssl_types.h

Issue 948543002: Convert crypto::ScopedOpenSSL to type aliases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/rsa_private_key_openssl.cc ('k') | crypto/signature_verifier_openssl.cc » ('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/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 using AllowSelfReset = void;
26 void operator()(Type* ptr) const { Destroyer(ptr); } 26 void operator()(Type* ptr) const { Destroyer(ptr); }
27 }; 27 };
28 28
29 template <typename PointerType, void (*Destroyer)(PointerType*)> 29 template <typename PointerType, void (*Destroyer)(PointerType*)>
30 struct ScopedOpenSSL { 30 using ScopedOpenSSL =
31 typedef scoped_ptr<PointerType, OpenSSLDestroyer<PointerType, Destroyer> > 31 scoped_ptr<PointerType, OpenSSLDestroyer<PointerType, Destroyer>>;
32 Type;
33 };
34 32
35 struct OpenSSLFree { 33 struct OpenSSLFree {
36 void operator()(uint8_t* ptr) const { OPENSSL_free(ptr); } 34 void operator()(uint8_t* ptr) const { OPENSSL_free(ptr); }
37 }; 35 };
38 36
39 // Several typedefs are provided for crypto-specific primitives, for 37 // Several typedefs are provided for crypto-specific primitives, for
40 // short-hand and prevalence. Note that OpenSSL types related to X.509 are 38 // short-hand and prevalence. Note that OpenSSL types related to X.509 are
41 // intentionally not included, as crypto/ does not generally deal with 39 // intentionally not included, as crypto/ does not generally deal with
42 // certificates or PKI. 40 // certificates or PKI.
43 typedef ScopedOpenSSL<BIGNUM, BN_free>::Type ScopedBIGNUM; 41 using ScopedBIGNUM = ScopedOpenSSL<BIGNUM, BN_free>;
44 typedef ScopedOpenSSL<EC_KEY, EC_KEY_free>::Type ScopedEC_KEY; 42 using ScopedEC_Key = ScopedOpenSSL<EC_KEY, EC_KEY_free>;
45 typedef ScopedOpenSSL<BIO, BIO_free_all>::Type ScopedBIO; 43 using ScopedBIO = ScopedOpenSSL<BIO, BIO_free_all>;
46 typedef ScopedOpenSSL<DSA, DSA_free>::Type ScopedDSA; 44 using ScopedDSA = ScopedOpenSSL<DSA, DSA_free>;
47 typedef ScopedOpenSSL<ECDSA_SIG, ECDSA_SIG_free>::Type ScopedECDSA_SIG; 45 using ScopedECDSA_SIG = ScopedOpenSSL<ECDSA_SIG, ECDSA_SIG_free>;
48 typedef ScopedOpenSSL<EC_GROUP, EC_GROUP_free>::Type ScopedEC_GROUP; 46 using ScopedEC_GROUP = ScopedOpenSSL<EC_GROUP, EC_GROUP_free>;
49 typedef ScopedOpenSSL<EC_KEY, EC_KEY_free>::Type ScopedEC_KEY; 47 using ScopedEC_KEY = ScopedOpenSSL<EC_KEY, EC_KEY_free>;
50 typedef ScopedOpenSSL<EC_POINT, EC_POINT_free>::Type ScopedEC_POINT; 48 using ScopedEC_POINT = ScopedOpenSSL<EC_POINT, EC_POINT_free>;
51 typedef ScopedOpenSSL<EVP_MD_CTX, EVP_MD_CTX_destroy>::Type ScopedEVP_MD_CTX; 49 using ScopedEVP_MD_CTX = ScopedOpenSSL<EVP_MD_CTX, EVP_MD_CTX_destroy>;
52 typedef ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free>::Type ScopedEVP_PKEY; 50 using ScopedEVP_PKEY = ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free>;
53 typedef ScopedOpenSSL<EVP_PKEY_CTX, EVP_PKEY_CTX_free>::Type ScopedEVP_PKEY_CTX; 51 using ScopedEVP_PKEY_CTX = ScopedOpenSSL<EVP_PKEY_CTX, EVP_PKEY_CTX_free>;
54 typedef ScopedOpenSSL<RSA, RSA_free>::Type ScopedRSA; 52 using ScopedRSA = ScopedOpenSSL<RSA, RSA_free>;
55 53
56 // The bytes must have been allocated with OPENSSL_malloc. 54 // The bytes must have been allocated with OPENSSL_malloc.
57 typedef scoped_ptr<uint8_t, OpenSSLFree> ScopedOpenSSLBytes; 55 using ScopedOpenSSLBytes = scoped_ptr<uint8_t, OpenSSLFree>;
58 56
59 } // namespace crypto 57 } // namespace crypto
60 58
61 #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_ 59 #endif // CRYPTO_SCOPED_OPENSSL_TYPES_H_
OLDNEW
« no previous file with comments | « crypto/rsa_private_key_openssl.cc ('k') | crypto/signature_verifier_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698