Skip to content

Commit

Permalink
Merge development into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix committed May 9, 2021
2 parents be234e0 + 37567d0 commit 1526787
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/ComposableStorageCrypto/KeychainStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct KeychainStorage<Item: Storable>: ThrowingStorage {
public func item(matching label: String) throws -> Item? {
try keychain.container(for: label)
.fetch()
.flatMap { try Item.decoding($0) }
.flatMap { try? Item.decoding($0) }
}

/// Return all stored `Item`s.
Expand Down Expand Up @@ -84,13 +84,17 @@ public struct KeychainStorage<Item: Storable>: ThrowingStorage {
public func discard(_ label: String) throws -> Item? {
try keychain.container(for: label)
.drop()
.flatMap { try Item.decoding($0) }
.flatMap { try? Item.decoding($0) }
}

/// Empty storage.
///
/// - throws: Some `Error`.
public func empty() throws {
try keychain.empty()
// If it's not empty just manually delete them all.
let keys = try keychain.keys()
guard !keys.isEmpty else { return }
keys.forEach { try? keychain.container(for: $0).drop() }
}
}

0 comments on commit 1526787

Please sign in to comment.