| 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 #ifndef CRYPTO_MOCK_KEYCHAIN_MAC_H_ | 5 #ifndef CRYPTO_MOCK_KEYCHAIN_MAC_H_ |
| 6 #define CRYPTO_MOCK_KEYCHAIN_MAC_H_ | 6 #define CRYPTO_MOCK_KEYCHAIN_MAC_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 const char* path; | 111 const char* path; |
| 112 const UInt32 port; | 112 const UInt32 port; |
| 113 const char* security_domain; | 113 const char* security_domain; |
| 114 const char* creation_date; | 114 const char* creation_date; |
| 115 const char* username; | 115 const char* username; |
| 116 const char* password; | 116 const char* password; |
| 117 const bool negative_item; | 117 const bool negative_item; |
| 118 }; | 118 }; |
| 119 // Adds a keychain item with the given info to the test set. | 119 // Adds a keychain item with the given info to the test set. |
| 120 void AddTestItem(const KeychainTestData& item_data); | 120 void AddTestItem(const KeychainTestData& item_data); |
| 121 |
| 122 void set_locked(bool locked) { locked_ = locked; } |
| 121 #endif // !defined(OS_IOS) | 123 #endif // !defined(OS_IOS) |
| 122 | 124 |
| 123 // |FindGenericPassword()| can return different results depending on user | 125 // |FindGenericPassword()| can return different results depending on user |
| 124 // interaction with the system Keychain. For mocking purposes we allow the | 126 // interaction with the system Keychain. For mocking purposes we allow the |
| 125 // user of this class to specify the result code of the | 127 // user of this class to specify the result code of the |
| 126 // |FindGenericPassword()| call so we can simulate the result of different | 128 // |FindGenericPassword()| call so we can simulate the result of different |
| 127 // user interactions. | 129 // user interactions. |
| 128 void set_find_generic_result(OSStatus result) { | 130 void set_find_generic_result(OSStatus result) { |
| 129 find_generic_result_ = result; | 131 find_generic_result_ = result; |
| 130 } | 132 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // the data will not be null-terminated. | 196 // the data will not be null-terminated. |
| 195 void SetTestDataPasswordString(MockKeychainItemType item, const char* value); | 197 void SetTestDataPasswordString(MockKeychainItemType item, const char* value); |
| 196 | 198 |
| 197 // Returns the address of the attribute in attribute_list with tag |tag|. | 199 // Returns the address of the attribute in attribute_list with tag |tag|. |
| 198 static SecKeychainAttribute* AttributeWithTag( | 200 static SecKeychainAttribute* AttributeWithTag( |
| 199 const SecKeychainAttributeList& attribute_list, | 201 const SecKeychainAttributeList& attribute_list, |
| 200 UInt32 tag); | 202 UInt32 tag); |
| 201 | 203 |
| 202 static const SecKeychainSearchRef kDummySearchRef; | 204 static const SecKeychainSearchRef kDummySearchRef; |
| 203 | 205 |
| 206 // Simulates the state when the user refuses to unclock the Keychain. |
| 207 // If true, reading and modifying a password value result in errSecAuthFailed. |
| 208 bool locked_; |
| 209 |
| 204 typedef struct KeychainPasswordData { | 210 typedef struct KeychainPasswordData { |
| 205 KeychainPasswordData() : data(NULL), length(0) {} | 211 KeychainPasswordData() : data(NULL), length(0) {} |
| 206 void* data; | 212 void* data; |
| 207 UInt32 length; | 213 UInt32 length; |
| 208 } KeychainPasswordData; | 214 } KeychainPasswordData; |
| 209 | 215 |
| 210 // Mutable because the MockAppleKeychain API requires its internal keychain | 216 // Mutable because the MockAppleKeychain API requires its internal keychain |
| 211 // storage to be modifiable by users of this class. | 217 // storage to be modifiable by users of this class. |
| 212 mutable MockKeychainAttributesMap keychain_attr_list_; | 218 mutable MockKeychainAttributesMap keychain_attr_list_; |
| 213 mutable std::map<MockKeychainItemType, | 219 mutable std::map<MockKeychainItemType, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 241 // and |ItemFreeContent|. | 247 // and |ItemFreeContent|. |
| 242 mutable int password_data_count_; | 248 mutable int password_data_count_; |
| 243 | 249 |
| 244 // Records the password being set when |AddGenericPassword()| gets called. | 250 // Records the password being set when |AddGenericPassword()| gets called. |
| 245 mutable std::string add_generic_password_; | 251 mutable std::string add_generic_password_; |
| 246 }; | 252 }; |
| 247 | 253 |
| 248 } // namespace crypto | 254 } // namespace crypto |
| 249 | 255 |
| 250 #endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_ | 256 #endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_ |
| OLD | NEW |