ping-openmls-sdk-mls-store 0.6.13

Persistent OpenMLS provider — SQLite (native) / memory backends ([CR-4])
Documentation
// `PathBuf` + `Zeroizing` are only referenced by the `Sqlite` variant, which is
// native-only. Gate the imports the same way to avoid a wasm32 unused-imports lint.
#[cfg(not(target_arch = "wasm32"))]
use std::path::PathBuf;
#[cfg(not(target_arch = "wasm32"))]
use zeroize::Zeroizing;

use std::sync::Arc;

use crate::AsyncBlobStore;

/// Where the persistent provider checkpoints `MemoryStorage` to. Selected at
/// `MessagingClient::init` time via [`ping_core::ClientConfig::storage_backend`].
#[derive(Debug, Clone, Default)]
pub enum StorageBackend {
    /// In-memory only. Default and what tests use; loses state on process exit.
    /// Cold-start scenarios (iOS NSE, web Service Worker) MUST use [`Self::Sqlite`]
    /// or [`Self::IndexedDb`] instead.
    #[default]
    Memory,

    /// SQLite-backed; native targets only. The SDK owns the file at `path`; the
    /// parent directory must exist. Pass `encryption_key = Some(...)` to enable
    /// SQLCipher; absence means the file is unencrypted (tests, dev only).
    #[cfg(not(target_arch = "wasm32"))]
    Sqlite {
        /// Absolute path. Host convention: `<app_support>/ping/<account_id>/mls.sqlite`
        /// for per-account isolation (CR-18); the SDK doesn't enforce this — the host
        /// picks the path.
        path: PathBuf,
        /// SQLCipher key. The SDK zeroes its copy on drop; the host is responsible
        /// for sourcing this from the OS keyring (Keychain / Keystore / etc.).
        encryption_key: Option<Zeroizing<[u8; 32]>>,
    },

    /// Host-supplied async blob storage. Available on every target.
    ///
    /// The provider snapshots the entire `MemoryStorage` HashMap into a
    /// single CBOR blob and round-trips it through the
    /// [`AsyncBlobStore`] the host implements. This is the universal
    /// persistence path:
    ///   * **WASM**: host wraps its IndexedDB layer (PingStorageWeb, which
    ///     already AES-GCM-encrypts every row under a non-extractable
    ///     wrap key kept inside the same IDB).
    ///   * **iOS / macOS / Android**: host wraps the same `Storage` trait
    ///     it already provides for conv metadata + cursors (typically
    ///     Keychain-encrypted SQLite or AsyncStorage), so the OpenMLS
    ///     snapshot sits under a reserved `("__mls", "snapshot")` slot
    ///     alongside the host's other persisted KV.
    ///
    /// Why this replaces the wasm-only `IndexedDb` variant: any host
    /// that already implements `Storage` (which every binding does)
    /// gets persistence for free, without per-platform path management,
    /// Keychain key plumbing, or SQLCipher dependency. The SQLite
    /// backend remains available for hosts that want a separate file
    /// (e.g. iOS NSE cold-start where the main app's Storage isn't
    /// reachable from the extension).
    AsyncBlob { blob_store: Arc<dyn AsyncBlobStore> },
}