From a71c7b2964e1add2fddfe25ce70d3b6381741af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 30 Jul 2020 15:54:56 +0200 Subject: [PATCH] crypto: Add a method to set the verification state of devices. --- matrix_sdk_crypto/src/device.rs | 8 ++++++++ matrix_sdk_crypto/src/store/mod.rs | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/device.rs index 80fced0b..ec93b5bd 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/device.rs @@ -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 diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 95a1f040..a848136d 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -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; + + /// 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 + } }