Struct matrix_sdk_crypto::olm::Session
source · pub struct Session {
pub user_id: OwnedUserId,
pub device_id: OwnedDeviceId,
pub our_identity_keys: Arc<IdentityKeys>,
pub inner: Arc<Mutex<Session>>,
pub session_id: Arc<str>,
pub sender_key: Curve25519PublicKey,
pub created_using_fallback_key: bool,
pub creation_time: SecondsSinceUnixEpoch,
pub last_use_time: SecondsSinceUnixEpoch,
}
Expand description
Cryptographic session that enables secure communication between two
Account
s
Fields§
§user_id: OwnedUserId
The UserId
associated with this session
device_id: OwnedDeviceId
The specific DeviceId
associated with this session
our_identity_keys: Arc<IdentityKeys>
The IdentityKeys
associated with this session
inner: Arc<Mutex<Session>>
The OlmSession
session_id: Arc<str>
Our sessionId
sender_key: Curve25519PublicKey
The Key of the sender
created_using_fallback_key: bool
Has this been created using the fallback key
creation_time: SecondsSinceUnixEpoch
When the session was created
last_use_time: SecondsSinceUnixEpoch
When the session was last used
Implementations§
source§impl Session
impl Session
sourcepub async fn decrypt(
&mut self,
message: &OlmMessage
) -> Result<String, DecryptionError>
pub async fn decrypt( &mut self, message: &OlmMessage ) -> Result<String, DecryptionError>
Decrypt the given Olm message.
Returns the decrypted plaintext or a DecryptionError
if decryption
failed.
Arguments
message
- The Olm message that should be decrypted.
sourcepub fn sender_key(&self) -> Curve25519PublicKey
pub fn sender_key(&self) -> Curve25519PublicKey
Get the sender key that was used to establish this Session.
sourcepub async fn session_config(&self) -> SessionConfig
pub async fn session_config(&self) -> SessionConfig
Get the SessionConfig
that this session is using.
sourcepub async fn algorithm(&self) -> EventEncryptionAlgorithm
pub async fn algorithm(&self) -> EventEncryptionAlgorithm
Get the EventEncryptionAlgorithm
of this Session
.
sourcepub async fn encrypt(
&mut self,
recipient_device: &ReadOnlyDevice,
event_type: &str,
content: impl Serialize,
message_id: Option<String>
) -> Result<Raw<ToDeviceEncryptedEventContent>, OlmError>
pub async fn encrypt( &mut self, recipient_device: &ReadOnlyDevice, event_type: &str, content: impl Serialize, message_id: Option<String> ) -> Result<Raw<ToDeviceEncryptedEventContent>, OlmError>
Encrypt the given event content content as an m.room.encrypted event content.
Arguments
-
recipient_device
- The device for which this message is going to be encrypted, this needs to be the device that was used to create this session with. -
event_type
- The type of the event content. -
content
- The content of the event.
sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Returns the unique identifier for this session.
sourcepub async fn pickle(&self) -> PickledSession
pub async fn pickle(&self) -> PickledSession
Store the session as a base64 encoded string.
Arguments
pickle_mode
- The mode that was used to pickle the session, either an unencrypted mode or an encrypted using passphrase.
sourcepub fn from_pickle(
user_id: OwnedUserId,
device_id: OwnedDeviceId,
our_identity_keys: Arc<IdentityKeys>,
pickle: PickledSession
) -> Self
pub fn from_pickle( user_id: OwnedUserId, device_id: OwnedDeviceId, our_identity_keys: Arc<IdentityKeys>, pickle: PickledSession ) -> Self
Restore a Session from a previously pickled string.
Returns the restored Olm Session or a SessionUnpicklingError
if there
was an error.
Arguments
-
user_id
- Our own user id that the session belongs to. -
device_id
- Our own device ID that the session belongs to. -
our_identity_keys
- An clone of the Arc to our own identity keys. -
pickle
- The pickled version of theSession
. -
pickle_mode
- The mode that was used to pickle the session, either an unencrypted mode or an encrypted using passphrase.