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
sourceimpl 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.
A session ID is the SHA256 of the concatenation of the account’s identity key, an ephemeral base key and the one-time key which was used to establish the session. Due to the construction, every session ID is (probabilistically) globally unique.
sourcepub fn has_received_message(&self) -> bool
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.
sourcepub fn encrypt(&mut self, plaintext: &str) -> OlmMessage
pub fn encrypt(&mut self, plaintext: &str) -> 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 fn session_keys(&self) -> SessionKeys
pub fn session_keys(&self) -> SessionKeys
Get the keys associated with this session.
sourcepub fn decrypt(
&mut self,
message: &OlmMessage
) -> Result<String, DecryptionError>
pub fn decrypt(
&mut self,
message: &OlmMessage
) -> Result<String, 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
.
Trait Implementations
sourceimpl From<SessionPickle> for Session
impl From<SessionPickle> for Session
sourcefn from(pickle: SessionPickle) -> Self
fn from(pickle: SessionPickle) -> Self
Converts to this type from the input type.
Auto Trait Implementations
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more