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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/time.h" | 6 #include "base/time.h" |
7 #include "crypto/mock_keychain_mac.h" | 7 #include "crypto/mock_keychain_mac.h" |
8 | 8 |
9 namespace crypto { | 9 namespace crypto { |
10 | 10 |
11 MockKeychain::MockKeychain() | 11 MockKeychain::MockKeychain() |
12 : next_item_key_(0), | 12 : next_item_key_(0), |
13 search_copy_count_(0), | 13 search_copy_count_(0), |
14 keychain_item_copy_count_(0), | 14 keychain_item_copy_count_(0), |
15 attribute_data_copy_count_(0), | 15 attribute_data_copy_count_(0), |
16 find_generic_result_(noErr), | 16 find_generic_result_(noErr), |
17 called_add_generic_(false), | 17 called_add_generic_(false), |
18 password_data_count_(0) {} | 18 password_data_count_(0) {} |
19 | 19 |
20 void MockKeychain::InitializeKeychainData(unsigned int key) const { | 20 void MockKeychain::InitializeKeychainData(uintptr_t key) const { |
21 UInt32 tags[] = { kSecAccountItemAttr, | 21 UInt32 tags[] = { kSecAccountItemAttr, |
22 kSecServerItemAttr, | 22 kSecServerItemAttr, |
23 kSecPortItemAttr, | 23 kSecPortItemAttr, |
24 kSecPathItemAttr, | 24 kSecPathItemAttr, |
25 kSecProtocolItemAttr, | 25 kSecProtocolItemAttr, |
26 kSecAuthenticationTypeItemAttr, | 26 kSecAuthenticationTypeItemAttr, |
27 kSecSecurityDomainItemAttr, | 27 kSecSecurityDomainItemAttr, |
28 kSecCreationDateItemAttr, | 28 kSecCreationDateItemAttr, |
29 kSecNegativeItemAttr, | 29 kSecNegativeItemAttr, |
30 kSecCreatorItemAttr }; | 30 kSecCreatorItemAttr }; |
(...skipping 23 matching lines...) Expand all Loading... | |
54 break; | 54 break; |
55 } | 55 } |
56 if (data_size > 0) { | 56 if (data_size > 0) { |
57 keychain_attr_list_[key].attr[i].length = data_size; | 57 keychain_attr_list_[key].attr[i].length = data_size; |
58 keychain_attr_list_[key].attr[i].data = calloc(1, data_size); | 58 keychain_attr_list_[key].attr[i].data = calloc(1, data_size); |
59 } | 59 } |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 MockKeychain::~MockKeychain() { | 63 MockKeychain::~MockKeychain() { |
64 for (std::map<unsigned int, SecKeychainAttributeList>::iterator it = | 64 for (std::map<uintptr_t, SecKeychainAttributeList>::iterator it = |
65 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { | 65 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { |
66 for (unsigned int i = 0; i < it->second.count; ++i) { | 66 for (unsigned int i = 0; i < it->second.count; ++i) { |
67 if (it->second.attr[i].data) | 67 if (it->second.attr[i].data) |
68 free(it->second.attr[i].data); | 68 free(it->second.attr[i].data); |
69 } | 69 } |
70 free(it->second.attr); | 70 free(it->second.attr); |
71 if (keychain_data_[it->first].data) | 71 if (keychain_data_[it->first].data) |
72 free(keychain_data_[it->first].data); | 72 free(keychain_data_[it->first].data); |
73 } | 73 } |
74 keychain_attr_list_.clear(); | 74 keychain_attr_list_.clear(); |
(...skipping 10 matching lines...) Expand all Loading... | |
85 break; | 85 break; |
86 } | 86 } |
87 } | 87 } |
88 if (attribute_index == -1) { | 88 if (attribute_index == -1) { |
89 NOTREACHED() << "Unsupported attribute: " << tag; | 89 NOTREACHED() << "Unsupported attribute: " << tag; |
90 return NULL; | 90 return NULL; |
91 } | 91 } |
92 return &(attribute_list.attr[attribute_index]); | 92 return &(attribute_list.attr[attribute_index]); |
93 } | 93 } |
94 | 94 |
95 void MockKeychain::SetTestDataBytes(int item, | 95 void MockKeychain::SetTestDataBytes(uintptr_t item, |
96 UInt32 tag, | 96 UInt32 tag, |
97 const void* data, | 97 const void* data, |
98 size_t length) { | 98 size_t length) { |
99 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], | 99 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], |
100 tag); | 100 tag); |
101 attribute->length = length; | 101 attribute->length = length; |
102 if (length > 0) { | 102 if (length > 0) { |
103 if (attribute->data) | 103 if (attribute->data) |
104 free(attribute->data); | 104 free(attribute->data); |
105 attribute->data = malloc(length); | 105 attribute->data = malloc(length); |
106 CHECK(attribute->data); | 106 CHECK(attribute->data); |
107 memcpy(attribute->data, data, length); | 107 memcpy(attribute->data, data, length); |
108 } else { | 108 } else { |
109 attribute->data = NULL; | 109 attribute->data = NULL; |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void MockKeychain::SetTestDataString(int item, UInt32 tag, const char* value) { | 113 void MockKeychain::SetTestDataString(uintptr_t item, |
114 UInt32 tag, | |
115 const char* value) { | |
wtc
2012/07/16 23:00:40
Nit: the second and third arguments need to be ali
| |
114 SetTestDataBytes(item, tag, value, value ? strlen(value) : 0); | 116 SetTestDataBytes(item, tag, value, value ? strlen(value) : 0); |
115 } | 117 } |
116 | 118 |
117 void MockKeychain::SetTestDataPort(int item, UInt32 value) { | 119 void MockKeychain::SetTestDataPort(uintptr_t item, UInt32 value) { |
118 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], | 120 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], |
119 kSecPortItemAttr); | 121 kSecPortItemAttr); |
120 UInt32* data = static_cast<UInt32*>(attribute->data); | 122 UInt32* data = static_cast<UInt32*>(attribute->data); |
121 *data = value; | 123 *data = value; |
122 } | 124 } |
123 | 125 |
124 void MockKeychain::SetTestDataProtocol(int item, SecProtocolType value) { | 126 void MockKeychain::SetTestDataProtocol(uintptr_t item, SecProtocolType value) { |
125 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], | 127 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], |
126 kSecProtocolItemAttr); | 128 kSecProtocolItemAttr); |
127 SecProtocolType* data = static_cast<SecProtocolType*>(attribute->data); | 129 SecProtocolType* data = static_cast<SecProtocolType*>(attribute->data); |
128 *data = value; | 130 *data = value; |
129 } | 131 } |
130 | 132 |
131 void MockKeychain::SetTestDataAuthType(int item, SecAuthenticationType value) { | 133 void MockKeychain::SetTestDataAuthType(uintptr_t item, |
134 SecAuthenticationType value) { | |
wtc
2012/07/16 23:00:40
Nit: fix indentation of the second argument here a
| |
132 SecKeychainAttribute* attribute = AttributeWithTag( | 135 SecKeychainAttribute* attribute = AttributeWithTag( |
133 keychain_attr_list_[item], kSecAuthenticationTypeItemAttr); | 136 keychain_attr_list_[item], kSecAuthenticationTypeItemAttr); |
134 SecAuthenticationType* data = static_cast<SecAuthenticationType*>( | 137 SecAuthenticationType* data = static_cast<SecAuthenticationType*>( |
135 attribute->data); | 138 attribute->data); |
136 *data = value; | 139 *data = value; |
137 } | 140 } |
138 | 141 |
139 void MockKeychain::SetTestDataNegativeItem(int item, Boolean value) { | 142 void MockKeychain::SetTestDataNegativeItem(uintptr_t item, Boolean value) { |
140 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], | 143 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], |
141 kSecNegativeItemAttr); | 144 kSecNegativeItemAttr); |
142 Boolean* data = static_cast<Boolean*>(attribute->data); | 145 Boolean* data = static_cast<Boolean*>(attribute->data); |
143 *data = value; | 146 *data = value; |
144 } | 147 } |
145 | 148 |
146 void MockKeychain::SetTestDataCreator(int item, OSType value) { | 149 void MockKeychain::SetTestDataCreator(uintptr_t item, OSType value) { |
147 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], | 150 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], |
148 kSecCreatorItemAttr); | 151 kSecCreatorItemAttr); |
149 OSType* data = static_cast<OSType*>(attribute->data); | 152 OSType* data = static_cast<OSType*>(attribute->data); |
150 *data = value; | 153 *data = value; |
151 } | 154 } |
152 | 155 |
153 void MockKeychain::SetTestDataPasswordBytes(int item, const void* data, | 156 void MockKeychain::SetTestDataPasswordBytes(uintptr_t item, const void* data, |
154 size_t length) { | 157 size_t length) { |
155 keychain_data_[item].length = length; | 158 keychain_data_[item].length = length; |
156 if (length > 0) { | 159 if (length > 0) { |
157 if (keychain_data_[item].data) | 160 if (keychain_data_[item].data) |
158 free(keychain_data_[item].data); | 161 free(keychain_data_[item].data); |
159 keychain_data_[item].data = malloc(length); | 162 keychain_data_[item].data = malloc(length); |
160 memcpy(keychain_data_[item].data, data, length); | 163 memcpy(keychain_data_[item].data, data, length); |
161 } else { | 164 } else { |
162 keychain_data_[item].data = NULL; | 165 keychain_data_[item].data = NULL; |
163 } | 166 } |
164 } | 167 } |
165 | 168 |
166 void MockKeychain::SetTestDataPasswordString(int item, const char* value) { | 169 void MockKeychain::SetTestDataPasswordString(uintptr_t item, |
170 const char* value) { | |
167 SetTestDataPasswordBytes(item, value, value ? strlen(value) : 0); | 171 SetTestDataPasswordBytes(item, value, value ? strlen(value) : 0); |
168 } | 172 } |
169 | 173 |
170 OSStatus MockKeychain::ItemCopyAttributesAndData( | 174 OSStatus MockKeychain::ItemCopyAttributesAndData( |
171 SecKeychainItemRef itemRef, | 175 SecKeychainItemRef itemRef, |
172 SecKeychainAttributeInfo* info, | 176 SecKeychainAttributeInfo* info, |
173 SecItemClass* itemClass, | 177 SecItemClass* itemClass, |
174 SecKeychainAttributeList** attrList, | 178 SecKeychainAttributeList** attrList, |
175 UInt32* length, | 179 UInt32* length, |
176 void** outData) const { | 180 void** outData) const { |
177 DCHECK(itemRef); | 181 DCHECK(itemRef); |
178 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; | 182 uintptr_t key = reinterpret_cast<uintptr_t>(itemRef) - 1; |
179 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) | 183 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) |
180 return errSecInvalidItemRef; | 184 return errSecInvalidItemRef; |
181 | 185 |
182 DCHECK(!itemClass); // itemClass not implemented in the Mock. | 186 DCHECK(!itemClass); // itemClass not implemented in the Mock. |
183 if (attrList) | 187 if (attrList) |
184 *attrList = &(keychain_attr_list_[key]); | 188 *attrList = &(keychain_attr_list_[key]); |
185 if (outData) { | 189 if (outData) { |
186 *outData = keychain_data_[key].data; | 190 *outData = keychain_data_[key].data; |
187 DCHECK(length); | 191 DCHECK(length); |
188 *length = keychain_data_[key].length; | 192 *length = keychain_data_[key].length; |
189 } | 193 } |
190 | 194 |
191 ++attribute_data_copy_count_; | 195 ++attribute_data_copy_count_; |
192 return noErr; | 196 return noErr; |
193 } | 197 } |
194 | 198 |
195 OSStatus MockKeychain::ItemModifyAttributesAndData( | 199 OSStatus MockKeychain::ItemModifyAttributesAndData( |
196 SecKeychainItemRef itemRef, | 200 SecKeychainItemRef itemRef, |
197 const SecKeychainAttributeList* attrList, | 201 const SecKeychainAttributeList* attrList, |
198 UInt32 length, | 202 UInt32 length, |
199 const void* data) const { | 203 const void* data) const { |
200 DCHECK(itemRef); | 204 DCHECK(itemRef); |
201 const char* fail_trigger = "fail_me"; | 205 const char* fail_trigger = "fail_me"; |
202 if (length == strlen(fail_trigger) && | 206 if (length == strlen(fail_trigger) && |
203 memcmp(data, fail_trigger, length) == 0) { | 207 memcmp(data, fail_trigger, length) == 0) { |
204 return errSecAuthFailed; | 208 return errSecAuthFailed; |
205 } | 209 } |
206 | 210 |
207 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; | 211 uintptr_t key = reinterpret_cast<uintptr_t>(itemRef) - 1; |
208 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) | 212 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) |
209 return errSecInvalidItemRef; | 213 return errSecInvalidItemRef; |
210 | 214 |
211 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); | 215 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); |
212 if (attrList) { | 216 if (attrList) { |
213 for (UInt32 change_attr = 0; change_attr < attrList->count; ++change_attr) { | 217 for (UInt32 change_attr = 0; change_attr < attrList->count; ++change_attr) { |
214 if (attrList->attr[change_attr].tag == kSecCreatorItemAttr) { | 218 if (attrList->attr[change_attr].tag == kSecCreatorItemAttr) { |
215 void* data = attrList->attr[change_attr].data; | 219 void* data = attrList->attr[change_attr].data; |
216 mutable_this->SetTestDataCreator(key, *(static_cast<OSType*>(data))); | 220 mutable_this->SetTestDataCreator(key, *(static_cast<OSType*>(data))); |
217 } else { | 221 } else { |
218 NOTIMPLEMENTED(); | 222 NOTIMPLEMENTED(); |
219 } | 223 } |
220 } | 224 } |
221 } | 225 } |
222 if (data) | 226 if (data) |
223 mutable_this->SetTestDataPasswordBytes(key, data, length); | 227 mutable_this->SetTestDataPasswordBytes(key, data, length); |
224 return noErr; | 228 return noErr; |
225 } | 229 } |
226 | 230 |
227 OSStatus MockKeychain::ItemFreeAttributesAndData( | 231 OSStatus MockKeychain::ItemFreeAttributesAndData( |
228 SecKeychainAttributeList* attrList, | 232 SecKeychainAttributeList* attrList, |
229 void* data) const { | 233 void* data) const { |
230 --attribute_data_copy_count_; | 234 --attribute_data_copy_count_; |
231 return noErr; | 235 return noErr; |
232 } | 236 } |
233 | 237 |
234 OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const { | 238 OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const { |
235 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; | 239 uintptr_t key = reinterpret_cast<uintptr_t>(itemRef) - 1; |
236 | 240 |
237 for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) { | 241 for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) { |
238 if (keychain_attr_list_[key].attr[i].data) | 242 if (keychain_attr_list_[key].attr[i].data) |
239 free(keychain_attr_list_[key].attr[i].data); | 243 free(keychain_attr_list_[key].attr[i].data); |
240 } | 244 } |
241 free(keychain_attr_list_[key].attr); | 245 free(keychain_attr_list_[key].attr); |
242 if (keychain_data_[key].data) | 246 if (keychain_data_[key].data) |
243 free(keychain_data_[key].data); | 247 free(keychain_data_[key].data); |
244 | 248 |
245 keychain_attr_list_.erase(key); | 249 keychain_attr_list_.erase(key); |
246 keychain_data_.erase(key); | 250 keychain_data_.erase(key); |
247 added_via_api_.erase(key); | 251 added_via_api_.erase(key); |
248 return noErr; | 252 return noErr; |
249 } | 253 } |
250 | 254 |
251 OSStatus MockKeychain::SearchCreateFromAttributes( | 255 OSStatus MockKeychain::SearchCreateFromAttributes( |
252 CFTypeRef keychainOrArray, | 256 CFTypeRef keychainOrArray, |
253 SecItemClass itemClass, | 257 SecItemClass itemClass, |
254 const SecKeychainAttributeList* attrList, | 258 const SecKeychainAttributeList* attrList, |
255 SecKeychainSearchRef* searchRef) const { | 259 SecKeychainSearchRef* searchRef) const { |
256 // Figure out which of our mock items matches, and set up the array we'll use | 260 // Figure out which of our mock items matches, and set up the array we'll use |
257 // to generate results out of SearchCopyNext. | 261 // to generate results out of SearchCopyNext. |
258 remaining_search_results_.clear(); | 262 remaining_search_results_.clear(); |
259 for (std::map<unsigned int, SecKeychainAttributeList>::const_iterator it = | 263 for (std::map<uintptr_t, SecKeychainAttributeList>::const_iterator it = |
260 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { | 264 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { |
261 bool mock_item_matches = true; | 265 bool mock_item_matches = true; |
262 for (UInt32 search_attr = 0; search_attr < attrList->count; ++search_attr) { | 266 for (UInt32 search_attr = 0; search_attr < attrList->count; ++search_attr) { |
263 SecKeychainAttribute* mock_attribute = | 267 SecKeychainAttribute* mock_attribute = |
264 AttributeWithTag(it->second, attrList->attr[search_attr].tag); | 268 AttributeWithTag(it->second, attrList->attr[search_attr].tag); |
265 if (mock_attribute->length != attrList->attr[search_attr].length || | 269 if (mock_attribute->length != attrList->attr[search_attr].length || |
266 memcmp(mock_attribute->data, attrList->attr[search_attr].data, | 270 memcmp(mock_attribute->data, attrList->attr[search_attr].data, |
267 attrList->attr[search_attr].length) != 0) { | 271 attrList->attr[search_attr].length) != 0) { |
268 mock_item_matches = false; | 272 mock_item_matches = false; |
269 break; | 273 break; |
(...skipping 14 matching lines...) Expand all Loading... | |
284 const char* serverName, | 288 const char* serverName, |
285 UInt32 securityDomainLength, | 289 UInt32 securityDomainLength, |
286 const char* securityDomain, | 290 const char* securityDomain, |
287 UInt32 accountNameLength, | 291 UInt32 accountNameLength, |
288 const char* accountName, | 292 const char* accountName, |
289 UInt32 pathLength, | 293 UInt32 pathLength, |
290 const char* path, | 294 const char* path, |
291 UInt16 port, | 295 UInt16 port, |
292 SecProtocolType protocol, | 296 SecProtocolType protocol, |
293 SecAuthenticationType authenticationType) const { | 297 SecAuthenticationType authenticationType) const { |
294 for (std::map<unsigned int, SecKeychainAttributeList>::const_iterator it = | 298 for (std::map<uintptr_t, SecKeychainAttributeList>::const_iterator it = |
295 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { | 299 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { |
296 SecKeychainAttribute* attribute; | 300 SecKeychainAttribute* attribute; |
297 attribute = AttributeWithTag(it->second, kSecServerItemAttr); | 301 attribute = AttributeWithTag(it->second, kSecServerItemAttr); |
298 if ((attribute->length != serverNameLength) || | 302 if ((attribute->length != serverNameLength) || |
299 (attribute->data == NULL && *serverName != '\0') || | 303 (attribute->data == NULL && *serverName != '\0') || |
300 (attribute->data != NULL && *serverName == '\0') || | 304 (attribute->data != NULL && *serverName == '\0') || |
301 strncmp(serverName, | 305 strncmp(serverName, |
302 (const char*) attribute->data, | 306 (const char*) attribute->data, |
303 serverNameLength) != 0) { | 307 serverNameLength) != 0) { |
304 continue; | 308 continue; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 if (AlreadyContainsInternetPassword(serverNameLength, serverName, | 382 if (AlreadyContainsInternetPassword(serverNameLength, serverName, |
379 securityDomainLength, securityDomain, | 383 securityDomainLength, securityDomain, |
380 accountNameLength, accountName, | 384 accountNameLength, accountName, |
381 pathLength, path, | 385 pathLength, path, |
382 port, protocol, | 386 port, protocol, |
383 authenticationType)) { | 387 authenticationType)) { |
384 return errSecDuplicateItem; | 388 return errSecDuplicateItem; |
385 } | 389 } |
386 | 390 |
387 // Pick the next unused slot. | 391 // Pick the next unused slot. |
388 unsigned int key = next_item_key_++; | 392 uintptr_t key = next_item_key_++; |
389 | 393 |
390 // Initialize keychain data storage at the target location. | 394 // Initialize keychain data storage at the target location. |
391 InitializeKeychainData(key); | 395 InitializeKeychainData(key); |
392 | 396 |
393 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); | 397 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); |
394 mutable_this->SetTestDataBytes(key, kSecServerItemAttr, serverName, | 398 mutable_this->SetTestDataBytes(key, kSecServerItemAttr, serverName, |
395 serverNameLength); | 399 serverNameLength); |
396 mutable_this->SetTestDataBytes(key, kSecSecurityDomainItemAttr, | 400 mutable_this->SetTestDataBytes(key, kSecSecurityDomainItemAttr, |
397 securityDomain, securityDomainLength); | 401 securityDomain, securityDomainLength); |
398 mutable_this->SetTestDataBytes(key, kSecAccountItemAttr, accountName, | 402 mutable_this->SetTestDataBytes(key, kSecAccountItemAttr, accountName, |
(...skipping 18 matching lines...) Expand all Loading... | |
417 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1); | 421 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1); |
418 ++keychain_item_copy_count_; | 422 ++keychain_item_copy_count_; |
419 } | 423 } |
420 return noErr; | 424 return noErr; |
421 } | 425 } |
422 | 426 |
423 OSStatus MockKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, | 427 OSStatus MockKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, |
424 SecKeychainItemRef* itemRef) const { | 428 SecKeychainItemRef* itemRef) const { |
425 if (remaining_search_results_.empty()) | 429 if (remaining_search_results_.empty()) |
426 return errSecItemNotFound; | 430 return errSecItemNotFound; |
427 unsigned int key = remaining_search_results_.front(); | 431 uintptr_t key = remaining_search_results_.front(); |
428 remaining_search_results_.erase(remaining_search_results_.begin()); | 432 remaining_search_results_.erase(remaining_search_results_.begin()); |
429 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1); | 433 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1); |
430 ++keychain_item_copy_count_; | 434 ++keychain_item_copy_count_; |
431 return noErr; | 435 return noErr; |
432 } | 436 } |
433 | 437 |
434 OSStatus MockKeychain::FindGenericPassword(CFTypeRef keychainOrArray, | 438 OSStatus MockKeychain::FindGenericPassword(CFTypeRef keychainOrArray, |
435 UInt32 serviceNameLength, | 439 UInt32 serviceNameLength, |
436 const char* serviceName, | 440 const char* serviceName, |
437 UInt32 accountNameLength, | 441 UInt32 accountNameLength, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 add_generic_password_ = | 480 add_generic_password_ = |
477 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), | 481 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), |
478 passwordLength); | 482 passwordLength); |
479 return noErr; | 483 return noErr; |
480 } | 484 } |
481 | 485 |
482 void MockKeychain::Free(CFTypeRef ref) const { | 486 void MockKeychain::Free(CFTypeRef ref) const { |
483 if (!ref) | 487 if (!ref) |
484 return; | 488 return; |
485 | 489 |
486 if (reinterpret_cast<int>(ref) == kDummySearchRef) { | 490 if (reinterpret_cast<uintptr_t>(ref) == kDummySearchRef) { |
487 --search_copy_count_; | 491 --search_copy_count_; |
488 } else { | 492 } else { |
489 --keychain_item_copy_count_; | 493 --keychain_item_copy_count_; |
490 } | 494 } |
491 } | 495 } |
492 | 496 |
493 int MockKeychain::UnfreedSearchCount() const { | 497 int MockKeychain::UnfreedSearchCount() const { |
494 return search_copy_count_; | 498 return search_copy_count_; |
495 } | 499 } |
496 | 500 |
(...skipping 11 matching lines...) Expand all Loading... | |
508 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[*i], | 512 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[*i], |
509 kSecCreatorItemAttr); | 513 kSecCreatorItemAttr); |
510 OSType* data = static_cast<OSType*>(attribute->data); | 514 OSType* data = static_cast<OSType*>(attribute->data); |
511 if (*data == 0) | 515 if (*data == 0) |
512 return false; | 516 return false; |
513 } | 517 } |
514 return true; | 518 return true; |
515 } | 519 } |
516 | 520 |
517 void MockKeychain::AddTestItem(const KeychainTestData& item_data) { | 521 void MockKeychain::AddTestItem(const KeychainTestData& item_data) { |
518 unsigned int key = next_item_key_++; | 522 uintptr_t key = next_item_key_++; |
519 | 523 |
520 InitializeKeychainData(key); | 524 InitializeKeychainData(key); |
521 SetTestDataAuthType(key, item_data.auth_type); | 525 SetTestDataAuthType(key, item_data.auth_type); |
522 SetTestDataString(key, kSecServerItemAttr, item_data.server); | 526 SetTestDataString(key, kSecServerItemAttr, item_data.server); |
523 SetTestDataProtocol(key, item_data.protocol); | 527 SetTestDataProtocol(key, item_data.protocol); |
524 SetTestDataString(key, kSecPathItemAttr, item_data.path); | 528 SetTestDataString(key, kSecPathItemAttr, item_data.path); |
525 SetTestDataPort(key, item_data.port); | 529 SetTestDataPort(key, item_data.port); |
526 SetTestDataString(key, kSecSecurityDomainItemAttr, | 530 SetTestDataString(key, kSecSecurityDomainItemAttr, |
527 item_data.security_domain); | 531 item_data.security_domain); |
528 SetTestDataString(key, kSecCreationDateItemAttr, item_data.creation_date); | 532 SetTestDataString(key, kSecCreationDateItemAttr, item_data.creation_date); |
529 SetTestDataString(key, kSecAccountItemAttr, item_data.username); | 533 SetTestDataString(key, kSecAccountItemAttr, item_data.username); |
530 SetTestDataPasswordString(key, item_data.password); | 534 SetTestDataPasswordString(key, item_data.password); |
531 SetTestDataNegativeItem(key, item_data.negative_item); | 535 SetTestDataNegativeItem(key, item_data.negative_item); |
532 } | 536 } |
533 | 537 |
534 } // namespace crypto | 538 } // namespace crypto |
OLD | NEW |