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:
- 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.
- 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
Account::create_outbound_session
, if you are the first participant to send a message in this channel, orAccount::create_inbound_session
, if the other participant initiated the channel by sending you a message.
Implementations§
source§impl Session
impl Session
sourcepub fn session_id(&self) -> String
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.
sourcepub const fn has_received_message(&self) -> bool
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.
sourcepub fn encrypt(&mut self, plaintext: impl AsRef<[u8]>) -> OlmMessage
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.
sourcepub const fn session_keys(&self) -> SessionKeys
pub const fn session_keys(&self) -> SessionKeys
Get the keys associated with this session.
sourcepub const fn session_config(&self) -> SessionConfig
pub const fn session_config(&self) -> SessionConfig
Get the SessionConfig
that this Session
is configured to use.
sourcepub fn decrypt(
&mut self,
message: &OlmMessage,
) -> Result<Vec<u8>, DecryptionError>
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
.
sourcepub fn pickle(&self) -> SessionPickle
pub fn pickle(&self) -> SessionPickle
Convert the session into a struct which implements serde::Serialize
and serde::Deserialize
.
sourcepub fn from_pickle(pickle: SessionPickle) -> Self
pub fn from_pickle(pickle: SessionPickle) -> Self
Restore a Session
from a previously saved SessionPickle
.
sourcepub fn from_libolm_pickle(
pickle: &str,
pickle_key: &[u8],
) -> Result<Self, LibolmPickleError>
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
.