Struct vodozemac::megolm::InboundGroupSession
source · pub struct InboundGroupSession { /* private fields */ }
Implementations§
source§impl InboundGroupSession
impl InboundGroupSession
pub fn new(key: &SessionKey, session_config: SessionConfig) -> Self
pub fn import( session_key: &ExportedSessionKey, session_config: SessionConfig, ) -> Self
pub fn session_id(&self) -> String
sourcepub fn connected(&mut self, other: &mut InboundGroupSession) -> bool
pub fn connected(&mut self, other: &mut InboundGroupSession) -> bool
Check if two InboundGroupSession
s 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
InboundGroupSession
s 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 InboundGroupSession
s 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.
sourcepub fn compare(&mut self, other: &mut InboundGroupSession) -> SessionOrdering
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.
sourcepub fn merge(
&mut self,
other: &mut InboundGroupSession,
) -> Option<InboundGroupSession>
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);
pub fn first_known_index(&self) -> u32
sourcepub fn advance_to(&mut self, index: u32) -> bool
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.
pub fn decrypt( &mut self, message: &MegolmMessage, ) -> Result<DecryptedMessage, DecryptionError>
pub fn export_at(&mut self, index: u32) -> Option<ExportedSessionKey>
pub fn export_at_first_known_index(&self) -> ExportedSessionKey
sourcepub fn pickle(&self) -> InboundGroupSessionPickle
pub fn pickle(&self) -> InboundGroupSessionPickle
Convert the inbound group session into a struct which implements
serde::Serialize
and serde::Deserialize
.
sourcepub fn from_pickle(pickle: InboundGroupSessionPickle) -> Self
pub fn from_pickle(pickle: InboundGroupSessionPickle) -> Self
Restore an InboundGroupSession
from a previously saved
InboundGroupSessionPickle
.