34 lines
1.1 KiB
Swift
34 lines
1.1 KiB
Swift
import Foundation
|
|
@testable import Closer
|
|
|
|
/// In-memory fake for `CoupleKeyStoreProtocol` used in unit tests.
|
|
///
|
|
/// The iOS Keychain requires a device entitlement / simulator environment and
|
|
/// cannot be exercised in a headless Linux Swift build. This fake validates the
|
|
/// store/load/delete contract at the business-logic layer.
|
|
public final class InMemoryCoupleKeyStore: @unchecked Sendable, CoupleKeyStoreProtocol {
|
|
private var storage: [String: Data] = [:]
|
|
private let lock = NSLock()
|
|
|
|
public init() {}
|
|
|
|
public func storeCoupleKey(_ key: CoupleKeyMaterial, for coupleId: String) throws {
|
|
lock.lock()
|
|
defer { lock.unlock() }
|
|
storage[coupleId] = key.rawKey.bytes
|
|
}
|
|
|
|
public func loadCoupleKey(for coupleId: String) throws -> CoupleKeyMaterial? {
|
|
lock.lock()
|
|
defer { lock.unlock() }
|
|
guard let bytes = storage[coupleId] else { return nil }
|
|
return CoupleKeyMaterial(rawBytes: bytes)
|
|
}
|
|
|
|
public func deleteCoupleKey(for coupleId: String) throws {
|
|
lock.lock()
|
|
defer { lock.unlock() }
|
|
storage.removeValue(forKey: coupleId)
|
|
}
|
|
}
|