Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CSSM_INIT_H_ | 5 #ifndef CRYPTO_CSSM_INIT_H_ |
| 6 #define CRYPTO_CSSM_INIT_H_ | 6 #define CRYPTO_CSSM_INIT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <Security/cssm.h> | 9 #include <Security/cssm.h> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "crypto/crypto_api.h" | |
| 12 | 13 |
| 13 namespace crypto { | 14 namespace crypto { |
| 14 | 15 |
| 15 // Initialize CSSM if it isn't already initialized. This must be called before | 16 // Initialize CSSM if it isn't already initialized. This must be called before |
| 16 // any other CSSM functions. This function is thread-safe, and CSSM will only | 17 // any other CSSM functions. This function is thread-safe, and CSSM will only |
| 17 // ever be initialized once. CSSM will be properly shut down on program exit. | 18 // ever be initialized once. CSSM will be properly shut down on program exit. |
| 18 void EnsureCSSMInit(); | 19 CRYPTO_API void EnsureCSSMInit(); |
| 19 | 20 |
| 20 // Returns the shared CSP handle used by CSSM functions. | 21 // Returns the shared CSP handle used by CSSM functions. |
| 21 CSSM_CSP_HANDLE GetSharedCSPHandle(); | 22 CSSM_CSP_HANDLE GetSharedCSPHandle(); |
| 22 | 23 |
| 23 // Returns the shared CL handle used by CSSM functions. | 24 // Returns the shared CL handle used by CSSM functions. |
| 24 CSSM_CL_HANDLE GetSharedCLHandle(); | 25 CRYPTO_API CSSM_CL_HANDLE GetSharedCLHandle(); |
| 25 | 26 |
| 26 // Returns the shared TP handle used by CSSM functions. | 27 // Returns the shared TP handle used by CSSM functions. |
| 27 CSSM_TP_HANDLE GetSharedTPHandle(); | 28 CRYPTO_API CSSM_TP_HANDLE GetSharedTPHandle(); |
| 28 | 29 |
| 29 // Set of pointers to memory function wrappers that are required for CSSM | 30 // Set of pointers to memory function wrappers that are required for CSSM |
| 30 extern const CSSM_API_MEMORY_FUNCS kCssmMemoryFunctions; | 31 extern const CSSM_API_MEMORY_FUNCS kCssmMemoryFunctions; |
| 31 | 32 |
| 32 // Utility function to log an error message including the error name. | 33 // Utility function to log an error message including the error name. |
| 33 void LogCSSMError(const char *function_name, CSSM_RETURN err); | 34 CRYPTO_API void LogCSSMError(const char *function_name, CSSM_RETURN err); |
| 34 | 35 |
| 35 // Utility functions to allocate and release CSSM memory. | 36 // Utility functions to allocate and release CSSM memory. |
| 36 void* CSSMMalloc(CSSM_SIZE size); | 37 void* CSSMMalloc(CSSM_SIZE size); |
| 37 void CSSMFree(void* ptr); | 38 CRYPTO_API void CSSMFree(void* ptr); |
|
Nico
2011/07/29 02:03:37
Called by net/base/x509_certificate_mac.cc. Nobody
| |
| 38 | 39 |
| 39 // Wrapper class for CSSM_DATA type. This should only be used when using the | 40 // Wrapper class for CSSM_DATA type. This should only be used when using the |
| 40 // CL/TP/CSP handles from above, since that's the only time we're guaranteed (or | 41 // CL/TP/CSP handles from above, since that's the only time we're guaranteed (or |
| 41 // supposed to be guaranteed) that our memory management functions will be used. | 42 // supposed to be guaranteed) that our memory management functions will be used. |
| 42 // Apple's Sec* APIs manage their own memory so it shouldn't be used for those. | 43 // Apple's Sec* APIs manage their own memory so it shouldn't be used for those. |
| 43 // The constructor initializes data_ to zero and the destructor releases the | 44 // The constructor initializes data_ to zero and the destructor releases the |
| 44 // data properly. | 45 // data properly. |
| 45 class ScopedCSSMData { | 46 class ScopedCSSMData { |
| 46 public: | 47 public: |
| 47 ScopedCSSMData(); | 48 ScopedCSSMData(); |
| 48 ~ScopedCSSMData(); | 49 ~ScopedCSSMData(); |
| 49 operator CSSM_DATA*() { return &data_; } | 50 operator CSSM_DATA*() { return &data_; } |
| 50 CSSM_DATA* operator ->() { return &data_; } | 51 CSSM_DATA* operator ->() { return &data_; } |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 CSSM_DATA data_; | 54 CSSM_DATA data_; |
| 54 | 55 |
| 55 DISALLOW_COPY_AND_ASSIGN(ScopedCSSMData); | 56 DISALLOW_COPY_AND_ASSIGN(ScopedCSSMData); |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 } // namespace crypto | 59 } // namespace crypto |
| 59 | 60 |
| 60 #endif // CRYPTO_CSSM_INIT_H_ | 61 #endif // CRYPTO_CSSM_INIT_H_ |
| OLD | NEW |