| 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 11 matching lines...) Expand all Loading... |
| 22 // KeychainPasswordData values in separate mutable containers and | 22 // KeychainPasswordData values in separate mutable containers and |
| 23 // mapping them to integer keys. | 23 // mapping them to integer keys. |
| 24 // | 24 // |
| 25 // Note that "const" is pretty much meaningless for this class; the const-ness | 25 // Note that "const" is pretty much meaningless for this class; the const-ness |
| 26 // of AppleKeychain doesn't apply to the actual keychain data, so all of the | 26 // of AppleKeychain doesn't apply to the actual keychain data, so all of the |
| 27 // Mock data is mutable; don't assume that it won't change over the life of | 27 // Mock data is mutable; don't assume that it won't change over the life of |
| 28 // tests. | 28 // tests. |
| 29 class CRYPTO_EXPORT MockAppleKeychain : public AppleKeychain { | 29 class CRYPTO_EXPORT MockAppleKeychain : public AppleKeychain { |
| 30 public: | 30 public: |
| 31 MockAppleKeychain(); | 31 MockAppleKeychain(); |
| 32 virtual ~MockAppleKeychain(); | 32 ~MockAppleKeychain() override; |
| 33 | 33 |
| 34 // AppleKeychain implementation. | 34 // AppleKeychain implementation. |
| 35 virtual OSStatus FindGenericPassword( | 35 OSStatus FindGenericPassword(CFTypeRef keychainOrArray, |
| 36 CFTypeRef keychainOrArray, | 36 UInt32 serviceNameLength, |
| 37 UInt32 serviceNameLength, | 37 const char* serviceName, |
| 38 const char* serviceName, | 38 UInt32 accountNameLength, |
| 39 UInt32 accountNameLength, | 39 const char* accountName, |
| 40 const char* accountName, | 40 UInt32* passwordLength, |
| 41 UInt32* passwordLength, | 41 void** passwordData, |
| 42 void** passwordData, | 42 SecKeychainItemRef* itemRef) const override; |
| 43 SecKeychainItemRef* itemRef) const override; | 43 OSStatus ItemFreeContent(SecKeychainAttributeList* attrList, |
| 44 virtual OSStatus ItemFreeContent(SecKeychainAttributeList* attrList, | 44 void* data) const override; |
| 45 void* data) const override; | 45 OSStatus AddGenericPassword(SecKeychainRef keychain, |
| 46 virtual OSStatus AddGenericPassword( | 46 UInt32 serviceNameLength, |
| 47 SecKeychainRef keychain, | 47 const char* serviceName, |
| 48 UInt32 serviceNameLength, | 48 UInt32 accountNameLength, |
| 49 const char* serviceName, | 49 const char* accountName, |
| 50 UInt32 accountNameLength, | 50 UInt32 passwordLength, |
| 51 const char* accountName, | 51 const void* passwordData, |
| 52 UInt32 passwordLength, | 52 SecKeychainItemRef* itemRef) const override; |
| 53 const void* passwordData, | |
| 54 SecKeychainItemRef* itemRef) const override; | |
| 55 | 53 |
| 56 #if !defined(OS_IOS) | 54 #if !defined(OS_IOS) |
| 57 virtual OSStatus ItemCopyAttributesAndData( | 55 OSStatus ItemCopyAttributesAndData(SecKeychainItemRef itemRef, |
| 58 SecKeychainItemRef itemRef, | 56 SecKeychainAttributeInfo* info, |
| 59 SecKeychainAttributeInfo* info, | 57 SecItemClass* itemClass, |
| 60 SecItemClass* itemClass, | 58 SecKeychainAttributeList** attrList, |
| 61 SecKeychainAttributeList** attrList, | 59 UInt32* length, |
| 62 UInt32* length, | 60 void** outData) const override; |
| 63 void** outData) const override; | |
| 64 // Pass "fail_me" as the data to get errSecAuthFailed. | 61 // Pass "fail_me" as the data to get errSecAuthFailed. |
| 65 virtual OSStatus ItemModifyAttributesAndData( | 62 OSStatus ItemModifyAttributesAndData(SecKeychainItemRef itemRef, |
| 66 SecKeychainItemRef itemRef, | 63 const SecKeychainAttributeList* attrList, |
| 67 const SecKeychainAttributeList* attrList, | 64 UInt32 length, |
| 68 UInt32 length, | 65 const void* data) const override; |
| 69 const void* data) const override; | 66 OSStatus ItemFreeAttributesAndData(SecKeychainAttributeList* attrList, |
| 70 virtual OSStatus ItemFreeAttributesAndData(SecKeychainAttributeList* attrList, | 67 void* data) const override; |
| 71 void* data) const override; | 68 OSStatus ItemDelete(SecKeychainItemRef itemRef) const override; |
| 72 virtual OSStatus ItemDelete(SecKeychainItemRef itemRef) const override; | 69 OSStatus SearchCreateFromAttributes( |
| 73 virtual OSStatus SearchCreateFromAttributes( | |
| 74 CFTypeRef keychainOrArray, | 70 CFTypeRef keychainOrArray, |
| 75 SecItemClass itemClass, | 71 SecItemClass itemClass, |
| 76 const SecKeychainAttributeList* attrList, | 72 const SecKeychainAttributeList* attrList, |
| 77 SecKeychainSearchRef* searchRef) const override; | 73 SecKeychainSearchRef* searchRef) const override; |
| 78 virtual OSStatus SearchCopyNext(SecKeychainSearchRef searchRef, | 74 OSStatus SearchCopyNext(SecKeychainSearchRef searchRef, |
| 79 SecKeychainItemRef* itemRef) const override; | 75 SecKeychainItemRef* itemRef) const override; |
| 80 // Pass "some.domain.com" as the serverName to get errSecDuplicateItem. | 76 // Pass "some.domain.com" as the serverName to get errSecDuplicateItem. |
| 81 virtual OSStatus AddInternetPassword( | 77 OSStatus AddInternetPassword(SecKeychainRef keychain, |
| 82 SecKeychainRef keychain, | 78 UInt32 serverNameLength, |
| 83 UInt32 serverNameLength, | 79 const char* serverName, |
| 84 const char* serverName, | 80 UInt32 securityDomainLength, |
| 85 UInt32 securityDomainLength, | 81 const char* securityDomain, |
| 86 const char* securityDomain, | 82 UInt32 accountNameLength, |
| 87 UInt32 accountNameLength, | 83 const char* accountName, |
| 88 const char* accountName, | 84 UInt32 pathLength, |
| 89 UInt32 pathLength, const char* path, | 85 const char* path, |
| 90 UInt16 port, SecProtocolType protocol, | 86 UInt16 port, |
| 91 SecAuthenticationType authenticationType, | 87 SecProtocolType protocol, |
| 92 UInt32 passwordLength, | 88 SecAuthenticationType authenticationType, |
| 93 const void* passwordData, | 89 UInt32 passwordLength, |
| 94 SecKeychainItemRef* itemRef) const override; | 90 const void* passwordData, |
| 95 virtual void Free(CFTypeRef ref) const override; | 91 SecKeychainItemRef* itemRef) const override; |
| 92 void Free(CFTypeRef ref) const override; |
| 96 | 93 |
| 97 // Return the counts of objects returned by Create/Copy functions but never | 94 // Return the counts of objects returned by Create/Copy functions but never |
| 98 // Free'd as they should have been. | 95 // Free'd as they should have been. |
| 99 int UnfreedSearchCount() const; | 96 int UnfreedSearchCount() const; |
| 100 int UnfreedKeychainItemCount() const; | 97 int UnfreedKeychainItemCount() const; |
| 101 int UnfreedAttributeDataCount() const; | 98 int UnfreedAttributeDataCount() const; |
| 102 | 99 |
| 103 // Returns true if all items added with AddInternetPassword have a creator | 100 // Returns true if all items added with AddInternetPassword have a creator |
| 104 // code set. | 101 // code set. |
| 105 bool CreatorCodesSetForAddedItems() const; | 102 bool CreatorCodesSetForAddedItems() const; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // and |ItemFreeContent|. | 238 // and |ItemFreeContent|. |
| 242 mutable int password_data_count_; | 239 mutable int password_data_count_; |
| 243 | 240 |
| 244 // Records the password being set when |AddGenericPassword()| gets called. | 241 // Records the password being set when |AddGenericPassword()| gets called. |
| 245 mutable std::string add_generic_password_; | 242 mutable std::string add_generic_password_; |
| 246 }; | 243 }; |
| 247 | 244 |
| 248 } // namespace crypto | 245 } // namespace crypto |
| 249 | 246 |
| 250 #endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_ | 247 #endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_ |
| OLD | NEW |