//! Persistent OpenMLS provider for the Ping SDK ([CR-4]).
//!
//! ## What this crate is
//!
//! The Ping SDK's [`MessagingClient`](::openmls) uses OpenMLS for the cryptographic
//! state machine, and OpenMLS owns its key material via an `OpenMlsProvider`. The
//! reference provider — [`openmls_rust_crypto::OpenMlsRustCrypto`] — keeps everything
//! in memory; on process exit, the state is gone. That breaks the **iOS NSE** and
//! **web Service Worker** cold-start paths, which spin up a *fresh* process expected
//! to decrypt a push payload.
//!
//! This crate adds a persistent provider:
//!
//! ```text
//! PersistentMlsProvider {
//!   crypto:   RustCrypto,          // unchanged — RNG + signature + HPKE + KDF
//!   storage:  MemoryStorage,        // in-process working set (openmls_memory_storage)
//!   backend:  StorageBackend,       // where to flush MemoryStorage to disk
//! }
//! ```
//!
//! Reads hit the in-memory working set (fast). Writes are mediated by OpenMLS through
//! `MemoryStorage`; the provider exposes a [`checkpoint`](PersistentMlsProvider::checkpoint)
//! method the SDK calls after state-changing ops to flush the working set to disk.
//!
//! ## v0.1 serialization strategy
//!
//! For v0.1 we serialize the *entire* `MemoryStorage` HashMap as one CBOR blob per
//! checkpoint and write it to a single SQLite row. Pros: tiny diff against an
//! already-tested in-memory provider; no risk of mis-implementing OpenMLS's ~50-method
//! `StorageProvider<V>` trait. Cons: O(state) write cost per checkpoint. For the v1
//! profile (tens of groups, ~10-100 KB total state), this is fine. A future revision
//! can upgrade to per-row writes behind the same `StorageBackend` enum without
//! changing the public API. See [`docs/design/CR4_CR7_PERSISTENCE.md`] for the longer
//! discussion.
//!
//! ## At-rest encryption
//!
//! The SDK never derives its own key. `StorageBackend::Sqlite::encryption_key`, when
//! present, is passed through to SQLCipher's `PRAGMA key`. Hosts are expected to source
//! it from the OS keyring (Keychain on iOS, Keystore on Android, etc.) — matches the
//! documented split in `docs/architecture/crypto.md §Storage adapters`.

#![deny(unsafe_code)]
#![warn(rust_2018_idioms, missing_debug_implementations)]

mod backend;
mod error;
mod provider;

#[cfg(not(target_arch = "wasm32"))]
mod sqlite;

pub use backend::StorageBackend;
pub use error::{Error, Result};
pub use provider::PersistentMlsProvider;
