Struct matrix_sdk::encryption::recovery::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<'_>

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,

§

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§

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§

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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> SendOutsideWasm for T
where T: Send,

source§

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