|
|
@@ -92,7 +92,7 @@ public class KeychainSwift {
|
|
|
]
|
|
|
|
|
|
query = addAccessGroupWhenPresent(query)
|
|
|
- query = addSynchronizableIfRequired(query)
|
|
|
+ query = addSynchronizableIfRequired(query, addingItems: true)
|
|
|
lastQueryParameters = query
|
|
|
|
|
|
lastResultCode = SecItemAdd(query as CFDictionaryRef, nil)
|
|
|
@@ -158,7 +158,7 @@ public class KeychainSwift {
|
|
|
]
|
|
|
|
|
|
query = addAccessGroupWhenPresent(query)
|
|
|
- query = addSynchronizableIfRequired(query)
|
|
|
+ query = addSynchronizableIfRequired(query, addingItems: false)
|
|
|
lastQueryParameters = query
|
|
|
|
|
|
var result: AnyObject?
|
|
|
@@ -204,7 +204,7 @@ public class KeychainSwift {
|
|
|
]
|
|
|
|
|
|
query = addAccessGroupWhenPresent(query)
|
|
|
- query = addSynchronizableIfRequired(query)
|
|
|
+ query = addSynchronizableIfRequired(query, addingItems: false)
|
|
|
lastQueryParameters = query
|
|
|
|
|
|
lastResultCode = SecItemDelete(query as CFDictionaryRef)
|
|
|
@@ -222,7 +222,7 @@ public class KeychainSwift {
|
|
|
public func clear() -> Bool {
|
|
|
var query: [String: NSObject] = [ kSecClass as String : kSecClassGenericPassword ]
|
|
|
query = addAccessGroupWhenPresent(query)
|
|
|
- query = addSynchronizableIfRequired(query)
|
|
|
+ query = addSynchronizableIfRequired(query, addingItems: false)
|
|
|
lastQueryParameters = query
|
|
|
|
|
|
lastResultCode = SecItemDelete(query as CFDictionaryRef)
|
|
|
@@ -243,11 +243,20 @@ public class KeychainSwift {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
- /// Adds kSecAttrSynchronizable: kSecAttrSynchronizableAny` item to the dictionary when the `synchronizable` property is true.
|
|
|
- func addSynchronizableIfRequired(items: [String: NSObject]) -> [String: NSObject] {
|
|
|
+ /**
|
|
|
+
|
|
|
+ Adds kSecAttrSynchronizable: kSecAttrSynchronizableAny` item to the dictionary when the `synchronizable` property is true.
|
|
|
+
|
|
|
+ - parameter items: The dictionary where the kSecAttrSynchronizable items will be added when requested.
|
|
|
+ - parameter addingItems: Use `true` when the dictionary will be used with `SecItemAdd` method (adding a keychain item). For getting and deleting items, use `false`.
|
|
|
+
|
|
|
+ - returns: the dictionary with kSecAttrSynchronizable item added if it was requested. Otherwise, it returns the original dictionary.
|
|
|
+
|
|
|
+ */
|
|
|
+ func addSynchronizableIfRequired(items: [String: NSObject], addingItems: Bool) -> [String: NSObject] {
|
|
|
if !synchronizable { return items }
|
|
|
var result: [String: NSObject] = items
|
|
|
- result[KeychainSwiftConstants.attrSynchronizable] = kSecAttrSynchronizableAny
|
|
|
+ result[KeychainSwiftConstants.attrSynchronizable] = addingItems == true ? true : kSecAttrSynchronizableAny
|
|
|
return result
|
|
|
}
|
|
|
}
|