Struct vodozemac::megolm::InboundGroupSession

source ·
pub struct InboundGroupSession { /* private fields */ }

Implementations§

source§

impl InboundGroupSession

source

pub fn new(key: &SessionKey, session_config: SessionConfig) -> Self

source

pub fn import( session_key: &ExportedSessionKey, session_config: SessionConfig ) -> Self

source

pub fn session_id(&self) -> String

source

pub fn connected(&mut self, other: &mut InboundGroupSession) -> bool

Check if two InboundGroupSessions are the same.

An InboundGroupSession could be received multiple times with varying degrees of trust and first known message indices.

This method checks if the underlying ratchets of the two InboundGroupSessions are actually the same ratchet, potentially at a different ratcheting index. That is, if the sessions are connected, then ratcheting one of the ratchets to the index of the other should yield the same ratchet value, byte-for-byte. This will only be the case if the InboundGroupSessions were created from the same GroupSession.

If the sessions are connected, the session with the lower message index can safely replace the one with the higher message index.

source

pub fn compare(&mut self, other: &mut InboundGroupSession) -> SessionOrdering

Compare the InboundGroupSession with the given other InboundGroupSession.

Returns a SessionOrdering describing how the two sessions relate to each other.

source

pub fn merge( &mut self, other: &mut InboundGroupSession ) -> Option<InboundGroupSession>

Merge the session with the given other session, picking the best parts from each of them.

This method is useful when you receive multiple sessions with the same session ID but potentially different ratchet indices and authenticity properties.

For example, imagine you receive a SessionKey S1 with ratchet index A from a fully-trusted source and an ExportedSessionKey S2 with ratchet state B from a less trusted source. If A > B, then S1 is better because it’s fully trusted, but worse because it’s ratcheted further than S2.

This method allows you to merge S1 and S2 safely into a fully-trusted S3 with ratchet state B, provided S1 and S2 connect with each other (meaning they are the same session, just at different ratchet indices).

Returns Some(session) if the sessions could be merged, i.e. they are considered to be connected and None otherwise.

§Example
use vodozemac::megolm::{GroupSession, InboundGroupSession, SessionOrdering};

let session = GroupSession::new(Default::default());
let session_key = session.session_key();

let mut first_session = InboundGroupSession::new(&session_key, Default::default());
let mut second_session = InboundGroupSession::import(&first_session.export_at(10).unwrap(), Default::default());

assert_eq!(first_session.compare(&mut second_session), SessionOrdering::Better);

let mut merged = second_session.merge(&mut first_session).unwrap();

assert_eq!(merged.compare(&mut second_session), SessionOrdering::Better);
assert_eq!(merged.compare(&mut first_session), SessionOrdering::Equal);
source

pub fn first_known_index(&self) -> u32

source

pub fn advance_to(&mut self, index: u32) -> bool

Permanently advance the session to the given index.

This will remove the ability to decrypt messages that were encrypted with a lower message index than what is given as the argument.

Returns true if the ratchet has been advanced, false if the ratchet was already advanced past the given index.

source

pub fn decrypt( &mut self, message: &MegolmMessage ) -> Result<DecryptedMessage, DecryptionError>

source

pub fn export_at(&mut self, index: u32) -> Option<ExportedSessionKey>

source

pub fn export_at_first_known_index(&self) -> ExportedSessionKey

source

pub fn pickle(&self) -> InboundGroupSessionPickle

Convert the inbound group session into a struct which implements serde::Serialize and serde::Deserialize.

source

pub fn from_pickle(pickle: InboundGroupSessionPickle) -> Self

Restore an InboundGroupSession from a previously saved InboundGroupSessionPickle.

source

pub fn from_libolm_pickle( pickle: &str, pickle_key: &[u8] ) -> Result<Self, LibolmPickleError>

Available on crate feature libolm-compat only.

Trait Implementations§

source§

impl<'de> Deserialize<'de> for InboundGroupSession

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<&GroupSession> for InboundGroupSession

source§

fn from(session: &GroupSession) -> Self

Converts to this type from the input type.
source§

impl From<&InboundGroupSession> for InboundGroupSessionPickle

source§

fn from(session: &InboundGroupSession) -> Self

Converts to this type from the input type.
source§

impl From<InboundGroupSessionPickle> for InboundGroupSession

source§

fn from(pickle: InboundGroupSessionPickle) -> Self

Converts to this type from the input type.

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,