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 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 168 } |
169 | 169 |
170 OSStatus MockKeychain::ItemCopyAttributesAndData( | 170 OSStatus MockKeychain::ItemCopyAttributesAndData( |
171 SecKeychainItemRef itemRef, | 171 SecKeychainItemRef itemRef, |
172 SecKeychainAttributeInfo* info, | 172 SecKeychainAttributeInfo* info, |
173 SecItemClass* itemClass, | 173 SecItemClass* itemClass, |
174 SecKeychainAttributeList** attrList, | 174 SecKeychainAttributeList** attrList, |
175 UInt32* length, | 175 UInt32* length, |
176 void** outData) const { | 176 void** outData) const { |
177 DCHECK(itemRef); | 177 DCHECK(itemRef); |
178 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; | 178 uintptr_t key = reinterpret_cast<uintptr_t>(itemRef) - 1; |
179 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) | 179 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) |
180 return errSecInvalidItemRef; | 180 return errSecInvalidItemRef; |
181 | 181 |
182 DCHECK(!itemClass); // itemClass not implemented in the Mock. | 182 DCHECK(!itemClass); // itemClass not implemented in the Mock. |
183 if (attrList) | 183 if (attrList) |
184 *attrList = &(keychain_attr_list_[key]); | 184 *attrList = &(keychain_attr_list_[key]); |
185 if (outData) { | 185 if (outData) { |
186 *outData = keychain_data_[key].data; | 186 *outData = keychain_data_[key].data; |
187 DCHECK(length); | 187 DCHECK(length); |
188 *length = keychain_data_[key].length; | 188 *length = keychain_data_[key].length; |
189 } | 189 } |
190 | 190 |
191 ++attribute_data_copy_count_; | 191 ++attribute_data_copy_count_; |
192 return noErr; | 192 return noErr; |
193 } | 193 } |
194 | 194 |
195 OSStatus MockKeychain::ItemModifyAttributesAndData( | 195 OSStatus MockKeychain::ItemModifyAttributesAndData( |
196 SecKeychainItemRef itemRef, | 196 SecKeychainItemRef itemRef, |
197 const SecKeychainAttributeList* attrList, | 197 const SecKeychainAttributeList* attrList, |
198 UInt32 length, | 198 UInt32 length, |
199 const void* data) const { | 199 const void* data) const { |
200 DCHECK(itemRef); | 200 DCHECK(itemRef); |
201 const char* fail_trigger = "fail_me"; | 201 const char* fail_trigger = "fail_me"; |
202 if (length == strlen(fail_trigger) && | 202 if (length == strlen(fail_trigger) && |
203 memcmp(data, fail_trigger, length) == 0) { | 203 memcmp(data, fail_trigger, length) == 0) { |
204 return errSecAuthFailed; | 204 return errSecAuthFailed; |
205 } | 205 } |
206 | 206 |
207 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; | 207 uintptr_t key = reinterpret_cast<uintptr_t>(itemRef) - 1; |
208 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) | 208 if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) |
209 return errSecInvalidItemRef; | 209 return errSecInvalidItemRef; |
210 | 210 |
211 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); | 211 MockKeychain* mutable_this = const_cast<MockKeychain*>(this); |
212 if (attrList) { | 212 if (attrList) { |
213 for (UInt32 change_attr = 0; change_attr < attrList->count; ++change_attr) { | 213 for (UInt32 change_attr = 0; change_attr < attrList->count; ++change_attr) { |
214 if (attrList->attr[change_attr].tag == kSecCreatorItemAttr) { | 214 if (attrList->attr[change_attr].tag == kSecCreatorItemAttr) { |
215 void* data = attrList->attr[change_attr].data; | 215 void* data = attrList->attr[change_attr].data; |
216 mutable_this->SetTestDataCreator(key, *(static_cast<OSType*>(data))); | 216 mutable_this->SetTestDataCreator(key, *(static_cast<OSType*>(data))); |
217 } else { | 217 } else { |
218 NOTIMPLEMENTED(); | 218 NOTIMPLEMENTED(); |
219 } | 219 } |
220 } | 220 } |
221 } | 221 } |
222 if (data) | 222 if (data) |
223 mutable_this->SetTestDataPasswordBytes(key, data, length); | 223 mutable_this->SetTestDataPasswordBytes(key, data, length); |
224 return noErr; | 224 return noErr; |
225 } | 225 } |
226 | 226 |
227 OSStatus MockKeychain::ItemFreeAttributesAndData( | 227 OSStatus MockKeychain::ItemFreeAttributesAndData( |
228 SecKeychainAttributeList* attrList, | 228 SecKeychainAttributeList* attrList, |
229 void* data) const { | 229 void* data) const { |
230 --attribute_data_copy_count_; | 230 --attribute_data_copy_count_; |
231 return noErr; | 231 return noErr; |
232 } | 232 } |
233 | 233 |
234 OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const { | 234 OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const { |
235 unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; | 235 uintptr_t key = reinterpret_cast<uintptr_t>(itemRef) - 1; |
236 | 236 |
237 for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) { | 237 for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) { |
238 if (keychain_attr_list_[key].attr[i].data) | 238 if (keychain_attr_list_[key].attr[i].data) |
239 free(keychain_attr_list_[key].attr[i].data); | 239 free(keychain_attr_list_[key].attr[i].data); |
240 } | 240 } |
241 free(keychain_attr_list_[key].attr); | 241 free(keychain_attr_list_[key].attr); |
242 if (keychain_data_[key].data) | 242 if (keychain_data_[key].data) |
243 free(keychain_data_[key].data); | 243 free(keychain_data_[key].data); |
244 | 244 |
245 keychain_attr_list_.erase(key); | 245 keychain_attr_list_.erase(key); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 add_generic_password_ = | 476 add_generic_password_ = |
477 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), | 477 std::string(const_cast<char*>(static_cast<const char*>(passwordData)), |
478 passwordLength); | 478 passwordLength); |
479 return noErr; | 479 return noErr; |
480 } | 480 } |
481 | 481 |
482 void MockKeychain::Free(CFTypeRef ref) const { | 482 void MockKeychain::Free(CFTypeRef ref) const { |
483 if (!ref) | 483 if (!ref) |
484 return; | 484 return; |
485 | 485 |
486 if (reinterpret_cast<int>(ref) == kDummySearchRef) { | 486 if (reinterpret_cast<uintptr_t>(ref) == kDummySearchRef) { |
487 --search_copy_count_; | 487 --search_copy_count_; |
488 } else { | 488 } else { |
489 --keychain_item_copy_count_; | 489 --keychain_item_copy_count_; |
490 } | 490 } |
491 } | 491 } |
492 | 492 |
493 int MockKeychain::UnfreedSearchCount() const { | 493 int MockKeychain::UnfreedSearchCount() const { |
494 return search_copy_count_; | 494 return search_copy_count_; |
495 } | 495 } |
496 | 496 |
(...skipping 28 matching lines...) Expand all Loading... |
525 SetTestDataPort(key, item_data.port); | 525 SetTestDataPort(key, item_data.port); |
526 SetTestDataString(key, kSecSecurityDomainItemAttr, | 526 SetTestDataString(key, kSecSecurityDomainItemAttr, |
527 item_data.security_domain); | 527 item_data.security_domain); |
528 SetTestDataString(key, kSecCreationDateItemAttr, item_data.creation_date); | 528 SetTestDataString(key, kSecCreationDateItemAttr, item_data.creation_date); |
529 SetTestDataString(key, kSecAccountItemAttr, item_data.username); | 529 SetTestDataString(key, kSecAccountItemAttr, item_data.username); |
530 SetTestDataPasswordString(key, item_data.password); | 530 SetTestDataPasswordString(key, item_data.password); |
531 SetTestDataNegativeItem(key, item_data.negative_item); | 531 SetTestDataNegativeItem(key, item_data.negative_item); |
532 } | 532 } |
533 | 533 |
534 } // namespace crypto | 534 } // namespace crypto |
OLD | NEW |