| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_CAPI_TYPES_H_ | 5 #ifndef CRYPTO_SCOPED_CAPI_TYPES_H_ |
| 6 #define CRYPTO_SCOPED_CAPI_TYPES_H_ | 6 #define CRYPTO_SCOPED_CAPI_TYPES_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <wincrypt.h> | 9 #include <wincrypt.h> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 void operator()(CAPIHandle handle) const { | 35 void operator()(CAPIHandle handle) const { |
| 36 if (handle) { | 36 if (handle) { |
| 37 BOOL ok = Destroyer(handle, flags); | 37 BOOL ok = Destroyer(handle, flags); |
| 38 DCHECK(ok); | 38 DCHECK(ok); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // scoped_ptr-like class for the CryptoAPI cryptography and certificate | 43 // scoped_ptr-like class for the CryptoAPI cryptography and certificate |
| 44 // handles. Because these handles are defined as integer types, and not | 44 // handles. Because these handles are defined as integer types, and not |
| 45 // pointers, the existing scoped classes, such as scoped_ptr_malloc, are | 45 // pointers, the existing scoped classes, such as scoped_ptr, are insufficient. |
| 46 // insufficient. The semantics are the same as scoped_ptr. | 46 // The semantics are the same as scoped_ptr. |
| 47 template <class CAPIHandle, typename FreeProc> | 47 template <class CAPIHandle, typename FreeProc> |
| 48 class ScopedCAPIHandle { | 48 class ScopedCAPIHandle { |
| 49 public: | 49 public: |
| 50 explicit ScopedCAPIHandle(CAPIHandle handle = NULL) : handle_(handle) {} | 50 explicit ScopedCAPIHandle(CAPIHandle handle = NULL) : handle_(handle) {} |
| 51 | 51 |
| 52 ~ScopedCAPIHandle() { | 52 ~ScopedCAPIHandle() { |
| 53 reset(); | 53 reset(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void reset(CAPIHandle handle = NULL) { | 56 void reset(CAPIHandle handle = NULL) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 typedef ScopedCAPIHandle< | 113 typedef ScopedCAPIHandle< |
| 114 HCRYPTKEY, CAPIDestroyer<HCRYPTKEY, CryptDestroyKey> > ScopedHCRYPTKEY; | 114 HCRYPTKEY, CAPIDestroyer<HCRYPTKEY, CryptDestroyKey> > ScopedHCRYPTKEY; |
| 115 | 115 |
| 116 typedef ScopedCAPIHandle< | 116 typedef ScopedCAPIHandle< |
| 117 HCRYPTHASH, CAPIDestroyer<HCRYPTHASH, CryptDestroyHash> > ScopedHCRYPTHASH; | 117 HCRYPTHASH, CAPIDestroyer<HCRYPTHASH, CryptDestroyHash> > ScopedHCRYPTHASH; |
| 118 | 118 |
| 119 } // namespace crypto | 119 } // namespace crypto |
| 120 | 120 |
| 121 #endif // CRYPTO_SCOPED_CAPI_TYPES_H_ | 121 #endif // CRYPTO_SCOPED_CAPI_TYPES_H_ |
| OLD | NEW |