| 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 #include "crypto/cssm_init.h" | 5 #include "crypto/cssm_init.h" |
| 6 | 6 |
| 7 #include <Security/SecBase.h> | 7 #include <Security/SecBase.h> |
| 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 13 | 14 |
| 14 // When writing crypto code for Mac OS X, you may find the following | 15 // When writing crypto code for Mac OS X, you may find the following |
| 15 // documentation useful: | 16 // documentation useful: |
| 16 // - Common Security: CDSA and CSSM, Version 2 (with corrigenda) | 17 // - Common Security: CDSA and CSSM, Version 2 (with corrigenda) |
| 17 // http://www.opengroup.org/security/cdsa.htm | 18 // http://www.opengroup.org/security/cdsa.htm |
| 18 // - Apple Cryptographic Service Provider Functional Specification | 19 // - Apple Cryptographic Service Provider Functional Specification |
| 19 // - CryptoSample: http://developer.apple.com/SampleCode/CryptoSample/ | 20 // - CryptoSample: http://developer.apple.com/SampleCode/CryptoSample/ |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 void* CSSMMalloc(CSSM_SIZE size, void* alloc_ref) { | 24 void* CSSMMalloc(CSSM_SIZE size, void* alloc_ref) { |
| 24 return malloc(size); | 25 return malloc(size); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void CSSMFree(void* mem_ptr, void* alloc_ref) { | 28 void CSSMFree(void* mem_ptr, void* alloc_ref) { |
| 28 free(mem_ptr); | 29 free(mem_ptr); |
| 29 } | 30 } |
| 30 | 31 |
| 31 void* CSSMRealloc(void* ptr, CSSM_SIZE size, void* alloc_ref) { | 32 void* CSSMRealloc(void* ptr, CSSM_SIZE size, void* alloc_ref) { |
| 32 return realloc(ptr, size); | 33 return realloc(ptr, size); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void* CSSMCalloc(uint32 num, CSSM_SIZE size, void* alloc_ref) { | 36 void* CSSMCalloc(uint32_t num, CSSM_SIZE size, void* alloc_ref) { |
| 36 return calloc(num, size); | 37 return calloc(num, size); |
| 37 } | 38 } |
| 38 | 39 |
| 39 class CSSMInitSingleton { | 40 class CSSMInitSingleton { |
| 40 public: | 41 public: |
| 41 static CSSMInitSingleton* GetInstance() { | 42 static CSSMInitSingleton* GetInstance() { |
| 42 return base::Singleton<CSSMInitSingleton, base::LeakySingletonTraits< | 43 return base::Singleton<CSSMInitSingleton, base::LeakySingletonTraits< |
| 43 CSSMInitSingleton>>::get(); | 44 CSSMInitSingleton>>::get(); |
| 44 } | 45 } |
| 45 | 46 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 196 } |
| 196 | 197 |
| 197 ScopedCSSMData::~ScopedCSSMData() { | 198 ScopedCSSMData::~ScopedCSSMData() { |
| 198 if (data_.Data) { | 199 if (data_.Data) { |
| 199 CSSMFree(data_.Data); | 200 CSSMFree(data_.Data); |
| 200 data_.Data = NULL; | 201 data_.Data = NULL; |
| 201 } | 202 } |
| 202 } | 203 } |
| 203 | 204 |
| 204 } // namespace crypto | 205 } // namespace crypto |
| OLD | NEW |