-
-static CFMutableDictionaryRef makeBaseItemDictionary(CFStringRef itemclass) {
- CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
- CFDictionaryAddValue(query, kSecReturnRef, kCFBooleanTrue);
- CFDictionarySetValue(query, kSecClass, itemclass);
-
- if(CFEqual(itemclass, kSecClassInternetPassword)) {
- CFDictionarySetValue(query, kSecAttrServer, CFSTR("test_service"));
- CFDictionarySetValue(query, kSecAttrAuthenticationType, CFSTR("dflt")); // Default, I guess?
- } else {
- // Generic passwords have services
- CFDictionarySetValue(query, kSecAttrService, CFSTR("test_service"));
- }
- return query;
-}
-
-static CFMutableDictionaryRef makeQueryItemDictionary(SecKeychainRef kc, CFStringRef itemclass) {
- CFMutableDictionaryRef query = makeBaseItemDictionary(itemclass);
-
- CFMutableArrayRef searchList = (CFMutableArrayRef) CFArrayCreateMutable(kCFAllocatorDefault, 1, &kCFTypeArrayCallBacks);
- CFArrayAppendValue((CFMutableArrayRef)searchList, kc);
- CFDictionarySetValue(query, kSecMatchSearchList, searchList);
-
- CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitAll);
-
- return query;
-}
-
-static CFMutableDictionaryRef makeQueryCustomItemDictionary(SecKeychainRef kc, CFStringRef itemclass, CFStringRef label) {
- CFMutableDictionaryRef query = makeQueryItemDictionary(kc, itemclass);
- CFDictionarySetValue(query, kSecAttrLabel, label);
- return query;
-}
-
-static CFMutableDictionaryRef makeAddCustomItemDictionary(SecKeychainRef kc, CFStringRef itemclass, CFStringRef label, CFStringRef account) {
- CFMutableDictionaryRef query = makeBaseItemDictionary(itemclass);
-
- CFDictionaryAddValue(query, kSecUseKeychain, kc);
- CFDictionarySetValue(query, kSecAttrAccount, account);
- CFDictionarySetValue(query, kSecAttrComment, CFSTR("a comment"));
- CFDictionarySetValue(query, kSecAttrLabel, label);
- CFDictionarySetValue(query, kSecValueData, CFDataCreate(NULL, (void*)"data", 4));
- return query;
-}
-
-static CFMutableDictionaryRef makeAddItemDictionary(SecKeychainRef kc, CFStringRef itemclass, CFStringRef label) {
- return makeAddCustomItemDictionary(kc, itemclass, label, CFSTR("test_account"));
-}
-
-static SecKeychainItemRef makeCustomItem(const char* name, SecKeychainRef kc, CFDictionaryRef addDictionary) {
- CFTypeRef result = NULL;
- ok_status(SecItemAdd(addDictionary, &result), "%s: SecItemAdd", name);
- ok(result != NULL, "%s: SecItemAdd returned a result", name);
-
- SecKeychainItemRef item = (SecKeychainItemRef) result;
- ok(item != NULL, "%s: Couldn't convert into SecKeychainItemRef", name);
-
- return item;
-}
-#define makeCustomItemTests 3
-
-static SecKeychainItemRef makeItem(const char* name, SecKeychainRef kc, CFStringRef itemclass, CFStringRef label) {
- CFMutableDictionaryRef query = makeAddItemDictionary(kc, itemclass, label);
-
- SecKeychainItemRef item = makeCustomItem(name, kc, query);
-
- CFReleaseNull(query);
- return item;
-}
-#define makeItemTests makeCustomItemTests
-
-static void makeCustomDuplicateItem(const char* name, SecKeychainRef kc, CFStringRef itemclass, CFStringRef label) {
- CFMutableDictionaryRef query = makeAddItemDictionary(kc, itemclass, label);
-
- CFTypeRef result = NULL;
- is(SecItemAdd(query, &result), errSecDuplicateItem, "%s: SecItemAdd (duplicate)", name);
-
- CFReleaseNull(query);
-}
-#define makeCustomDuplicateItemTests 1
-
-static void makeDuplicateItem(const char* name, SecKeychainRef kc, CFStringRef itemclass) {
- return makeCustomDuplicateItem(name, kc, itemclass, CFSTR("test_label"));
-}
-#define makeDuplicateItemTests makeCustomDuplicateItemTests
-