secretive/Sources/Packages/Sources/SecretKit/SecretStoreList.swift
Max Goedjen 3d3d123484
CryptoKit migration (#628)
* WIP.

* WIP

* WIP Edit

* Key selection.

* WIP

* WIP

* Proxy through

* WIP

* Remove verify.

* Migration.

* Comment

* Add param

* Semi-offering key

* Ignore updates if test build.

* Fix rsa public key gen

* Messily fix RSA

* Remove 1024 bit rsa

* Cleanup

* Cleanup

* Clean out MLDSA refs for now

* Dump notifier changes

* Put back UI tweaks

* Fixes.
2025-08-24 15:35:15 -07:00

40 lines
1.2 KiB
Swift

import Foundation
import Observation
/// A "Store Store," which holds a list of type-erased stores.
@Observable @MainActor public final class SecretStoreList: Sendable {
/// The Stores managed by the SecretStoreList.
public var stores: [AnySecretStore] = []
/// A modifiable store, if one is available.
public var modifiableStore: AnySecretStoreModifiable? = nil
/// Initializes a SecretStoreList.
public nonisolated init() {
}
/// Adds a non-type-erased SecretStore to the list.
public func add<SecretStoreType: SecretStore>(store: SecretStoreType) {
stores.append(AnySecretStore(store))
}
/// Adds a non-type-erased modifiable SecretStore.
public func add<SecretStoreType: SecretStoreModifiable>(store: SecretStoreType) {
let modifiable = AnySecretStoreModifiable(store)
if modifiableStore == nil {
modifiableStore = modifiable
}
stores.append(modifiable)
}
/// A boolean describing whether there are any Stores available.
public var anyAvailable: Bool {
stores.contains(where: \.isAvailable)
}
public var allSecrets: [AnySecret] {
stores.flatMap(\.secrets)
}
}