Skip to content

Commit

Permalink
Add CredentialPack.clearPacks (#38)
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Nascimento <[email protected]>
  • Loading branch information
theosirian authored Nov 7, 2024
1 parent c3b2daa commit 45f97ca
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/MobileSdk/CredentialPack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ struct CredentialPackContents {
return CredentialPack(id: self.id, credentials: credentials)
}

/// Clears all CredentialPacks.
public static func clear(storageManager: StorageManagerInterface) throws {
do {
try storageManager.list()
.filter { file in
file.hasPrefix(Self.storagePrefix)
}
.forEach { file in
try storageManager.remove(key: file)
}
} catch {
throw CredentialPackError.clearing(reason: error)
}
}

/// Lists all CredentialPacks.
///
/// These can then be individually loaded. For eager loading of all packs, see `CredentialPack.loadAll`.
Expand Down Expand Up @@ -312,6 +327,8 @@ enum CredentialPackError: Error {
case missing(file: String)
/// Failed to list CredentialPackContents from storage.
case listing(reason: Error)
/// Failed to clear CredentialPacks from storage.
case clearing(reason: Error)
/// Failed to remove CredentialPackContents from storage.
case removing(reason: Error)
/// Failed to save CredentialPackContents to storage.
Expand Down

0 comments on commit 45f97ca

Please sign in to comment.