zoe_client/pqxdh/state.rs
1use serde::{Deserialize, Serialize};
2
3use std::collections::BTreeMap;
4
5use super::PqxdhSession;
6use zoe_wire_protocol::{KeyId, PqxdhInboxProtocol, Tag, inbox::pqxdh::PqxdhInbox};
7
8/// Serializable state for a PQXDH protocol handler
9///
10/// This structure contains all the persistent state needed to restore a
11/// `PqxdhProtocolHandler` across application restarts. It excludes runtime
12/// dependencies like the messages manager and client keypair, focusing only
13/// on the cryptographic and session state that needs to be preserved.
14///
15/// ## Persistence Strategy
16/// This state can be serialized with `postcard` and stored in a database or file
17/// system. When the application restarts, this state can be loaded and used to
18/// reconstruct a fully functional protocol handler.
19///
20/// ## State Components
21/// - **Protocol**: The specific PQXDH protocol variant being used
22/// - **Sessions**: Active sessions keyed by target user ID
23/// - **Inbox Tag**: The published inbox tag (for service providers)
24/// - **Private Keys**: Cryptographic keys for responding to initial messages
25#[derive(Serialize, Deserialize, Clone)]
26pub struct PqxdhProtocolState {
27 /// The PQXDH protocol variant being used
28 pub(super) protocol: PqxdhInboxProtocol,
29 /// Active sessions keyed by target user ID
30 pub(super) sessions: BTreeMap<KeyId, PqxdhSession>,
31 pub(super) inbox_tag: Option<Tag>,
32 pub(super) inbox: Option<PqxdhInbox>,
33 /// Private keys for responding to initial messages (if we're a service provider)
34 pub(super) private_keys: Option<zoe_wire_protocol::inbox::pqxdh::PqxdhPrivateKeys>,
35}
36
37impl PqxdhProtocolState {
38 /// Creates a new empty protocol state
39 ///
40 /// Initializes a new protocol state with the specified protocol variant.
41 /// All other fields are set to their default empty values.
42 ///
43 /// # Arguments
44 /// * `protocol` - The PQXDH protocol variant to use
45 pub fn new(protocol: PqxdhInboxProtocol) -> Self {
46 Self {
47 protocol,
48 sessions: BTreeMap::new(),
49 inbox_tag: None,
50 private_keys: None,
51 inbox: None,
52 }
53 }
54}