ash: Update app list layout:
[chromium-blink-merge.git] / crypto / cssm_init.h
blob0e9ed32f4d8d3c5ea77a9f7c5ce308578e581419
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
3 // found in the LICENSE file.
5 #ifndef CRYPTO_CSSM_INIT_H_
6 #define CRYPTO_CSSM_INIT_H_
7 #pragma once
9 #include <Security/cssm.h>
11 #include "base/basictypes.h"
12 #include "crypto/crypto_export.h"
14 namespace crypto {
16 // Initialize CSSM if it isn't already initialized. This must be called before
17 // any other CSSM functions. This function is thread-safe, and CSSM will only
18 // ever be initialized once. CSSM will be properly shut down on program exit.
19 CRYPTO_EXPORT void EnsureCSSMInit();
21 // Returns the shared CSP handle used by CSSM functions.
22 CRYPTO_EXPORT CSSM_CSP_HANDLE GetSharedCSPHandle();
24 // Returns the shared CL handle used by CSSM functions.
25 CRYPTO_EXPORT CSSM_CL_HANDLE GetSharedCLHandle();
27 // Returns the shared TP handle used by CSSM functions.
28 CRYPTO_EXPORT CSSM_TP_HANDLE GetSharedTPHandle();
30 // Set of pointers to memory function wrappers that are required for CSSM
31 extern const CSSM_API_MEMORY_FUNCS kCssmMemoryFunctions;
33 // Utility function to log an error message including the error name.
34 CRYPTO_EXPORT void LogCSSMError(const char *function_name, CSSM_RETURN err);
36 // Utility functions to allocate and release CSSM memory.
37 void* CSSMMalloc(CSSM_SIZE size);
38 CRYPTO_EXPORT void CSSMFree(void* ptr);
40 // Wrapper class for CSSM_DATA type. This should only be used when using the
41 // CL/TP/CSP handles from above, since that's the only time we're guaranteed (or
42 // supposed to be guaranteed) that our memory management functions will be used.
43 // Apple's Sec* APIs manage their own memory so it shouldn't be used for those.
44 // The constructor initializes data_ to zero and the destructor releases the
45 // data properly.
46 class ScopedCSSMData {
47 public:
48 ScopedCSSMData();
49 ~ScopedCSSMData();
50 operator CSSM_DATA*() { return &data_; }
51 CSSM_DATA* operator ->() { return &data_; }
53 private:
54 CSSM_DATA data_;
56 DISALLOW_COPY_AND_ASSIGN(ScopedCSSMData);
59 } // namespace crypto
61 #endif // CRYPTO_CSSM_INIT_H_