pub struct RehydratedDevice { /* private fields */ }
Expand description
A rehydraded device.
This device can now receive to-device events to decrypt and gather room keys which were sent to the dehydrated device.
Implementations§
Source§impl RehydratedDevice
impl RehydratedDevice
Sourcepub async fn receive_events(
&self,
events: Vec<Raw<AnyToDeviceEvent>>,
) -> Result<Vec<RoomKeyInfo>, OlmError>
pub async fn receive_events( &self, events: Vec<Raw<AnyToDeviceEvent>>, ) -> Result<Vec<RoomKeyInfo>, OlmError>
Feed to-device events the device was supposed to receive into the
RehydratedDevice
.
Most to-device events we feed into the RehydratedDevice
will contain
room keys, the rehydrated device will pass these room keys into our
own OlmMachine
which will persist them and make the room keys
available for use using the usual
OlmMachine::decrypt_room_event()
method.
Once the homeserver returns a response without any to-device events, we can safely delete the current dehydrated device and create a new one.
§Examples
async fn get_dehydrated_device() -> Result<dehydrated_device::get_dehydrated_device::unstable::Response> {
todo!("Download the dehydrated device");
}
async fn get_events(
device_id: &DeviceId,
since_token: Option<&str>
) -> Result<dehydrated_device::get_events::unstable::Response> {
todo!("Download the to-device events of the dehydrated device");
}
// Get the cached dehydrated key (got it after verification/recovery)
let pickle_key = machine
.dehydrated_devices().get_dehydrated_device_pickle_key().await?.unwrap();
// Fetch the dehydrated device from the server.
let response = get_dehydrated_device().await?;
let device_id = response.device_id;
// Rehydrate the device.
let rehydrated = machine
.dehydrated_devices()
.rehydrate(&pickle_key, &device_id, response.device_data)
.await?;
let mut since_token = None;
let mut imported_room_keys = 0;
loop {
let response =
get_events(&device_id, since_token).await?;
if response.events.is_empty() {
break;
}
since_token = response.next_batch.as_deref();
imported_room_keys += rehydrated.receive_events(response.events).await?.len();
}
println!("Successfully imported {imported_room_keys} from the dehydrated device.");
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RehydratedDevice
impl !RefUnwindSafe for RehydratedDevice
impl Send for RehydratedDevice
impl Sync for RehydratedDevice
impl Unpin for RehydratedDevice
impl !UnwindSafe for RehydratedDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Consume a handle, getting back the initial
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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