vodozemac::olm

Struct 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 const 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 const fn session_keys(&self) -> SessionKeys

Get the keys associated with this session.

Source

pub const fn session_config(&self) -> SessionConfig

Get the SessionConfig that this Session is configured to use.

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>

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

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V