diff --git a/Keychain/Sources/Keychain/Keychain.swift b/Keychain/Sources/Keychain/Keychain.swift index 65b1eca..dbd1598 100644 --- a/Keychain/Sources/Keychain/Keychain.swift +++ b/Keychain/Sources/Keychain/Keychain.swift @@ -19,7 +19,13 @@ extension LiveKeychain: Keychain { query[kSecValueData as String] = data - let status = SecItemAdd(query as CFDictionary, nil) + var status = SecItemAdd(query as CFDictionary, nil) + + if status == errSecDuplicateItem { + status = SecItemUpdate( + genericPasswordQueryDictionary(account: account, service: service) as CFDictionary, + [kSecValueData as String: data] as CFDictionary) + } if status != errSecSuccess { throw NSError(status: status) @@ -54,6 +60,8 @@ extension LiveKeychain: Keychain { } public static func generateKeyAndReturnPublicKey(applicationTag: String, attributes: [String: Any]) throws -> Data { + try? deleteKey(applicationTag: applicationTag) + var attributes = attributes var error: Unmanaged? diff --git a/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift b/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift index d925dc8..a5e8dd4 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/AllIdentitiesService.swift @@ -124,6 +124,7 @@ public extension AllIdentitiesService { } } .map(Publishers.MergeMany.init) + .flatMap { $0 } .ignoreOutput() .eraseToAnyPublisher() }