[][src]Struct matrix_sdk_crypto::OlmMachine

pub struct OlmMachine { /* fields omitted */ }

State machine implementation of the Olm/Megolm encryption protocol used for Matrix end to end encryption.

Implementations

impl OlmMachine[src]

pub fn new(user_id: &UserId, device_id: &DeviceId) -> Self[src]

Create a new memory based OlmMachine.

The created machine will keep the encryption keys only in memory and once the object is dropped the keys will be lost.

Arguments

  • user_id - The unique id of the user that owns this machine.

  • device_id - The unique id of the device that owns this machine.

pub async fn new_with_store(
    user_id: UserId,
    device_id: DeviceIdBox,
    store: Box<dyn CryptoStore>
) -> StoreResult<Self>
[src]

Create a new OlmMachine with the given CryptoStore.

The created machine will keep the encryption keys only in memory and once the object is dropped the keys will be lost.

If the store already contains encryption keys for the given user/device pair those will be re-used. Otherwise new ones will be created and stored.

Arguments

  • user_id - The unique id of the user that owns this machine.

  • device_id - The unique id of the device that owns this machine.

  • store - A Cryptostore implementation that will be used to store the encryption keys.

pub async fn new_with_default_store(
    user_id: &UserId,
    device_id: &DeviceId,
    path: impl AsRef<Path>,
    passphrase: &str
) -> StoreResult<Self>
[src]

This is supported on sqlite_cryptostore only.

Create a new machine with the default crypto store.

The default store uses a SQLite database to store the encryption keys.

Arguments

  • user_id - The unique id of the user that owns this machine.

  • device_id - The unique id of the device that owns this machine.

pub fn user_id(&self) -> &UserId[src]

The unique user id that owns this OlmMachine instance.

pub fn device_id(&self) -> &DeviceId[src]

The unique device id that identifies this OlmMachine.

pub fn identity_keys(&self) -> &IdentityKeys[src]

Get the public parts of our Olm identity keys.

pub async fn outgoing_requests(&self) -> Vec<OutgoingRequest>[src]

Get the outgoing requests that need to be sent out.

This returns a list of OutGoingRequest, those requests need to be sent out to the server and the responses need to be passed back to the state machine using mark_request_as_sent.

pub async fn mark_request_as_sent<'a>(
    &self,
    request_id: &Uuid,
    response: impl Into<IncomingResponse<'a>>
) -> Result<(), OlmError>
[src]

Mark the request with the given request id as sent.

Arguments

  • request_id - The unique id of the request that was sent out. This is needed to couple the response with the now sent out request.

  • response - The response that was received from the server after the outgoing request was sent out.

pub async fn bootstrap_cross_signing(
    &self,
    reset: bool
) -> StoreResult<(UploadSigningKeysRequest, UploadSignaturesRequest)>
[src]

Create a new cross signing identity and get the upload request to push the new public keys to the server.

Warning: This will delete any existing cross signing keys that might exist on the server and thus will reset the trust between all the devices.

Uploading these keys will require user interactive auth.

pub async fn get_missing_sessions(
    &self,
    users: &mut impl Iterator<Item = &UserId>
) -> Result<Option<(Uuid, KeysClaimRequest)>, OlmError>
[src]

Get the a key claiming request for the user/device pairs that we are missing Olm sessions for.

Returns None if no key claiming request needs to be sent out.

Sessions need to be established between devices so group sessions for a room can be shared with them.

This should be called every time a group session needs to be shared as well as between sync calls. After a sync some devices may request room keys without us having a valid Olm session with them, making it impossible to server the room key request, thus it's necessary to check for missing sessions between sync as well.

Note: Care should be taken that only one such request at a time is in flight, e.g. using a lock.

The response of a successful key claiming requests needs to be passed to the OlmMachine with the mark_request_as_sent.

Arguments

users - The list of users that we should check if we lack a session with one of their devices. This can be an empty iterator when calling this method between sync requests.

pub async fn encrypt(
    &self,
    room_id: &RoomId,
    content: AnyMessageEventContent
) -> Result<EncryptedEventContent, MegolmError>
[src]

Encrypt a room message for the given room.

Beware that a group session needs to be shared before this method can be called using the share_group_session method.

Since group sessions can expire or become invalid if the room membership changes client authors should check with the should_share_group_session method if a new group session needs to be shared.

Arguments

  • room_id - The id of the room for which the message should be encrypted.

  • content - The plaintext content of the message that should be encrypted.

Panics

Panics if a group session for the given room wasn't shared beforehand.

pub fn should_share_group_session(&self, room_id: &RoomId) -> bool[src]

Should the client share a group session for the given room.

Returns true if a session needs to be shared before room messages can be encrypted, false if one is already shared and ready to encrypt room messages.

This should be called every time a new room message wants to be sent out since group sessions can expire at any time.

pub fn invalidate_group_session(&self, room_id: &RoomId) -> bool[src]

Invalidate the currently active outbound group session for the given room.

Returns true if a session was invalidated, false if there was no session to invalidate.

pub async fn share_group_session(
    &self,
    room_id: &RoomId,
    users: impl Iterator<Item = &UserId>,
    encryption_settings: impl Into<EncryptionSettings>
) -> Result<Vec<Arc<ToDeviceRequest>>, OlmError>
[src]

Get to-device requests to share a group session with users in a room.

Arguments

room_id - The room id of the room where the group session will be used.

users - The list of users that should receive the group session.

pub fn get_verification(&self, flow_id: &str) -> Option<Sas>[src]

Get a Sas verification object with the given flow id.

pub async fn receive_sync_response(
    &self,
    response: &mut SyncResponse
) -> Result<(), OlmError>
[src]

Handle a sync response and update the internal state of the Olm machine.

This will decrypt to-device events but will not touch events in the room timeline.

To decrypt an event from the room timeline call decrypt_room_event.

Arguments

  • response - The sync latest sync response.

pub async fn decrypt_room_event(
    &self,
    event: &SyncMessageEvent<EncryptedEventContent>,
    room_id: &RoomId
) -> Result<Raw<AnySyncRoomEvent>, MegolmError>
[src]

Decrypt an event from a room timeline.

Arguments

  • event - The event that should be decrypted.

  • room_id - The ID of the room where the event was sent to.

pub async fn update_tracked_users(
    &self,
    users: impl IntoIterator<Item = &UserId>
)
[src]

Update the tracked users.

Arguments

  • users - An iterator over user ids that should be marked for tracking.

This will mark users that weren't seen before for a key query and tracking.

If the user is already known to the Olm machine it will not be considered for a key query.

pub async fn get_device(
    &self,
    user_id: &UserId,
    device_id: &DeviceId
) -> StoreResult<Option<Device>>
[src]

Get a specific device of a user.

Arguments

  • user_id - The unique id of the user that the device belongs to.

  • device_id - The unique id of the device.

Returns a Device if one is found and the crypto store didn't throw an error.

Example

let device = machine.get_device(&alice, "DEVICEID".into()).await;

println!("{:?}", device);

pub async fn get_user_devices(
    &self,
    user_id: &UserId
) -> StoreResult<UserDevices>
[src]

Get a map holding all the devices of an user.

Arguments

  • user_id - The unique id of the user that the devices belong to.

Example

let devices = machine.get_user_devices(&alice).await.unwrap();

for device in devices.devices() {
    println!("{:?}", device);
}

pub async fn import_keys(
    &self,
    exported_keys: Vec<ExportedRoomKey>
) -> StoreResult<(usize, usize)>
[src]

Import the given room keys into our store.

Arguments

  • exported_keys - A list of previously exported keys that should be imported into our store. If we already have a better version of a key the key will not be imported.

Returns a tuple of numbers that represent the number of sessions that were imported and the total number of sessions that were found in the key export.

Examples

let exported_keys = decrypt_key_export(export, "1234").unwrap();
machine.import_keys(exported_keys).await.unwrap();

pub async fn export_keys(
    &self,
    predicate: impl FnMut(&InboundGroupSession) -> bool
) -> StoreResult<Vec<ExportedRoomKey>>
[src]

Export the keys that match the given predicate.

Arguments

  • predicate - A closure that will be called for every known InboundGroupSession, which represents a room key. If the closure returns true the InboundGroupSessoin will be included in the export, if the closure returns false it will not be included.

Panics

This method will panic if it can't get enough randomness from the OS to encrypt the exported keys securely.

Examples

let room_id = room_id!("!test:localhost");
let exported_keys = machine.export_keys(|s| s.room_id() == &room_id).await.unwrap();
let encrypted_export = encrypt_key_export(&exported_keys, "1234", 1);

Trait Implementations

impl Clone for OlmMachine[src]

impl Debug for OlmMachine[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> AsyncTraitDeps for T where
    T: Send + Sync + Debug
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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