Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: crypto/mock_keychain_mac.cc

Issue 10738003: src/crypto should build on the x86_64 architecture. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: used typedefs (to uintptr_t) for keys and items. changed password_data_count_'s type to int. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« crypto/mock_keychain_mac.h ('K') | « crypto/mock_keychain_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(MockKeychainKeyType 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
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<MockKeychainKeyType, 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
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(MockKeychainItemType 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(
114 MockKeychainItemType item,
115 UInt32 tag,
116 const char* value) {
114 SetTestDataBytes(item, tag, value, value ? strlen(value) : 0); 117 SetTestDataBytes(item, tag, value, value ? strlen(value) : 0);
115 } 118 }
116 119
117 void MockKeychain::SetTestDataPort(int item, UInt32 value) { 120 void MockKeychain::SetTestDataPort(MockKeychainItemType item, UInt32 value) {
118 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], 121 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
119 kSecPortItemAttr); 122 kSecPortItemAttr);
120 UInt32* data = static_cast<UInt32*>(attribute->data); 123 UInt32* data = static_cast<UInt32*>(attribute->data);
121 *data = value; 124 *data = value;
122 } 125 }
123 126
124 void MockKeychain::SetTestDataProtocol(int item, SecProtocolType value) { 127 void MockKeychain::SetTestDataProtocol(MockKeychainItemType item,
128 SecProtocolType value) {
125 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], 129 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
126 kSecProtocolItemAttr); 130 kSecProtocolItemAttr);
127 SecProtocolType* data = static_cast<SecProtocolType*>(attribute->data); 131 SecProtocolType* data = static_cast<SecProtocolType*>(attribute->data);
128 *data = value; 132 *data = value;
129 } 133 }
130 134
131 void MockKeychain::SetTestDataAuthType(int item, SecAuthenticationType value) { 135 void MockKeychain::SetTestDataAuthType(
136 MockKeychainItemType item,
137 SecAuthenticationType value) {
132 SecKeychainAttribute* attribute = AttributeWithTag( 138 SecKeychainAttribute* attribute = AttributeWithTag(
133 keychain_attr_list_[item], kSecAuthenticationTypeItemAttr); 139 keychain_attr_list_[item], kSecAuthenticationTypeItemAttr);
134 SecAuthenticationType* data = static_cast<SecAuthenticationType*>( 140 SecAuthenticationType* data = static_cast<SecAuthenticationType*>(
135 attribute->data); 141 attribute->data);
136 *data = value; 142 *data = value;
137 } 143 }
138 144
139 void MockKeychain::SetTestDataNegativeItem(int item, Boolean value) { 145 void MockKeychain::SetTestDataNegativeItem(MockKeychainItemType item,
146 Boolean value) {
140 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], 147 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
141 kSecNegativeItemAttr); 148 kSecNegativeItemAttr);
142 Boolean* data = static_cast<Boolean*>(attribute->data); 149 Boolean* data = static_cast<Boolean*>(attribute->data);
143 *data = value; 150 *data = value;
144 } 151 }
145 152
146 void MockKeychain::SetTestDataCreator(int item, OSType value) { 153 void MockKeychain::SetTestDataCreator(MockKeychainItemType item, OSType value) {
147 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], 154 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
148 kSecCreatorItemAttr); 155 kSecCreatorItemAttr);
149 OSType* data = static_cast<OSType*>(attribute->data); 156 OSType* data = static_cast<OSType*>(attribute->data);
150 *data = value; 157 *data = value;
151 } 158 }
152 159
153 void MockKeychain::SetTestDataPasswordBytes(int item, const void* data, 160 void MockKeychain::SetTestDataPasswordBytes(MockKeychainItemType item,
161 const void* data,
154 size_t length) { 162 size_t length) {
155 keychain_data_[item].length = length; 163 keychain_data_[item].length = length;
156 if (length > 0) { 164 if (length > 0) {
157 if (keychain_data_[item].data) 165 if (keychain_data_[item].data)
158 free(keychain_data_[item].data); 166 free(keychain_data_[item].data);
159 keychain_data_[item].data = malloc(length); 167 keychain_data_[item].data = malloc(length);
160 memcpy(keychain_data_[item].data, data, length); 168 memcpy(keychain_data_[item].data, data, length);
161 } else { 169 } else {
162 keychain_data_[item].data = NULL; 170 keychain_data_[item].data = NULL;
163 } 171 }
164 } 172 }
165 173
166 void MockKeychain::SetTestDataPasswordString(int item, const char* value) { 174 void MockKeychain::SetTestDataPasswordString(
175 MockKeychainItemType item,
176 const char* value) {
167 SetTestDataPasswordBytes(item, value, value ? strlen(value) : 0); 177 SetTestDataPasswordBytes(item, value, value ? strlen(value) : 0);
168 } 178 }
169 179
170 OSStatus MockKeychain::ItemCopyAttributesAndData( 180 OSStatus MockKeychain::ItemCopyAttributesAndData(
171 SecKeychainItemRef itemRef, 181 SecKeychainItemRef itemRef,
172 SecKeychainAttributeInfo* info, 182 SecKeychainAttributeInfo* info,
173 SecItemClass* itemClass, 183 SecItemClass* itemClass,
174 SecKeychainAttributeList** attrList, 184 SecKeychainAttributeList** attrList,
175 UInt32* length, 185 UInt32* length,
176 void** outData) const { 186 void** outData) const {
177 DCHECK(itemRef); 187 DCHECK(itemRef);
178 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; 188 MockKeychainKeyType key = reinterpret_cast<MockKeychainKeyType>(itemRef) - 1;
179 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) 189 if (keychain_attr_list_.find(key) == keychain_attr_list_.end())
180 return errSecInvalidItemRef; 190 return errSecInvalidItemRef;
181 191
182 DCHECK(!itemClass); // itemClass not implemented in the Mock. 192 DCHECK(!itemClass); // itemClass not implemented in the Mock.
183 if (attrList) 193 if (attrList)
184 *attrList = &(keychain_attr_list_[key]); 194 *attrList = &(keychain_attr_list_[key]);
185 if (outData) { 195 if (outData) {
186 *outData = keychain_data_[key].data; 196 *outData = keychain_data_[key].data;
187 DCHECK(length); 197 DCHECK(length);
188 *length = keychain_data_[key].length; 198 *length = keychain_data_[key].length;
189 } 199 }
190 200
191 ++attribute_data_copy_count_; 201 ++attribute_data_copy_count_;
192 return noErr; 202 return noErr;
193 } 203 }
194 204
195 OSStatus MockKeychain::ItemModifyAttributesAndData( 205 OSStatus MockKeychain::ItemModifyAttributesAndData(
196 SecKeychainItemRef itemRef, 206 SecKeychainItemRef itemRef,
197 const SecKeychainAttributeList* attrList, 207 const SecKeychainAttributeList* attrList,
198 UInt32 length, 208 UInt32 length,
199 const void* data) const { 209 const void* data) const {
200 DCHECK(itemRef); 210 DCHECK(itemRef);
201 const char* fail_trigger = "fail_me"; 211 const char* fail_trigger = "fail_me";
202 if (length == strlen(fail_trigger) && 212 if (length == strlen(fail_trigger) &&
203 memcmp(data, fail_trigger, length) == 0) { 213 memcmp(data, fail_trigger, length) == 0) {
204 return errSecAuthFailed; 214 return errSecAuthFailed;
205 } 215 }
206 216
207 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; 217 MockKeychainKeyType key = reinterpret_cast<MockKeychainKeyType>(itemRef) - 1;
208 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) 218 if (keychain_attr_list_.find(key) == keychain_attr_list_.end())
209 return errSecInvalidItemRef; 219 return errSecInvalidItemRef;
210 220
211 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); 221 MockKeychain* mutable_this = const_cast<MockKeychain*>(this);
212 if (attrList) { 222 if (attrList) {
213 for (UInt32 change_attr = 0; change_attr < attrList->count; ++change_attr) { 223 for (UInt32 change_attr = 0; change_attr < attrList->count; ++change_attr) {
214 if (attrList->attr[change_attr].tag == kSecCreatorItemAttr) { 224 if (attrList->attr[change_attr].tag == kSecCreatorItemAttr) {
215 void* data = attrList->attr[change_attr].data; 225 void* data = attrList->attr[change_attr].data;
216 mutable_this->SetTestDataCreator(key, *(static_cast<OSType*>(data))); 226 mutable_this->SetTestDataCreator(key, *(static_cast<OSType*>(data)));
217 } else { 227 } else {
218 NOTIMPLEMENTED(); 228 NOTIMPLEMENTED();
219 } 229 }
220 } 230 }
221 } 231 }
222 if (data) 232 if (data)
223 mutable_this->SetTestDataPasswordBytes(key, data, length); 233 mutable_this->SetTestDataPasswordBytes(key, data, length);
224 return noErr; 234 return noErr;
225 } 235 }
226 236
227 OSStatus MockKeychain::ItemFreeAttributesAndData( 237 OSStatus MockKeychain::ItemFreeAttributesAndData(
228 SecKeychainAttributeList* attrList, 238 SecKeychainAttributeList* attrList,
229 void* data) const { 239 void* data) const {
230 --attribute_data_copy_count_; 240 --attribute_data_copy_count_;
231 return noErr; 241 return noErr;
232 } 242 }
233 243
234 OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const { 244 OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const {
235 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; 245 MockKeychainKeyType key = reinterpret_cast<MockKeychainKeyType>(itemRef) - 1;
236 246
237 for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) { 247 for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) {
238 if (keychain_attr_list_[key].attr[i].data) 248 if (keychain_attr_list_[key].attr[i].data)
239 free(keychain_attr_list_[key].attr[i].data); 249 free(keychain_attr_list_[key].attr[i].data);
240 } 250 }
241 free(keychain_attr_list_[key].attr); 251 free(keychain_attr_list_[key].attr);
242 if (keychain_data_[key].data) 252 if (keychain_data_[key].data)
243 free(keychain_data_[key].data); 253 free(keychain_data_[key].data);
244 254
245 keychain_attr_list_.erase(key); 255 keychain_attr_list_.erase(key);
246 keychain_data_.erase(key); 256 keychain_data_.erase(key);
247 added_via_api_.erase(key); 257 added_via_api_.erase(key);
248 return noErr; 258 return noErr;
249 } 259 }
250 260
251 OSStatus MockKeychain::SearchCreateFromAttributes( 261 OSStatus MockKeychain::SearchCreateFromAttributes(
252 CFTypeRef keychainOrArray, 262 CFTypeRef keychainOrArray,
253 SecItemClass itemClass, 263 SecItemClass itemClass,
254 const SecKeychainAttributeList* attrList, 264 const SecKeychainAttributeList* attrList,
255 SecKeychainSearchRef* searchRef) const { 265 SecKeychainSearchRef* searchRef) const {
256 // Figure out which of our mock items matches, and set up the array we'll use 266 // Figure out which of our mock items matches, and set up the array we'll use
257 // to generate results out of SearchCopyNext. 267 // to generate results out of SearchCopyNext.
258 remaining_search_results_.clear(); 268 remaining_search_results_.clear();
259 for (std::map<unsigned int, SecKeychainAttributeList>::const_iterator it = 269 for (std::map<MockKeychainKeyType, SecKeychainAttributeList>
260 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { 270 ::const_iterator it = keychain_attr_list_.begin();
271 it != keychain_attr_list_.end(); ++it) {
261 bool mock_item_matches = true; 272 bool mock_item_matches = true;
262 for (UInt32 search_attr = 0; search_attr < attrList->count; ++search_attr) { 273 for (UInt32 search_attr = 0; search_attr < attrList->count; ++search_attr) {
263 SecKeychainAttribute* mock_attribute = 274 SecKeychainAttribute* mock_attribute =
264 AttributeWithTag(it->second, attrList->attr[search_attr].tag); 275 AttributeWithTag(it->second, attrList->attr[search_attr].tag);
265 if (mock_attribute->length != attrList->attr[search_attr].length || 276 if (mock_attribute->length != attrList->attr[search_attr].length ||
266 memcmp(mock_attribute->data, attrList->attr[search_attr].data, 277 memcmp(mock_attribute->data, attrList->attr[search_attr].data,
267 attrList->attr[search_attr].length) != 0) { 278 attrList->attr[search_attr].length) != 0) {
268 mock_item_matches = false; 279 mock_item_matches = false;
269 break; 280 break;
270 } 281 }
(...skipping 13 matching lines...) Expand all
284 const char* serverName, 295 const char* serverName,
285 UInt32 securityDomainLength, 296 UInt32 securityDomainLength,
286 const char* securityDomain, 297 const char* securityDomain,
287 UInt32 accountNameLength, 298 UInt32 accountNameLength,
288 const char* accountName, 299 const char* accountName,
289 UInt32 pathLength, 300 UInt32 pathLength,
290 const char* path, 301 const char* path,
291 UInt16 port, 302 UInt16 port,
292 SecProtocolType protocol, 303 SecProtocolType protocol,
293 SecAuthenticationType authenticationType) const { 304 SecAuthenticationType authenticationType) const {
294 for (std::map<unsigned int, SecKeychainAttributeList>::const_iterator it = 305 for (std::map<MockKeychainKeyType, SecKeychainAttributeList>
295 keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { 306 ::const_iterator it = keychain_attr_list_.begin();
307 it != keychain_attr_list_.end(); ++it) {
296 SecKeychainAttribute* attribute; 308 SecKeychainAttribute* attribute;
297 attribute = AttributeWithTag(it->second, kSecServerItemAttr); 309 attribute = AttributeWithTag(it->second, kSecServerItemAttr);
298 if ((attribute->length != serverNameLength) || 310 if ((attribute->length != serverNameLength) ||
299 (attribute->data == NULL && *serverName != '\0') || 311 (attribute->data == NULL && *serverName != '\0') ||
300 (attribute->data != NULL && *serverName == '\0') || 312 (attribute->data != NULL && *serverName == '\0') ||
301 strncmp(serverName, 313 strncmp(serverName,
302 (const char*) attribute->data, 314 (const char*) attribute->data,
303 serverNameLength) != 0) { 315 serverNameLength) != 0) {
304 continue; 316 continue;
305 } 317 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (AlreadyContainsInternetPassword(serverNameLength, serverName, 390 if (AlreadyContainsInternetPassword(serverNameLength, serverName,
379 securityDomainLength, securityDomain, 391 securityDomainLength, securityDomain,
380 accountNameLength, accountName, 392 accountNameLength, accountName,
381 pathLength, path, 393 pathLength, path,
382 port, protocol, 394 port, protocol,
383 authenticationType)) { 395 authenticationType)) {
384 return errSecDuplicateItem; 396 return errSecDuplicateItem;
385 } 397 }
386 398
387 // Pick the next unused slot. 399 // Pick the next unused slot.
388 unsigned int key = next_item_key_++; 400 MockKeychainKeyType key = next_item_key_++;
389 401
390 // Initialize keychain data storage at the target location. 402 // Initialize keychain data storage at the target location.
391 InitializeKeychainData(key); 403 InitializeKeychainData(key);
392 404
393 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); 405 MockKeychain* mutable_this = const_cast<MockKeychain*>(this);
394 mutable_this->SetTestDataBytes(key, kSecServerItemAttr, serverName, 406 mutable_this->SetTestDataBytes(key, kSecServerItemAttr, serverName,
395 serverNameLength); 407 serverNameLength);
396 mutable_this->SetTestDataBytes(key, kSecSecurityDomainItemAttr, 408 mutable_this->SetTestDataBytes(key, kSecSecurityDomainItemAttr,
397 securityDomain, securityDomainLength); 409 securityDomain, securityDomainLength);
398 mutable_this->SetTestDataBytes(key, kSecAccountItemAttr, accountName, 410 mutable_this->SetTestDataBytes(key, kSecAccountItemAttr, accountName,
(...skipping 18 matching lines...) Expand all
417 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1); 429 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1);
418 ++keychain_item_copy_count_; 430 ++keychain_item_copy_count_;
419 } 431 }
420 return noErr; 432 return noErr;
421 } 433 }
422 434
423 OSStatus MockKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, 435 OSStatus MockKeychain::SearchCopyNext(SecKeychainSearchRef searchRef,
424 SecKeychainItemRef* itemRef) const { 436 SecKeychainItemRef* itemRef) const {
425 if (remaining_search_results_.empty()) 437 if (remaining_search_results_.empty())
426 return errSecItemNotFound; 438 return errSecItemNotFound;
427 unsigned int key = remaining_search_results_.front(); 439 MockKeychainKeyType key = remaining_search_results_.front();
428 remaining_search_results_.erase(remaining_search_results_.begin()); 440 remaining_search_results_.erase(remaining_search_results_.begin());
429 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1); 441 *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1);
430 ++keychain_item_copy_count_; 442 ++keychain_item_copy_count_;
431 return noErr; 443 return noErr;
432 } 444 }
433 445
434 OSStatus MockKeychain::FindGenericPassword(CFTypeRef keychainOrArray, 446 OSStatus MockKeychain::FindGenericPassword(CFTypeRef keychainOrArray,
435 UInt32 serviceNameLength, 447 UInt32 serviceNameLength,
436 const char* serviceName, 448 const char* serviceName,
437 UInt32 accountNameLength, 449 UInt32 accountNameLength,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 add_generic_password_ = 488 add_generic_password_ =
477 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), 489 std::string(const_cast<char*>(static_cast<const char*>(passwordData)),
478 passwordLength); 490 passwordLength);
479 return noErr; 491 return noErr;
480 } 492 }
481 493
482 void MockKeychain::Free(CFTypeRef ref) const { 494 void MockKeychain::Free(CFTypeRef ref) const {
483 if (!ref) 495 if (!ref)
484 return; 496 return;
485 497
486 if (reinterpret_cast<int>(ref) == kDummySearchRef) { 498 if (reinterpret_cast<MockKeychainKeyType>(ref) == kDummySearchRef) {
487 --search_copy_count_; 499 --search_copy_count_;
488 } else { 500 } else {
489 --keychain_item_copy_count_; 501 --keychain_item_copy_count_;
490 } 502 }
491 } 503 }
492 504
493 int MockKeychain::UnfreedSearchCount() const { 505 int MockKeychain::UnfreedSearchCount() const {
494 return search_copy_count_; 506 return search_copy_count_;
495 } 507 }
496 508
497 int MockKeychain::UnfreedKeychainItemCount() const { 509 int MockKeychain::UnfreedKeychainItemCount() const {
498 return keychain_item_copy_count_; 510 return keychain_item_copy_count_;
499 } 511 }
500 512
501 int MockKeychain::UnfreedAttributeDataCount() const { 513 int MockKeychain::UnfreedAttributeDataCount() const {
502 return attribute_data_copy_count_; 514 return attribute_data_copy_count_;
503 } 515 }
504 516
505 bool MockKeychain::CreatorCodesSetForAddedItems() const { 517 bool MockKeychain::CreatorCodesSetForAddedItems() const {
506 for (std::set<unsigned int>::const_iterator i = added_via_api_.begin(); 518 for (std::set<MockKeychainKeyType>::const_iterator i = added_via_api_.begin();
507 i != added_via_api_.end(); ++i) { 519 i != added_via_api_.end(); ++i) {
508 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[*i], 520 SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[*i],
509 kSecCreatorItemAttr); 521 kSecCreatorItemAttr);
510 OSType* data = static_cast<OSType*>(attribute->data); 522 OSType* data = static_cast<OSType*>(attribute->data);
511 if (*data == 0) 523 if (*data == 0)
512 return false; 524 return false;
513 } 525 }
514 return true; 526 return true;
515 } 527 }
516 528
517 void MockKeychain::AddTestItem(const KeychainTestData& item_data) { 529 void MockKeychain::AddTestItem(const KeychainTestData& item_data) {
518 unsigned int key = next_item_key_++; 530 MockKeychainKeyType key = next_item_key_++;
519 531
520 InitializeKeychainData(key); 532 InitializeKeychainData(key);
521 SetTestDataAuthType(key, item_data.auth_type); 533 SetTestDataAuthType(key, item_data.auth_type);
522 SetTestDataString(key, kSecServerItemAttr, item_data.server); 534 SetTestDataString(key, kSecServerItemAttr, item_data.server);
523 SetTestDataProtocol(key, item_data.protocol); 535 SetTestDataProtocol(key, item_data.protocol);
524 SetTestDataString(key, kSecPathItemAttr, item_data.path); 536 SetTestDataString(key, kSecPathItemAttr, item_data.path);
525 SetTestDataPort(key, item_data.port); 537 SetTestDataPort(key, item_data.port);
526 SetTestDataString(key, kSecSecurityDomainItemAttr, 538 SetTestDataString(key, kSecSecurityDomainItemAttr,
527 item_data.security_domain); 539 item_data.security_domain);
528 SetTestDataString(key, kSecCreationDateItemAttr, item_data.creation_date); 540 SetTestDataString(key, kSecCreationDateItemAttr, item_data.creation_date);
529 SetTestDataString(key, kSecAccountItemAttr, item_data.username); 541 SetTestDataString(key, kSecAccountItemAttr, item_data.username);
530 SetTestDataPasswordString(key, item_data.password); 542 SetTestDataPasswordString(key, item_data.password);
531 SetTestDataNegativeItem(key, item_data.negative_item); 543 SetTestDataNegativeItem(key, item_data.negative_item);
532 } 544 }
533 545
534 } // namespace crypto 546 } // namespace crypto
OLDNEW
« crypto/mock_keychain_mac.h ('K') | « crypto/mock_keychain_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698