crypto: Add a method to set the verification state of devices.

master
Damir Jelić 2020-07-30 15:54:56 +02:00
parent 30c07b4e08
commit a71c7b2964
2 changed files with 24 additions and 1 deletions

View File

@ -128,6 +128,14 @@ impl Device {
self.trust_state.load(Ordering::Relaxed)
}
/// Set the trust state of the device to the given state.
///
/// Note: This should only done in the cryptostore where the trust state can
/// be stored.
pub(crate) fn set_trust_state(&self, state: TrustState) {
self.trust_state.store(state, Ordering::Relaxed)
}
/// Get the list of algorithms this device supports.
pub fn algorithms(&self) -> &[Algorithm] {
&self.algorithms

View File

@ -23,7 +23,7 @@ use matrix_sdk_common::locks::Mutex;
use serde_json::Error as SerdeError;
use thiserror::Error;
use super::device::Device;
use super::device::{Device, TrustState};
use super::memory_stores::UserDevices;
use super::olm::{Account, InboundGroupSession, Session};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
@ -188,4 +188,19 @@ pub trait CryptoStore: Debug {
///
/// * `user_id` - The user for which we should get all the devices.
async fn get_user_devices(&self, user_id: &UserId) -> Result<UserDevices>;
/// Set the trust state of the given device.
///
/// # Arguments
///
/// * `device` - The device that should have its trust state changed.
///
/// * `state` - The new state that should be set on the device.
async fn set_device_verification(&self, device: Device, state: TrustState) -> Result<()>
where
Self: Sized,
{
device.set_trust_state(state);
self.save_devices(&[device]).await
}
}