OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 BASE_CRYPTO_SCOPED_CAPI_TYPES_H_ | 5 #ifndef CRYPTO_SCOPED_CAPI_TYPES_H_ |
6 #define BASE_CRYPTO_SCOPED_CAPI_TYPES_H_ | 6 #define CRYPTO_SCOPED_CAPI_TYPES_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <wincrypt.h> | 10 #include <wincrypt.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 | 15 |
16 namespace base { | 16 namespace crypto { |
17 | 17 |
18 // Simple destructor for the Free family of CryptoAPI functions, such as | 18 // Simple destructor for the Free family of CryptoAPI functions, such as |
19 // CryptDestroyHash, which take only a single argument to release. | 19 // CryptDestroyHash, which take only a single argument to release. |
20 template <typename CAPIHandle, BOOL (WINAPI *Destroyer)(CAPIHandle)> | 20 template <typename CAPIHandle, BOOL (WINAPI *Destroyer)(CAPIHandle)> |
21 struct CAPIDestroyer { | 21 struct CAPIDestroyer { |
22 void operator()(CAPIHandle handle) const { | 22 void operator()(CAPIHandle handle) const { |
23 if (handle) { | 23 if (handle) { |
24 BOOL ok = Destroyer(handle); | 24 BOOL ok = Destroyer(handle); |
25 DCHECK(ok); | 25 DCHECK(ok); |
26 } | 26 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 HCRYPTPROV, | 113 HCRYPTPROV, |
114 CAPIDestroyerWithFlags<HCRYPTPROV, | 114 CAPIDestroyerWithFlags<HCRYPTPROV, |
115 CryptReleaseContext, 0> > ScopedHCRYPTPROV; | 115 CryptReleaseContext, 0> > ScopedHCRYPTPROV; |
116 | 116 |
117 typedef ScopedCAPIHandle< | 117 typedef ScopedCAPIHandle< |
118 HCRYPTKEY, CAPIDestroyer<HCRYPTKEY, CryptDestroyKey> > ScopedHCRYPTKEY; | 118 HCRYPTKEY, CAPIDestroyer<HCRYPTKEY, CryptDestroyKey> > ScopedHCRYPTKEY; |
119 | 119 |
120 typedef ScopedCAPIHandle< | 120 typedef ScopedCAPIHandle< |
121 HCRYPTHASH, CAPIDestroyer<HCRYPTHASH, CryptDestroyHash> > ScopedHCRYPTHASH; | 121 HCRYPTHASH, CAPIDestroyer<HCRYPTHASH, CryptDestroyHash> > ScopedHCRYPTHASH; |
122 | 122 |
123 } // namespace base | 123 } // namespace crypto |
124 | 124 |
125 #endif // BASE_CRYPTO_SCOPED_CAPI_TYPES_H_ | 125 #endif // CRYPTO_SCOPED_CAPI_TYPES_H_ |
OLD | NEW |