Crate matrix_sdk_crypto[][src]

Expand description

A no-io implementation of a state machine that handles E2EE for Matrix clients.

Usage

This is probably not the crate you are looking for, it’s used internally in the matrix-sdk.

If you’re still interested in this crate it can be used to introduce E2EE support into your client or client library.

The state machine works in a push/pull manner, you push state changes and events that we receive from a sync response from the server, and we pull requests that we need to send to the server out of the state machine.

use std::{collections::BTreeMap, convert::TryFrom};

use matrix_sdk_crypto::{OlmMachine, OlmError};
use ruma::{UserId, api::client::r0::sync::sync_events::{ToDevice, DeviceLists}};

#[tokio::main]
async fn main() -> Result<(), OlmError> {
    let alice = UserId::try_from("@alice:example.org").unwrap();
    let machine = OlmMachine::new(&alice, "DEVICEID".into());

    let to_device_events = ToDevice::default();
    let changed_devices = DeviceLists::default();
    let one_time_key_counts = BTreeMap::default();

    // Push changes that the server sent to us in a sync response.
    let decrypted_to_device = machine.receive_sync_changes(
        to_device_events,
        &changed_devices,
        &one_time_key_counts
    ).await?;

    // Pull requests that we need to send out.
    let outgoing_requests = machine.outgoing_requests().await?;

    // Send the requests here out and call machine.mark_request_as_sent().

    Ok(())
}

Re-exports

pub use store::CrossSigningKeyExport;
pub use store::CryptoStoreError;
pub use store::SecretImportError;

Modules

The crypto specific Olm objects.

Types and traits to implement the storage layer for the OlmMachine

Structs

Customize the accept-reply for a verification process

A wrapper that transparently encrypts anything that implements Read as an Matrix attachment.

A wrapper that transparently encrypts anything that implements Read.

Information about the cancellation of a verification request or verification flow.

Struct representing the state of our private cross signing keys, it shows which private cross signing keys we have locally stored.

A device represents a E2EE capable client of an user.

Struct holding all the information that is needed to decrypt an encrypted file.

Settings for an encrypted room.

Customized version of ruma_client_api::r0::keys::get_keys::Request, without any references.

Wrapper for a cross signing key marking it as the master key.

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

Outgoing request type, holds the unique ID of the request and the actual request.

Struct representing a cross signing identity of a user.

A read-only version of a Device.

Struct representing a cross signing identity of our own user.

Struct representing a cross signing identity of a user.

Customized owned request type for sending out room messages.

Short authentication string object.

Customized version of ruma_client_api::r0::to_device::send_event_to_device::Request, using a UUID for the transaction ID.

Request that will publish a cross signing identity.

A read only view over all devices belonging to a user.

Struct representing a cross signing identity of a user.

An object controlling key verification requests.

Enums

Error type for attachment decryption.

Enum over all the incoming responses we need to receive.

Error representing a failure during key export or import.

The local trust state of a device.

Error representing a failure during a group encryption operation.

Error representing a failure during a device to device cryptographic operation.

Enum over the different outgoing requests we can have.

An enum over the different outgoing verification based requests.

Enum over the different user identity types we can have.

Error type describin different errors that happen when we check or create signatures for a Matrix JSON object.

Enum over the different user identity types we can have.

An enum over the different verification types the SDK supports.

Functions

Try to decrypt a reader into a list of exported room keys.

Encrypt the list of exported room keys using the given passphrase.