|
|
@@ -232,6 +232,32 @@ open class KeychainSwift {
|
|
|
return deleteNoLock(key)
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ Return all keys from keychain
|
|
|
+
|
|
|
+ - returns: An string array with all keys on keychain
|
|
|
+ */
|
|
|
+ open func allKeys() -> [String] {
|
|
|
+ var query: [String: Any] = [
|
|
|
+ KeychainSwiftConstants.klass : kSecClassGenericPassword,
|
|
|
+ KeychainSwiftConstants.returnData : true,
|
|
|
+ KeychainSwiftConstants.returnAttributes: true,
|
|
|
+ KeychainSwiftConstants.returnReference: true,
|
|
|
+ KeychainSwiftConstants.matchLimit: KeychainSwiftConstants.secMatchLimitAll
|
|
|
+ ]
|
|
|
+ query = addAccessGroupWhenPresent(query)
|
|
|
+ query = addSynchronizableIfRequired(query, addingItems: false)
|
|
|
+
|
|
|
+ var result: AnyObject?
|
|
|
+ let lastResultCode = withUnsafeMutablePointer(to: &result) {
|
|
|
+ SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
|
|
|
+ }
|
|
|
+ if lastResultCode == noErr {
|
|
|
+ return (result as? [[String: Any]])?.compactMap { $0[KeychainSwiftConstants.attrAccount] as? String } ?? []
|
|
|
+ }
|
|
|
+ return []
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
|
|
|
Same as `delete` but is only accessed internally, since it is not thread safe.
|