Struct vodozemac::olm::Session

source ·
pub struct Session { /* private fields */ }
Expand description

An Olm session represents one end of an encrypted communication channel between two participants.

A session enables enables the session owner to encrypt messages intended for, and decrypt messages sent by, the other participant of the channel.

Olm sessions have two important properties:

  1. They are based on a double ratchet algorithm which continuously introduces new entropy into the channel as messages are sent and received. This imbues the channel with self-healing properties, allowing it to recover from a momentary loss of confidentiality in the event of a key compromise.
  2. They are asynchronous, allowing the participant to start sending messages to the other side even if the other participant is not online at the moment.

An Olm Session is acquired from an Account, by calling either

Implementations§

source§

impl Session

source

pub fn session_id(&self) -> String

Returns the globally unique session ID, in base64-encoded form.

This is a shorthand helper of the SessionKeys::session_id() method.

source

pub fn has_received_message(&self) -> bool

Have we ever received and decrypted a message from the other side?

Used to decide if outgoing messages should be sent as normal or pre-key messages.

source

pub fn encrypt(&mut self, plaintext: impl AsRef<[u8]>) -> OlmMessage

Encrypt the plaintext and construct an OlmMessage.

The message will either be a pre-key message or a normal message, depending on whether the session is fully established. A session is fully established once you receive (and decrypt) at least one message from the other side.

source

pub fn session_keys(&self) -> SessionKeys

Get the keys associated with this session.

source

pub fn session_config(&self) -> SessionConfig

source

pub fn decrypt( &mut self, message: &OlmMessage ) -> Result<Vec<u8>, DecryptionError>

Try to decrypt an Olm message, which will either return the plaintext or result in a DecryptionError.

source

pub fn pickle(&self) -> SessionPickle

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

source

pub fn from_pickle(pickle: SessionPickle) -> Self

Restore a Session from a previously saved SessionPickle.

source

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

Available on crate feature libolm-compat only.

Create a Session object by unpickling a session pickle in libolm legacy pickle format.

Such pickles are encrypted and need to first be decrypted using pickle_key.

Trait Implementations§

source§

impl Debug for Session

source§

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

Formats the value using the given formatter. Read more
source§

impl From<SessionPickle> for Session

source§

fn from(pickle: SessionPickle) -> 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