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 #include "crypto/capi_util.h" | 5 #include "crypto/capi_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 #include <stdlib.h> |
9 #include "base/macros.h" | |
10 #include "base/memory/singleton.h" | |
11 #include "base/synchronization/lock.h" | |
12 | |
13 namespace { | |
14 | |
15 class CAPIUtilSingleton { | |
16 public: | |
17 static CAPIUtilSingleton* GetInstance() { | |
18 return base::Singleton<CAPIUtilSingleton>::get(); | |
19 } | |
20 | |
21 // Returns a lock to guard calls to CryptAcquireContext with | |
22 // CRYPT_DELETEKEYSET or CRYPT_NEWKEYSET. | |
23 base::Lock& acquire_context_lock() { | |
24 return acquire_context_lock_; | |
25 } | |
26 | |
27 private: | |
28 friend class base::Singleton<CAPIUtilSingleton>; | |
29 friend struct base::DefaultSingletonTraits<CAPIUtilSingleton>; | |
30 | |
31 CAPIUtilSingleton() {} | |
32 | |
33 base::Lock acquire_context_lock_; | |
34 | |
35 DISALLOW_COPY_AND_ASSIGN(CAPIUtilSingleton); | |
36 }; | |
37 | |
38 } // namespace | |
39 | 9 |
40 namespace crypto { | 10 namespace crypto { |
41 | 11 |
42 BOOL CryptAcquireContextLocked(HCRYPTPROV* prov, | |
43 LPCWSTR container, | |
44 LPCWSTR provider, | |
45 DWORD prov_type, | |
46 DWORD flags) { | |
47 base::AutoLock lock(CAPIUtilSingleton::GetInstance()->acquire_context_lock()); | |
48 return CryptAcquireContext(prov, container, provider, prov_type, flags); | |
49 } | |
50 | |
51 void* WINAPI CryptAlloc(size_t size) { | 12 void* WINAPI CryptAlloc(size_t size) { |
52 return malloc(size); | 13 return malloc(size); |
53 } | 14 } |
54 | 15 |
55 void WINAPI CryptFree(void* p) { | 16 void WINAPI CryptFree(void* p) { |
56 free(p); | 17 free(p); |
57 } | 18 } |
58 | 19 |
59 } // namespace crypto | 20 } // namespace crypto |
OLD | NEW |