Skip to main content

E2ESession

Struct E2ESession 

Source
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

Source

pub fn new(config: E2ESessionConfig) -> Self

Source

pub fn encrypted(&self) -> bool

Whether this session has an active group key.

Source

pub fn base_path(&self) -> &str

The base path for this session’s E2E subpaths.

Source

pub async fn start(&mut self) -> Result<()>

Start the session: attempt to load a persisted group key.

Source

pub async fn enable_encryption(&mut self) -> Result<PublicKeyAnnouncement>

Enable encryption: generate a new group key. Returns a PublicKeyAnnouncement to be published via CLASP.

Source

pub fn request_group_key(&mut self) -> Result<Option<PublicKeyAnnouncement>>

Create a public key announcement (for requestGroupKey).

Source

pub fn encrypt(&self, value: &str) -> Result<E2EEnvelope>

Encrypt a string value into an E2EEnvelope.

Source

pub async fn decrypt(&mut self, envelope: &E2EEnvelope) -> Result<String>

Decrypt an E2EEnvelope back to a string.

Source

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.

Source

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.

Source

pub async fn rotate_key(&mut self) -> Result<Vec<(String, KeyExchangeMessage)>>

Rotate the group key. Returns KeyExchangeMessages for all cached peers.

Source

pub fn remove_peer(&mut self, peer_id: &str)

Remove a peer’s cached public key.

Source

pub fn should_rotate(&self) -> bool

Check whether automatic rotation is due.

Source

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.

Source

pub fn rotation_count(&self) -> u64

Number of key rotations performed in this session.

Source

pub fn last_rotation(&self) -> Option<u64>

Timestamp of the last key rotation (Unix ms), if any.

Source

pub fn destroy(&mut self)

Destroy the session, zeroing all key material.

Trait Implementations§

Source§

impl Drop for E2ESession

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V