matrix_sdk::encryption::recovery

Struct Recovery

Source
pub struct Recovery { /* private fields */ }
Expand description

The recovery manager for the Client.

Implementations§

Source§

impl Recovery

Source

pub fn state(&self) -> RecoveryState

Get the current RecoveryState for this Client.

Source

pub fn state_stream(&self) -> impl Stream<Item = RecoveryState>

Get a stream of updates to the RecoveryState.

This method will send out the current state as the first update.

§Examples
use futures_util::StreamExt;

let recovery = client.encryption().recovery();

let mut state_stream = recovery.state_stream();

while let Some(update) = state_stream.next().await {
    match update {
        RecoveryState::Enabled => {
            println!("Recovery has been enabled");
        }
        _ => (),
    }
}
Source

pub fn enable(&self) -> Enable<'_>

Enable secret storage and backups.

This method will create a new secret storage key and a new backup if one doesn’t already exist. It will then upload all the locally cached secrets, including the backup recovery key, to the new secret store.

This method will throw an error if a backup already exists on the homeserver but this Client isn’t connected to the existing backup.

§Examples
use futures_util::StreamExt;

let recovery = client.encryption().recovery();

let enable = recovery
    .enable()
    .wait_for_backups_to_upload()
    .with_passphrase("my passphrase");

let mut progress_stream = enable.subscribe_to_progress();

tokio::spawn(async move {
    while let Some(update) = progress_stream.next().await {
        let Ok(update) = update else {
            panic!("Update to the enable progress lagged")
        };

        match update {
            EnableProgress::CreatingBackup => {
                println!("Creating a new backup");
            }
            EnableProgress::CreatingRecoveryKey => {
                println!("Creating a new recovery key");
            }
            EnableProgress::Done { .. } => {
                println!("Recovery has been enabled");
                break;
            }
            _ => (),
        }
    }
});

let recovery_key = enable.await?;
Source

pub async fn enable_backup(&self) -> Result<()>

Create a new backup if one does not exist yet.

This method will throw an error if a backup already exists on the homeserver but this Client isn’t connected to the existing backup.

§Examples
let recovery = client.encryption().recovery();

recovery.enable_backup().await?;

assert_eq!(client.encryption().backups().state(), BackupState::Enabled);
Source

pub async fn disable(&self) -> Result<()>

Disable recovery completely.

This method will do the following steps:

  1. Disable the uploading of room keys to a currently active backup.
  2. Delete the currently active backup.
  3. Set the m.secret_storage.default_key global account data event to an empty JSON content.
  4. Set a global account data event so clients won’t attempt to automatically re-enable a backup.
§Examples
let recovery = client.encryption().recovery();

recovery.disable().await?;

assert_eq!(recovery.state(), RecoveryState::Disabled);
Source

pub fn reset_key(&self) -> Reset<'_>

Reset the recovery key.

This will rotate the secret storage key and re-upload all the secrets to the SecretStore.

§Examples
let recovery = client.encryption().recovery();

let new_recovery_key =
    recovery.reset_key().with_passphrase("my passphrase").await;
Source

pub fn recover_and_reset<'a>(&'a self, old_key: &'a str) -> RecoverAndReset<'a>

Reset the recovery key but first import all the secrets from secret storage.

§Examples
let recovery = client.encryption().recovery();

let new_recovery_key = recovery
    .recover_and_reset("my old passphrase or key")
    .with_passphrase("my new passphrase")
    .await?;
Source

pub async fn reset_identity(&self) -> Result<Option<IdentityResetHandle>>

Completely reset the current user’s crypto identity. This method will go through the following steps:

  1. Disable backing up room keys and delete the active backup
  2. Disable recovery and delete secret storage
  3. Go through the cross-signing key reset flow
  4. Finally, re-enable key backups (only if they were already enabled)

Disclaimer: failures in this flow will potentially leave the user in an inconsistent state but they’re expected to just run the reset flow again as presumably the reason they started it to begin with was that they no longer had access to any of their data.

§Examples
    encryption::recovery, encryption::CrossSigningResetAuthType, ruma::api::client::uiaa,
    Client,
  };
let encryption = client.encryption();
       
if let Some(handle) = encryption.recovery().reset_identity().await? {
    match handle.auth_type() {
        CrossSigningResetAuthType::Uiaa(uiaa) => {
            let password = "1234".to_owned();
            let mut password = uiaa::Password::new(user_id, password);
            password.session = uiaa.session;

            handle.reset(Some(uiaa::AuthData::Password(password))).await?;
        }
        CrossSigningResetAuthType::Oidc(o) => {
            println!(
                "To reset your end-to-end encryption cross-signing identity, \
                you first need to approve it at {}",
                o.approval_url
            );
            handle.reset(None).await?;
        }
    }
}
Source

pub async fn recover(&self, recovery_key: &str) -> Result<()>

Recover all the secrets from the homeserver.

This method is a convenience method around the SecretStore::import_secrets() method, please read the documentation of this method for more information about what happens if you call this method.

In short, this method will turn a newly created Client into a fully end-to-end encryption enabled client.

§Examples
let recovery = client.encryption().recovery();

recovery.recover("my recovery key or passphrase").await;

assert_eq!(recovery.state(), RecoveryState::Enabled);
Source

pub async fn are_we_the_last_man_standing(&self) -> Result<bool>

Is this device the last device the user has?

This method is useful to check if we should recommend to the user that they should enable recovery, typically done before logging out.

If the user does not enable recovery before logging out of their last device, they will not be able to decrypt historic messages once they create a new device.

Trait Implementations§

Source§

impl Debug for Recovery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> AsyncTraitDeps for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,