diff --git a/Package.resolved b/Package.resolved index 20e759a..2704ea8 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "a9b23d82f5250c6c8e985d858107c64aa64534998518eb29a0cdc55f6e978eb8", + "originHash" : "c8a627aa8f2d0a03f1ae2545eef09f0a70810ecce4dc16cbff6f664abc9772f5", "pins" : [ { "identity" : "combine-schedulers", diff --git a/Package.swift b/Package.swift index f28a2a6..ecc8957 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,6 @@ let package = Package( .iOS(.v16), .macOS(.v13), .tvOS(.v16), - .visionOS(.v1), .watchOS(.v9) ], products: [ diff --git a/Sources/Keychain/Keychain+Sharing.swift b/Sources/Keychain/Keychain+Sharing.swift new file mode 100644 index 0000000..6ee09da --- /dev/null +++ b/Sources/Keychain/Keychain+Sharing.swift @@ -0,0 +1,57 @@ +#if canImport(Sharing) +import Dependencies +import Sharing + +extension SharedKey where Value: Codable & Sendable { + + public static func keychain(_ key: String) -> Self where Self == KeychainStorageKey { + KeychainStorageKey(key: key) + } + +} + +public struct KeychainStorageKey: SharedKey { + + @Dependency(\.keychain) private var _keychain + private let key: String + + public init(key: String) { + self.key = key + } + + public func load(context: LoadContext, continuation: LoadContinuation) { + do { + let value: Value = try _keychain.load(key: key) + continuation.resume(returning: value) + } catch { + continuation.resume(throwing: error) + } + } + + public func save(_ value: Value, context: SaveContext, continuation: SaveContinuation) { + do { + try _keychain.save(key: key, value: value) + continuation.resume() + } catch { + continuation.resume(throwing: error) + } + } + + public func subscribe(context: LoadContext, subscriber: SharedSubscriber) -> SharedSubscription { + SharedSubscription {} + } + +} + +extension KeychainStorageKey: Equatable, Hashable { + + public static func == (lhs: KeychainStorageKey, rhs: KeychainStorageKey) -> Bool { + lhs.key == rhs.key + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(key) + } + +} +#endif diff --git a/Sources/Keychain/InMemoryKeychain.swift b/Sources/Keychain/Keychains/InMemoryKeychain.swift similarity index 100% rename from Sources/Keychain/InMemoryKeychain.swift rename to Sources/Keychain/Keychains/InMemoryKeychain.swift diff --git a/Sources/Keychain/ValetKeychain.swift b/Sources/Keychain/Keychains/ValetKeychain.swift similarity index 100% rename from Sources/Keychain/ValetKeychain.swift rename to Sources/Keychain/Keychains/ValetKeychain.swift