pub struct E2ESession { /* private fields */ }Expand description
E2E encryption session state machine.
Manages ECDH key exchange, group key distribution, TOFU verification,
and encrypt/decrypt operations. This is the protocol layer that works
with raw bytes and messages — the CryptoClient (behind client feature)
wires it to a CLASP client.
Implementations§
Source§impl E2ESession
impl E2ESession
pub fn new(config: E2ESessionConfig) -> Self
Sourcepub async fn start(&mut self) -> Result<()>
pub async fn start(&mut self) -> Result<()>
Start the session: attempt to load a persisted group key.
Sourcepub async fn enable_encryption(&mut self) -> Result<PublicKeyAnnouncement>
pub async fn enable_encryption(&mut self) -> Result<PublicKeyAnnouncement>
Enable encryption: generate a new group key. Returns a PublicKeyAnnouncement to be published via CLASP.
Sourcepub fn request_group_key(&mut self) -> Result<Option<PublicKeyAnnouncement>>
pub fn request_group_key(&mut self) -> Result<Option<PublicKeyAnnouncement>>
Create a public key announcement (for requestGroupKey).
Sourcepub fn encrypt(&self, value: &str) -> Result<E2EEnvelope>
pub fn encrypt(&self, value: &str) -> Result<E2EEnvelope>
Encrypt a string value into an E2EEnvelope.
Sourcepub async fn decrypt(&mut self, envelope: &E2EEnvelope) -> Result<String>
pub async fn decrypt(&mut self, envelope: &E2EEnvelope) -> Result<String>
Decrypt an E2EEnvelope back to a string.
Sourcepub async fn handle_peer_pubkey(
&mut self,
peer_id: &str,
announcement: &PublicKeyAnnouncement,
) -> Result<Option<KeyExchangeMessage>>
pub async fn handle_peer_pubkey( &mut self, peer_id: &str, announcement: &PublicKeyAnnouncement, ) -> Result<Option<KeyExchangeMessage>>
Handle a peer’s public key announcement. Returns a KeyExchangeMessage if we have the group key and should distribute it.
Password-gated sessions: If password_hash is set, the caller must
verify the peer’s password proof before calling this method. This method
does not enforce password gating — it is the caller’s responsibility.
Sourcepub async fn handle_key_exchange(
&mut self,
msg: &KeyExchangeMessage,
) -> Result<()>
pub async fn handle_key_exchange( &mut self, msg: &KeyExchangeMessage, ) -> Result<()>
Handle a key exchange message sent to us. Decrypts and stores the group key.
Sourcepub async fn rotate_key(&mut self) -> Result<Vec<(String, KeyExchangeMessage)>>
pub async fn rotate_key(&mut self) -> Result<Vec<(String, KeyExchangeMessage)>>
Rotate the group key. Returns KeyExchangeMessages for all cached peers.
Sourcepub fn remove_peer(&mut self, peer_id: &str)
pub fn remove_peer(&mut self, peer_id: &str)
Remove a peer’s cached public key.
Sourcepub fn should_rotate(&self) -> bool
pub fn should_rotate(&self) -> bool
Check whether automatic rotation is due.
Sourcepub async fn maybe_rotate(
&mut self,
) -> Result<Option<(Vec<(String, KeyExchangeMessage)>, PublicKeyAnnouncement)>>
pub async fn maybe_rotate( &mut self, ) -> Result<Option<(Vec<(String, KeyExchangeMessage)>, PublicKeyAnnouncement)>>
Rotate the key if the rotation interval has elapsed.
Returns any key exchange messages to distribute, plus a new
PublicKeyAnnouncement so new peers can request the fresh key.
Sourcepub fn rotation_count(&self) -> u64
pub fn rotation_count(&self) -> u64
Number of key rotations performed in this session.
Sourcepub fn last_rotation(&self) -> Option<u64>
pub fn last_rotation(&self) -> Option<u64>
Timestamp of the last key rotation (Unix ms), if any.