@@ -35,7 +35,7 @@ public struct Keychain: KeychainType {
3535 let service = keychainService
3636 let accessGroup = keychainAccessGroup
3737 let scope : String
38-
38+
3939 public static var apiKey : Keychain {
4040 Keychain ( scope: " apiKey " )
4141 }
@@ -61,7 +61,6 @@ public struct Keychain: KeychainType {
6161 }
6262
6363 func set( _ value: String , key: String ) throws {
64- let key = scopeKey ( key)
6564 let query = query ( key) . merging ( [
6665 kSecValueData as String : value. data ( using: . utf8) ?? Data ( ) ,
6766 ] , uniquingKeysWith: { _, b in b } )
@@ -80,18 +79,18 @@ public struct Keychain: KeychainType {
8079 if scope. isEmpty {
8180 return key
8281 }
83- return " \( scope) . \( key) "
82+ return " \( scope) :: \( key) "
8483 }
85-
84+
8685 func escapeScope( _ key: String ) -> String ? {
8786 if scope. isEmpty {
8887 return key
8988 }
90- if !key. hasPrefix ( " \( scope) . " ) { return nil }
91- return key. replacingOccurrences ( of: " \( scope) . " , with: " " )
89+ if !key. hasPrefix ( " \( scope) :: " ) { return nil }
90+ return key. replacingOccurrences ( of: " \( scope) :: " , with: " " )
9291 }
9392
94- public func getAll( ) throws -> [ String : String ] {
93+ public func getAll( ) throws -> [ String : String ] {
9594 let query = [
9695 kSecClass as String : kSecClassGenericPassword as String ,
9796 kSecAttrService as String : service,
@@ -109,18 +108,17 @@ public struct Keychain: KeychainType {
109108
110109 var dict = [ String: String] ( )
111110 for item in items {
112- guard let keyData = item [ kSecAttrAccount as String ] as? Data ,
113- let key = String ( data: keyData, encoding: . utf8) ,
114- let valueData = item [ kSecValueData as String ] as? Data ,
115- let value = String ( data: valueData, encoding: . utf8) ,
111+ guard let key = item [ kSecAttrAccount as String ] as? String ,
116112 let escapedKey = escapeScope ( key)
117- else {
118- continue
119- }
113+ else { continue }
114+ guard let valueData = item [ kSecValueData as String ] as? Data ,
115+ let value = String ( data: valueData, encoding: . utf8)
116+ else { continue }
120117 dict [ escapedKey] = value
121118 }
119+ return dict
122120 }
123-
121+
124122 return [ : ]
125123 }
126124
0 commit comments