OZUserDefaultsStorageAdapter

public final actor OZUserDefaultsStorageAdapter : OZStorageAdapter

Persistent OZStorageAdapter backed by an isolated UserDefaults suite.

Stores credential and session payloads as UTF-8 JSON strings under stable keys:

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

The adapter scopes every read and write to a UserDefaults(suiteName:) instance so multiple adapter instances configured with different suites do not interfere with one another. Stored credentials contain only public key material plus metadata, so UserDefaults provides adequate isolation for typical use cases. Applications requiring stronger at-rest protection should use OZKeychainStorageAdapter instead.

Thread safety is provided by Swift Concurrency actor isolation, which serializes all operations against the underlying UserDefaults instance.

Example:

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

Important

Not encrypted at rest. UserDefaults persists payloads to a plaintext property-list file in the application container; on a jailbroken device or via an unencrypted iTunes/Finder backup, the contents are recoverable. The credentials persisted by this adapter contain only public-key material and non-secret metadata; applications storing session data or anything sensitive should use OZKeychainStorageAdapter instead.