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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 UInt32 securityDomainLength, | 143 UInt32 securityDomainLength, |
144 const char* securityDomain, | 144 const char* securityDomain, |
145 UInt32 accountNameLength, | 145 UInt32 accountNameLength, |
146 const char* accountName, | 146 const char* accountName, |
147 UInt32 pathLength, | 147 UInt32 pathLength, |
148 const char* path, | 148 const char* path, |
149 UInt16 port, | 149 UInt16 port, |
150 SecProtocolType protocol, | 150 SecProtocolType protocol, |
151 SecAuthenticationType authenticationType) const; | 151 SecAuthenticationType authenticationType) const; |
152 // Initializes storage for keychain data at |key|. | 152 // Initializes storage for keychain data at |key|. |
153 void InitializeKeychainData(unsigned int key) const; | 153 void InitializeKeychainData(uintptr_t key) const; |
154 // Sets the data and length of |tag| in the item-th test item. | 154 // Sets the data and length of |tag| in the item-th test item. |
155 void SetTestDataBytes(int item, UInt32 tag, const void* data, size_t length); | 155 void SetTestDataBytes( |
| 156 uintptr_t item, |
| 157 UInt32 tag, |
| 158 const void* data, |
| 159 size_t length); |
156 // Sets the data and length of |tag| in the item-th test item based on | 160 // Sets the data and length of |tag| in the item-th test item based on |
157 // |value|. The null-terminator will not be included; the Keychain Services | 161 // |value|. The null-terminator will not be included; the Keychain Services |
158 // docs don't indicate whether it is or not, so clients should not assume | 162 // docs don't indicate whether it is or not, so clients should not assume |
159 // that it will be. | 163 // that it will be. |
160 void SetTestDataString(int item, UInt32 tag, const char* value); | 164 void SetTestDataString(uintptr_t item, UInt32 tag, const char* value); |
161 // Sets the data of the corresponding attribute of the item-th test item to | 165 // Sets the data of the corresponding attribute of the item-th test item to |
162 // |value|. Assumes that the space has alread been allocated, and the length | 166 // |value|. Assumes that the space has alread been allocated, and the length |
163 // set. | 167 // set. |
164 void SetTestDataPort(int item, UInt32 value); | 168 void SetTestDataPort(uintptr_t item, UInt32 value); |
165 void SetTestDataProtocol(int item, SecProtocolType value); | 169 void SetTestDataProtocol(uintptr_t item, SecProtocolType value); |
166 void SetTestDataAuthType(int item, SecAuthenticationType value); | 170 void SetTestDataAuthType(uintptr_t item, SecAuthenticationType value); |
167 void SetTestDataNegativeItem(int item, Boolean value); | 171 void SetTestDataNegativeItem(uintptr_t item, Boolean value); |
168 void SetTestDataCreator(int item, OSType value); | 172 void SetTestDataCreator(uintptr_t item, OSType value); |
169 // Sets the password data and length for the item-th test item. | 173 // Sets the password data and length for the item-th test item. |
170 void SetTestDataPasswordBytes(int item, const void* data, size_t length); | 174 void SetTestDataPasswordBytes( |
| 175 uintptr_t item, |
| 176 const void* data, |
| 177 size_t length); |
171 // Sets the password for the item-th test item. As with SetTestDataString, | 178 // Sets the password for the item-th test item. As with SetTestDataString, |
172 // the data will not be null-terminated. | 179 // the data will not be null-terminated. |
173 void SetTestDataPasswordString(int item, const char* value); | 180 void SetTestDataPasswordString(uintptr_t item, const char* value); |
174 | 181 |
175 // Returns the address of the attribute in attribute_list with tag |tag|. | 182 // Returns the address of the attribute in attribute_list with tag |tag|. |
176 static SecKeychainAttribute* AttributeWithTag( | 183 static SecKeychainAttribute* AttributeWithTag( |
177 const SecKeychainAttributeList& attribute_list, | 184 const SecKeychainAttributeList& attribute_list, |
178 UInt32 tag); | 185 UInt32 tag); |
179 | 186 |
180 static const int kDummySearchRef = 1000; | 187 static const uintptr_t kDummySearchRef = 1000; |
181 | 188 |
182 typedef struct KeychainPasswordData { | 189 typedef struct KeychainPasswordData { |
183 KeychainPasswordData() : data(NULL), length(0) {} | 190 KeychainPasswordData() : data(NULL), length(0) {} |
184 void* data; | 191 void* data; |
185 UInt32 length; | 192 UInt32 length; |
186 } KeychainPasswordData; | 193 } KeychainPasswordData; |
187 | 194 |
188 // Mutable because the MockKeychain API requires its internal keychain storage | 195 // Mutable because the MockKeychain API requires its internal keychain storage |
189 // to be modifiable by users of this class. | 196 // to be modifiable by users of this class. |
190 mutable std::map<unsigned int, SecKeychainAttributeList> keychain_attr_list_; | 197 mutable std::map<uintptr_t, SecKeychainAttributeList> keychain_attr_list_; |
191 mutable std::map<unsigned int, KeychainPasswordData> keychain_data_; | 198 mutable std::map<uintptr_t, KeychainPasswordData> keychain_data_; |
192 mutable unsigned int next_item_key_; | 199 mutable uintptr_t next_item_key_; |
193 | 200 |
194 // Tracks the items that should be returned in subsequent calls to | 201 // Tracks the items that should be returned in subsequent calls to |
195 // SearchCopyNext, based on the last call to SearchCreateFromAttributes. | 202 // SearchCopyNext, based on the last call to SearchCreateFromAttributes. |
196 // We can't handle multiple active searches, since we don't track the search | 203 // We can't handle multiple active searches, since we don't track the search |
197 // ref we return, but we don't need to for our mocking. | 204 // ref we return, but we don't need to for our mocking. |
198 mutable std::vector<unsigned int> remaining_search_results_; | 205 mutable std::vector<uintptr_t> remaining_search_results_; |
199 | 206 |
200 // Track copies and releases to make sure they balance. Really these should | 207 // Track copies and releases to make sure they balance. Really these should |
201 // be maps to track per item, but this should be good enough to catch | 208 // be maps to track per item, but this should be good enough to catch |
202 // real mistakes. | 209 // real mistakes. |
203 mutable int search_copy_count_; | 210 mutable int search_copy_count_; |
204 mutable int keychain_item_copy_count_; | 211 mutable int keychain_item_copy_count_; |
205 mutable int attribute_data_copy_count_; | 212 mutable int attribute_data_copy_count_; |
206 | 213 |
207 // Tracks which items (by key) were added with AddInternetPassword. | 214 // Tracks which items (by key) were added with AddInternetPassword. |
208 mutable std::set<unsigned int> added_via_api_; | 215 mutable std::set<unsigned int> added_via_api_; |
209 | 216 |
210 // Result code for the |FindGenericPassword()| method. | 217 // Result code for the |FindGenericPassword()| method. |
211 OSStatus find_generic_result_; | 218 OSStatus find_generic_result_; |
212 | 219 |
213 // Records whether |AddGenericPassword()| gets called. | 220 // Records whether |AddGenericPassword()| gets called. |
214 mutable bool called_add_generic_; | 221 mutable bool called_add_generic_; |
215 | 222 |
216 // Tracks the allocations and frees of password data in |FindGenericPassword| | 223 // Tracks the allocations and frees of password data in |FindGenericPassword| |
217 // and |ItemFreeContent|. | 224 // and |ItemFreeContent|. |
218 mutable unsigned int password_data_count_; | 225 mutable unsigned int password_data_count_; |
219 | 226 |
220 // Records the password being set when |AddGenericPassword()| gets called. | 227 // Records the password being set when |AddGenericPassword()| gets called. |
221 mutable std::string add_generic_password_; | 228 mutable std::string add_generic_password_; |
222 }; | 229 }; |
223 | 230 |
224 } // namespace crypto | 231 } // namespace crypto |
225 | 232 |
226 #endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_ | 233 #endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_ |
OLD | NEW |