- // Find the keychain object for the given ref
- Keychain keychain;
- try
- {
- keychain = KeychainRef::required(*ix);
- }
- catch (const MacOSError& err)
- {
- if (err.osStatus() == errSecInvalidKeychain)
- continue;
- throw;
- }
-
- // Add it to the list
- dldbList.push_back(keychain->dLDbIdentifier());
+ CFTypeID typeID = CFGetTypeID(keychainOrArray);
+ if (typeID == CFArrayGetTypeID())
+ convertToKeychainList(CFArrayRef(keychainOrArray), keychainList);
+ else if (typeID == gTypes().keychain.typeId)
+ keychainList.push_back(gTypes().keychain.required(SecKeychainRef(keychainOrArray)));
+ else
+ MacOSError::throwMe(paramErr);
+ }
+}
+
+// static methods.
+void
+StorageManager::convertToKeychainList(CFArrayRef keychainArray, KeychainList &keychainList)
+{
+ assert(keychainArray);
+ CFIndex count = CFArrayGetCount(keychainArray);
+ KeychainList keychains(count);
+ CFClass<KeychainImpl, SecKeychainRef, errSecInvalidKeychain> &kcClass = gTypes().keychain;
+ for (CFIndex ix = 0; ix < count; ++ix)
+ {
+ keychains[ix] = kcClass.required(SecKeychainRef(CFArrayGetValueAtIndex(keychainArray, ix)));
+ }
+
+ keychainList.swap(keychains);
+}
+
+CFArrayRef
+StorageManager::convertFromKeychainList(const KeychainList &keychainList)
+{
+ CFRef<CFMutableArrayRef> keychainArray(CFArrayCreateMutable(NULL, keychainList.size(), &kCFTypeArrayCallBacks));
+
+ CFClass<KeychainImpl, SecKeychainRef, errSecInvalidKeychain> &kcClass = gTypes().keychain;
+ for (KeychainList::const_iterator ix = keychainList.begin(); ix != keychainList.end(); ++ix)
+ {
+ SecKeychainRef keychainRef = kcClass.handle(**ix);
+ CFArrayAppendValue(keychainArray, keychainRef);
+ CFRelease(keychainRef);