Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager { /* private fields */ }
Expand description

Manages 1:1 encrypted sessions.

Implementations§

Source§

impl SessionManager

Source

pub fn new( user_id: String, storage: Arc<dyn MlsStorage>, provider: MlsProvider, ) -> Self

Creates a new session manager.

Source

pub fn last_seal_mark(&self, other_user_id: &str) -> Option<SealMark>

The position of the most recent frame sealed for other_user_id, or None when nothing has been sealed in this session since it started (or since this process did).

Source

pub fn note_acknowledged_seal(&self, other_user_id: &str, mark: SealMark)

Records that the peer received the frame at mark, so it has decrypted at least that far into the session. Ignored for a frame of an earlier incarnation of the session.

Source

pub fn unacknowledged_seals(&self, other_user_id: &str) -> u64

How many frames this device has sealed for other_user_id past the last one the peer acknowledged.

A receiver cannot decrypt a frame more than the forward window past the newest it has decrypted, and an acknowledged frame is one it has, so keeping this below the window keeps every frame decryptable. The sender is what controls it: each re-sealed resend adds one.

Source

pub fn group_manager(&self) -> &GroupManager

Returns a reference to the underlying group manager.

Source

pub fn get_session_id(&self, other_user_id: &str) -> Result<GroupId>

Gets the session ID for a 1:1 conversation with another user.

Fails with crate::MlsError::InvalidGroupId if other_user_id contains storage-hostile characters (the session id is a raw storage key).

Source

pub fn has_session(&self, other_user_id: &str) -> Result<bool>

Checks if a session exists with another user.

Source

pub fn create_session( &self, other_user_id: &str, their_key_package: KeyPackage, credential_with_key: &CredentialWithKey, signer: &impl Signer, ) -> Result<WelcomeMessage>

Creates a new session with another user using their key package.

Source

pub fn join_session(&self, welcome_msg: &WelcomeMessage) -> Result<GroupInfo>

Joins a session using a Welcome message.

Implements a non-destructive “welcome-wins” strategy: if we already created a session for this peer (both-create race), the incoming Welcome is staged first and only replaces our group once staging succeeds (see crate::group::GroupManager::join_group_replacing). A retransmitted Welcome we already adopted, or a first-contact key-package race, fails to stage and leaves the existing converged group intact — so adoption is idempotent and never bricks a working session.

Source

pub fn encrypt_message( &self, other_user_id: &str, plaintext: &[u8], signer: &impl Signer, ) -> Result<EncryptedMessage>

Encrypts a message for the session partner.

Source

pub fn decrypt_message( &self, encrypted: &EncryptedMessage, claimed_sender: &str, ) -> Result<Option<Vec<u8>>>

Decrypts a message from a session.

claimed_sender is the transport-level sender this message will be attributed to; it must match the MLS-authenticated credential.

The envelope’s group_id is bound to claimed_sender before the group is loaded, because every failure OpenMLS raises below happens before it authenticates anything — see MlsError::SessionIdentityMismatch. This is the single chokepoint for the binding: decrypt_from_user is reachable both from the receive path and from the public manual_mls_decrypt_from_user API, so checking it in either caller alone leaves the other as a bypass.

Source

pub fn list_sessions(&self) -> Result<Vec<String>>

Lists the peers this device has a 1:1 session with.

A session id is session:<a>:<b> where exactly one of the two halves is us — ids cannot contain : (GroupId::validate runs the storage-key charset check per segment), so the split is unambiguous. Anything that does not have that exact shape is skipped rather than guessed at: a slot naming two other parties has no “other peer” to report, and returning one half of it anyway would surface a peer this device has no session with.

Source

pub fn delete_session(&self, other_user_id: &str) -> Result<()>

Deletes a session.

Source

pub fn get_session_info(&self, other_user_id: &str) -> Result<Option<GroupInfo>>

Gets information about a session.

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> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> Declassify for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more