pub struct SessionManager { /* private fields */ }Expand description
Manages 1:1 encrypted sessions.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(
user_id: String,
storage: Arc<dyn MlsStorage>,
provider: MlsProvider,
) -> Self
pub fn new( user_id: String, storage: Arc<dyn MlsStorage>, provider: MlsProvider, ) -> Self
Creates a new session manager.
Sourcepub fn last_seal_mark(&self, other_user_id: &str) -> Option<SealMark>
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).
Sourcepub fn note_acknowledged_seal(&self, other_user_id: &str, mark: SealMark)
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.
Sourcepub fn unacknowledged_seals(&self, other_user_id: &str) -> u64
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.
Sourcepub fn group_manager(&self) -> &GroupManager
pub fn group_manager(&self) -> &GroupManager
Returns a reference to the underlying group manager.
Sourcepub fn get_session_id(&self, other_user_id: &str) -> Result<GroupId>
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).
Sourcepub fn has_session(&self, other_user_id: &str) -> Result<bool>
pub fn has_session(&self, other_user_id: &str) -> Result<bool>
Checks if a session exists with another user.
Sourcepub fn create_session(
&self,
other_user_id: &str,
their_key_package: KeyPackage,
credential_with_key: &CredentialWithKey,
signer: &impl Signer,
) -> Result<WelcomeMessage>
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.
Sourcepub fn join_session(&self, welcome_msg: &WelcomeMessage) -> Result<GroupInfo>
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.
Sourcepub fn encrypt_message(
&self,
other_user_id: &str,
plaintext: &[u8],
signer: &impl Signer,
) -> Result<EncryptedMessage>
pub fn encrypt_message( &self, other_user_id: &str, plaintext: &[u8], signer: &impl Signer, ) -> Result<EncryptedMessage>
Encrypts a message for the session partner.
Sourcepub fn decrypt_message(
&self,
encrypted: &EncryptedMessage,
claimed_sender: &str,
) -> Result<Option<Vec<u8>>>
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.
Sourcepub fn list_sessions(&self) -> Result<Vec<String>>
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.
Sourcepub fn delete_session(&self, other_user_id: &str) -> Result<()>
pub fn delete_session(&self, other_user_id: &str) -> Result<()>
Deletes a session.
Auto Trait Implementations§
impl !Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl !UnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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