Skip to main content

ping_mls_store/
backend.rs

1// `PathBuf` + `Zeroizing` are only referenced by the `Sqlite` variant, which is
2// native-only. Gate the imports the same way to avoid a wasm32 unused-imports lint.
3#[cfg(not(target_arch = "wasm32"))]
4use std::path::PathBuf;
5#[cfg(not(target_arch = "wasm32"))]
6use zeroize::Zeroizing;
7
8/// Where the persistent provider checkpoints `MemoryStorage` to. Selected at
9/// `MessagingClient::init` time via [`ping_core::ClientConfig::storage_backend`].
10#[derive(Debug, Clone, Default)]
11pub enum StorageBackend {
12    /// In-memory only. Default and what tests use; loses state on process exit.
13    /// Cold-start scenarios (iOS NSE, web Service Worker) MUST use [`Self::Sqlite`]
14    /// or [`Self::IndexedDb`] instead.
15    #[default]
16    Memory,
17
18    /// SQLite-backed; native targets only. The SDK owns the file at `path`; the
19    /// parent directory must exist. Pass `encryption_key = Some(...)` to enable
20    /// SQLCipher; absence means the file is unencrypted (tests, dev only).
21    #[cfg(not(target_arch = "wasm32"))]
22    Sqlite {
23        /// Absolute path. Host convention: `<app_support>/ping/<account_id>/mls.sqlite`
24        /// for per-account isolation (CR-18); the SDK doesn't enforce this — the host
25        /// picks the path.
26        path: PathBuf,
27        /// SQLCipher key. The SDK zeroes its copy on drop; the host is responsible
28        /// for sourcing this from the OS keyring (Keychain / Keystore / etc.).
29        encryption_key: Option<Zeroizing<[u8; 32]>>,
30    },
31
32    /// IndexedDB-backed; WASM only. Placeholder for the chunk-2 implementation — the
33    /// memo's recommended approach. Returns an error from `PersistentMlsProvider::open`
34    /// today; tracking issue: CR-4 WASM follow-up.
35    #[cfg(target_arch = "wasm32")]
36    IndexedDb { db_name: String },
37}