pub struct Recovery { /* private fields */ }
Available on crate feature e2e-encryption only.
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 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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<>
§

fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

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

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

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>).
§

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
§

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

§

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,