|
|
@@ -153,10 +153,11 @@ open class KeychainSwift {
|
|
|
Retrieves the data from the keychain that corresponds to the given key.
|
|
|
|
|
|
- parameter key: The key that is used to read the keychain item.
|
|
|
+ - parameter isReference: Flag is used to determine the returning value (reference to the value or value)
|
|
|
- returns: The text value from the keychain. Returns nil if unable to read the item.
|
|
|
|
|
|
*/
|
|
|
- open func getData(_ key: String) -> Data? {
|
|
|
+ open func getData(_ key: String, isReference: Bool = false) -> Data? {
|
|
|
// The lock prevents the code to be run simlultaneously
|
|
|
// from multiple threads which may result in crashing
|
|
|
readLock.lock()
|
|
|
@@ -167,10 +168,15 @@ open class KeychainSwift {
|
|
|
var query: [String: Any] = [
|
|
|
KeychainSwiftConstants.klass : kSecClassGenericPassword,
|
|
|
KeychainSwiftConstants.attrAccount : prefixedKey,
|
|
|
- KeychainSwiftConstants.returnData : kCFBooleanTrue,
|
|
|
KeychainSwiftConstants.matchLimit : kSecMatchLimitOne
|
|
|
]
|
|
|
|
|
|
+ if isReference {
|
|
|
+ query[KeychainSwiftConstants.returnRefernce] = kCFBooleanTrue
|
|
|
+ } else {
|
|
|
+ query[KeychainSwiftConstants.returnData] = kCFBooleanTrue
|
|
|
+ }
|
|
|
+
|
|
|
query = addAccessGroupWhenPresent(query)
|
|
|
query = addSynchronizableIfRequired(query, addingItems: false)
|
|
|
lastQueryParameters = query
|
|
|
@@ -181,7 +187,9 @@ open class KeychainSwift {
|
|
|
SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
|
|
|
}
|
|
|
|
|
|
- if lastResultCode == noErr { return result as? Data }
|
|
|
+ if lastResultCode == noErr {
|
|
|
+ return result as? Data
|
|
|
+ }
|
|
|
|
|
|
return nil
|
|
|
}
|