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

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

Powered by Google App Engine
This is Rietveld 408576698