Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / crypto / cssm_init.h
blobe711099ef08e6e075d321911fe23ee2e4e6b5616
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
3 // found in the LICENSE file.
5 #ifndef CRYPTO_CSSM_INIT_H_
6 #define CRYPTO_CSSM_INIT_H_
8 #include <Security/cssm.h>
10 #include "base/basictypes.h"
11 #include "crypto/crypto_export.h"
13 namespace crypto {
15 // 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 // ever be initialized once. CSSM will be properly shut down on program exit.
18 CRYPTO_EXPORT void EnsureCSSMInit();
20 // Returns the shared CSP handle used by CSSM functions.
21 CRYPTO_EXPORT CSSM_CSP_HANDLE GetSharedCSPHandle();
23 // Returns the shared CL handle used by CSSM functions.
24 CRYPTO_EXPORT CSSM_CL_HANDLE GetSharedCLHandle();
26 // Returns the shared TP handle used by CSSM functions.
27 CRYPTO_EXPORT CSSM_TP_HANDLE GetSharedTPHandle();
29 // Set of pointers to memory function wrappers that are required for CSSM
30 extern const CSSM_API_MEMORY_FUNCS kCssmMemoryFunctions;
32 // Utility function to log an error message including the error name.
33 CRYPTO_EXPORT void LogCSSMError(const char *function_name, CSSM_RETURN err);
35 // Utility functions to allocate and release CSSM memory.
36 void* CSSMMalloc(CSSM_SIZE size);
37 CRYPTO_EXPORT void CSSMFree(void* ptr);
39 // 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 // 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 // The constructor initializes data_ to zero and the destructor releases the
44 // data properly.
45 class ScopedCSSMData {
46 public:
47 ScopedCSSMData();
48 ~ScopedCSSMData();
49 operator CSSM_DATA*() { return &data_; }
50 CSSM_DATA* operator ->() { return &data_; }
52 private:
53 CSSM_DATA data_;
55 DISALLOW_COPY_AND_ASSIGN(ScopedCSSMData);
58 } // namespace crypto
60 #endif // CRYPTO_CSSM_INIT_H_