-
-static void readPasswordContentsWithResult(SecKeychainItemRef item, OSStatus expectedResult, CFStringRef expectedContents) {
- if(!item) {
- fail("no item passed to readPasswordContentsWithResult");
- fail("Match test numbers");
- fail("Match test numbers");
- return;
- }
-
- CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
-
- CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitOne);
- CFDictionarySetValue(query, kSecReturnData, kCFBooleanTrue);
-
- CFMutableArrayRef itemList = (CFMutableArrayRef) CFArrayCreateMutable(kCFAllocatorDefault, 1, &kCFTypeArrayCallBacks);
- CFArrayAppendValue((CFMutableArrayRef)itemList, item);
- CFDictionarySetValue(query, kSecUseItemList, itemList);
-
- CFTypeRef results = NULL;
- if(expectedContents) {
- is(SecItemCopyMatching(query, (CFTypeRef*) &results), expectedResult, "%s: readPasswordContents: SecItemCopyMatching", testName);
- CFReleaseNull(query);
-
- if(results) {
- ok(CFGetTypeID(results) == CFDataGetTypeID(), "%s: result is not a data", testName);
-
- CFDataRef data = (CFDataRef) results;
- CFStringRef str = CFStringCreateWithBytes(NULL, CFDataGetBytePtr(data), CFDataGetLength(data), kCFStringEncodingUTF8, false);
- eq_cf(str, expectedContents, "%s: contents do not match", testName);
- CFReleaseNull(str);
- CFReleaseNull(results);
- } else {
- fail("Didn't get any results");
- fail("Match test numbers");
- }
- } else {
- is(SecItemCopyMatching(query, (CFTypeRef*) &results), expectedResult, "%s: readPasswordContents: expecting error %d", testName, (int) expectedResult);
- pass("Match test numbers");
- pass("Match test numbers");
- }
-}