Do not move fixed-size packaged apps by dragging shadow
[chromium-blink-merge.git] / crypto / apple_keychain_mac.mm
blob240c32067bcf147858e21746affbe2883cd3d171
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 #include "crypto/apple_keychain.h"
7 #import <Foundation/Foundation.h>
9 #include "base/synchronization/lock.h"
10 #include "crypto/mac_security_services_lock.h"
12 namespace crypto {
14 AppleKeychain::AppleKeychain() {}
16 AppleKeychain::~AppleKeychain() {}
18 OSStatus AppleKeychain::ItemCopyAttributesAndData(
19     SecKeychainItemRef itemRef,
20     SecKeychainAttributeInfo* info,
21     SecItemClass* itemClass,
22     SecKeychainAttributeList** attrList,
23     UInt32* length,
24     void** outData) const {
25   base::AutoLock lock(GetMacSecurityServicesLock());
26   return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass,
27                                               attrList, length, outData);
30 OSStatus AppleKeychain::ItemModifyAttributesAndData(
31     SecKeychainItemRef itemRef,
32     const SecKeychainAttributeList* attrList,
33     UInt32 length,
34     const void* data) const {
35   base::AutoLock lock(GetMacSecurityServicesLock());
36   return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length,
37                                                 data);
40 OSStatus AppleKeychain::ItemFreeAttributesAndData(
41     SecKeychainAttributeList* attrList,
42     void* data) const {
43   base::AutoLock lock(GetMacSecurityServicesLock());
44   return SecKeychainItemFreeAttributesAndData(attrList, data);
47 OSStatus AppleKeychain::ItemDelete(SecKeychainItemRef itemRef) const {
48   base::AutoLock lock(GetMacSecurityServicesLock());
49   return SecKeychainItemDelete(itemRef);
52 OSStatus AppleKeychain::SearchCreateFromAttributes(
53     CFTypeRef keychainOrArray,
54     SecItemClass itemClass,
55     const SecKeychainAttributeList* attrList,
56     SecKeychainSearchRef* searchRef) const {
57   base::AutoLock lock(GetMacSecurityServicesLock());
58   return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass,
59                                                attrList, searchRef);
62 OSStatus AppleKeychain::SearchCopyNext(SecKeychainSearchRef searchRef,
63                                        SecKeychainItemRef* itemRef) const {
64   base::AutoLock lock(GetMacSecurityServicesLock());
65   return SecKeychainSearchCopyNext(searchRef, itemRef);
68 OSStatus AppleKeychain::AddInternetPassword(
69     SecKeychainRef keychain,
70     UInt32 serverNameLength,
71     const char* serverName,
72     UInt32 securityDomainLength,
73     const char* securityDomain,
74     UInt32 accountNameLength,
75     const char* accountName,
76     UInt32 pathLength,
77     const char* path,
78     UInt16 port,
79     SecProtocolType protocol,
80     SecAuthenticationType authenticationType,
81     UInt32 passwordLength,
82     const void* passwordData,
83     SecKeychainItemRef* itemRef) const {
84   base::AutoLock lock(GetMacSecurityServicesLock());
85   return SecKeychainAddInternetPassword(keychain,
86                                         serverNameLength, serverName,
87                                         securityDomainLength, securityDomain,
88                                         accountNameLength, accountName,
89                                         pathLength, path,
90                                         port, protocol, authenticationType,
91                                         passwordLength, passwordData,
92                                         itemRef);
95 OSStatus AppleKeychain::FindGenericPassword(CFTypeRef keychainOrArray,
96                                             UInt32 serviceNameLength,
97                                             const char* serviceName,
98                                             UInt32 accountNameLength,
99                                             const char* accountName,
100                                             UInt32* passwordLength,
101                                             void** passwordData,
102                                             SecKeychainItemRef* itemRef) const {
103   base::AutoLock lock(GetMacSecurityServicesLock());
104   return SecKeychainFindGenericPassword(keychainOrArray,
105                                         serviceNameLength,
106                                         serviceName,
107                                         accountNameLength,
108                                         accountName,
109                                         passwordLength,
110                                         passwordData,
111                                         itemRef);
114 OSStatus AppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList,
115                                         void* data) const {
116   base::AutoLock lock(GetMacSecurityServicesLock());
117   return SecKeychainItemFreeContent(attrList, data);
120 OSStatus AppleKeychain::AddGenericPassword(SecKeychainRef keychain,
121                                            UInt32 serviceNameLength,
122                                            const char* serviceName,
123                                            UInt32 accountNameLength,
124                                            const char* accountName,
125                                            UInt32 passwordLength,
126                                            const void* passwordData,
127                                            SecKeychainItemRef* itemRef) const {
128   base::AutoLock lock(GetMacSecurityServicesLock());
129   return SecKeychainAddGenericPassword(keychain,
130                                        serviceNameLength,
131                                        serviceName,
132                                        accountNameLength,
133                                        accountName,
134                                        passwordLength,
135                                        passwordData,
136                                        itemRef);
139 void AppleKeychain::Free(CFTypeRef ref) const {
140   if (ref)
141     CFRelease(ref);
144 }  // namespace crypto