OZKeychainStorageAdapter

@available(iOS 13.0, macOS 10.15, *)
public final actor OZKeychainStorageAdapter : OZStorageAdapter

Persistent OZStorageAdapter backed by the iOS / macOS Keychain Services API.

Stores credential and session payloads as kSecClassGenericPassword items using the Security framework’s SecItem* primitives. Each entry is a UTF-8 JSON document keyed by a stable account name:

  • cred_<credentialId> for individual stored credentials,
  • credential_index for the JSON-encoded list of known credential IDs,
  • session_current for the active session.

All items are written with kSecAttrAccessibleAfterFirstUnlock so they survive app restarts but become inaccessible until the device is unlocked after a reboot.

Thread safety is provided by Swift Concurrency actor isolation, so all operations serialize even when invoked from multiple tasks.

Example:

let storage = OZKeychainStorageAdapter()
try await storage.save(credential: credential)
let loaded = try await storage.get(credentialId: credential.credentialId)

Important

On iOS Simulator and unsigned macOS test binaries, Keychain access requires the keychain-access-groups entitlement to be configured.