Session

Struct Session 

Source
pub struct Session<D> { /* private fields */ }
Expand description

A MLS Session enables a user device to communicate via the MLS protocol.

This closely maps to the Client term in RFC 9720, but we avoid that term to avoid ambiguity; Client is very overloaded with distinct meanings.

There is one Session per user per device. A session can contain many MLS groups/conversations.

It is cheap to clone a Session because everything heavy is wrapped inside an Arc.

§Why does the session have a generic parameter?

The reason is to ensure at compile time that from inside the session, we don’t have the full interface of the database, just the read-only one, so we don’t have to remember that the session should only have API that doesn’t require writing to the DB – it won’t compile if we forget and try to do that. All API requiring to write to the DB should live on the transaction context.

Ideally, we’d like to have the database as an Arc<dyn FetchFromDatabase>> field on the session. However, we’d need to refactor the FetchFromDatabase trait, and thus the Entity trait to be dyn-compatible, which would require us to rewrite the entire keystore crate.

Implementations§

Source§

impl<D> Session<D>

Source

pub async fn find_credentials( &self, find_filters: CredentialFindFilters<'_>, ) -> Result<Vec<CredentialRef>, Error>

Find all credentials known by this session which match the specified conditions.

If no filters are set, this is equivalent to Self::get_credentials.

Source

pub async fn get_credentials(&self) -> Result<Vec<CredentialRef>, Error>

Get all credentials known by this session.

Source§

impl<D> Session<D>

Source

pub async fn e2ei_is_pki_env_setup(&self) -> bool

Returns whether the E2EI PKI environment is setup (i.e. Root CA, Intermediates, CRLs)

Source

pub async fn e2ei_is_enabled( &self, ciphersuite: Ciphersuite, ) -> Result<bool, Error>

Returns true if end-to-end-identity is enabled for the given ciphersuite.

This is determined by checking for existence of credentials for the given ciphersuite: If there are x509 (and optionally basic) credentials -> Ok(true) If there are no x509 but basic credentials -> Ok(false) If there are no credentials for the given ciphersuite -> Err(CredentialNotFound)

Source

pub async fn e2ei_verify_group_state( &self, group_info: VerifiableGroupInfo, ) -> Result<E2eiConversationState, Error>

Verifies a Group state before joining it

Source

pub async fn get_credential_in_use( &self, group_info: VerifiableGroupInfo, credential_type: CredentialType, ) -> Result<E2eiConversationState, Error>

Gets the e2ei conversation state from a GroupInfo. Useful to check if the group has e2ei turned on or not before joining it.

Source§

impl<D> Session<D>

Source

pub async fn register_epoch_observer( &self, epoch_observer: Arc<dyn EpochObserver>, ) -> Result<(), Error>

Add an epoch observer to this session. (see EpochObserver).

This function should be called 0 or 1 times in a session’s lifetime. If called when an epoch observer already exists, this will return an error.

Source§

impl<D> Session<D>

Source

pub async fn register_history_observer( &self, history_observer: Arc<dyn HistoryObserver>, ) -> Result<()>

Add an history observer to this session. (see HistoryObserver).

This function should be called 0 or 1 times in a session’s lifetime. If called when an epoch observer already exists, this will return an error.

Source§

impl<D> Session<D>

Source

pub async fn get_keypackage_refs(&self) -> Result<Vec<KeypackageRef>, Error>

Get all KeypackageRefs in the database.

Source§

impl<D: FetchFromDatabase> Session<D>

Source

pub fn new( id: ClientId, crypto_provider: MlsCryptoProvider, database: D, transport: Arc<dyn MlsTransport>, ) -> Self

Create a new Session

Source

pub async fn get_raw_conversation( &self, id: &ConversationIdRef, ) -> Result<ImmutableConversation<D>, Error>

Get an immutable view of an MlsConversation.

Because it operates on the raw conversation type, this may be faster than crate::transaction_context::TransactionContext::conversation for transient and immutable purposes. For long-lived or mutable purposes, prefer the other method.

Source

pub async fn conversation_exists( &self, id: &ConversationIdRef, ) -> Result<bool, Error>

Checks if a given conversation id exists locally

Source

pub fn random_bytes(&self, len: usize) -> Result<Vec<u8>>

Generates a random byte array of the specified size

Source

pub async fn close(&self) -> Result<()>

Waits for running transactions to finish, then closes the connection with the local KeyStore.

§Errors

KeyStore errors, such as IO, and if there is more than one strong reference to the connection.

Source

pub fn database(&self) -> &impl FetchFromDatabase

Get read-only access to the database.

Source

pub async fn reseed(&self, seed: Option<EntropySeed>) -> Result<()>

Source

pub fn id(&self) -> ClientId

Retrieves the client’s client id. This is free-form and not inspected.

Trait Implementations§

Source§

impl<D: Clone> Clone for Session<D>

Source§

fn clone(&self) -> Session<D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D> Debug for Session<D>
where D: Debug,

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<D> Freeze for Session<D>
where D: Freeze,

§

impl<D> !RefUnwindSafe for Session<D>

§

impl<D> Send for Session<D>
where D: Send,

§

impl<D> Sync for Session<D>
where D: Sync,

§

impl<D> Unpin for Session<D>
where D: Unpin,

§

impl<D> !UnwindSafe for Session<D>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T