From 90ea0229f225e68c6e4eb8d9ffa60f1c3a94ce3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 19 Aug 2020 11:20:08 +0200 Subject: [PATCH] crypto: Rename TrustState to LocalTrust since. We might still trust the device event if our local trust isn't set, so rename the enum to better reflect that meaning. --- matrix_sdk/src/device.rs | 4 +-- matrix_sdk/src/lib.rs | 2 +- matrix_sdk_base/src/lib.rs | 2 +- matrix_sdk_crypto/src/device.rs | 36 +++++++++---------- matrix_sdk_crypto/src/lib.rs | 2 +- matrix_sdk_crypto/src/store/sqlite.rs | 4 +-- matrix_sdk_crypto/src/verification/sas/mod.rs | 6 ++-- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/matrix_sdk/src/device.rs b/matrix_sdk/src/device.rs index 1ffb51c5..dd4449da 100644 --- a/matrix_sdk/src/device.rs +++ b/matrix_sdk/src/device.rs @@ -15,7 +15,7 @@ use std::{ops::Deref, result::Result as StdResult}; use matrix_sdk_base::{ - CryptoStoreError, Device as BaseDevice, ReadOnlyDevice, TrustState, + CryptoStoreError, Device as BaseDevice, LocalTrust, ReadOnlyDevice, UserDevices as BaseUserDevices, }; use matrix_sdk_common::{ @@ -83,7 +83,7 @@ impl Device { /// * `trust_state` - The new trust state that should be set for the device. pub async fn set_trust_state( &self, - trust_state: TrustState, + trust_state: LocalTrust, ) -> StdResult<(), CryptoStoreError> { self.inner.set_trust_state(trust_state).await } diff --git a/matrix_sdk/src/lib.rs b/matrix_sdk/src/lib.rs index f6e81259..6784df65 100644 --- a/matrix_sdk/src/lib.rs +++ b/matrix_sdk/src/lib.rs @@ -41,7 +41,7 @@ pub use matrix_sdk_base::JsonStore; #[cfg(feature = "encryption")] #[cfg_attr(feature = "docs", doc(cfg(encryption)))] -pub use matrix_sdk_base::TrustState; +pub use matrix_sdk_base::LocalTrust; pub use matrix_sdk_base::{ CustomEvent, Error as BaseError, EventEmitter, Room, RoomState, Session, StateStore, SyncRoom, }; diff --git a/matrix_sdk_base/src/lib.rs b/matrix_sdk_base/src/lib.rs index a49b6906..4bf782ce 100644 --- a/matrix_sdk_base/src/lib.rs +++ b/matrix_sdk_base/src/lib.rs @@ -57,7 +57,7 @@ pub use state::{AllRooms, ClientState}; #[cfg(feature = "encryption")] #[cfg_attr(feature = "docs", doc(cfg(encryption)))] pub use matrix_sdk_crypto::{ - CryptoStoreError, Device, ReadOnlyDevice, Sas, TrustState, UserDevices, + CryptoStoreError, Device, LocalTrust, ReadOnlyDevice, Sas, UserDevices, }; #[cfg(feature = "messages")] diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/device.rs index 6e517279..958510a4 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/device.rs @@ -53,7 +53,7 @@ pub struct ReadOnlyDevice { signatures: Arc>>, display_name: Arc>, deleted: Arc, - trust_state: Arc>, + trust_state: Arc>, } #[derive(Debug, Clone)] @@ -88,7 +88,7 @@ impl Device { /// # Arguments /// /// * `trust_state` - The new trust state that should be set for the device. - pub async fn set_trust_state(&self, trust_state: TrustState) -> StoreResult<()> { + pub async fn set_trust_state(&self, trust_state: LocalTrust) -> StoreResult<()> { self.inner.set_trust_state(trust_state); self.verification_machine .store @@ -134,8 +134,8 @@ impl UserDevices { } #[derive(Debug, Clone, Copy, PartialEq)] -/// The trust state of a device. -pub enum TrustState { +/// The local trust state of a device. +pub enum LocalTrust { /// The device has been verified and is trusted. Verified = 0, /// The device been blacklisted from communicating. @@ -146,14 +146,14 @@ pub enum TrustState { Unset = 3, } -impl From for TrustState { +impl From for LocalTrust { fn from(state: i64) -> Self { match state { - 0 => TrustState::Verified, - 1 => TrustState::BlackListed, - 2 => TrustState::Ignored, - 3 => TrustState::Unset, - _ => TrustState::Unset, + 0 => LocalTrust::Verified, + 1 => LocalTrust::BlackListed, + 2 => LocalTrust::Ignored, + 3 => LocalTrust::Unset, + _ => LocalTrust::Unset, } } } @@ -164,7 +164,7 @@ impl ReadOnlyDevice { user_id: UserId, device_id: Box, display_name: Option, - trust_state: TrustState, + trust_state: LocalTrust, algorithms: Vec, keys: BTreeMap, signatures: BTreeMap>, @@ -213,27 +213,27 @@ impl ReadOnlyDevice { } /// Get the trust state of the device. - pub fn trust_state(&self) -> TrustState { + pub fn trust_state(&self) -> LocalTrust { self.trust_state.load(Ordering::Relaxed) } /// Is the device locally marked as trusted. pub fn is_trusted(&self) -> bool { - self.trust_state() == TrustState::Verified + self.trust_state() == LocalTrust::Verified } /// Is the device locally marked as blacklisted. /// /// Blacklisted devices won't receive any group sessions. pub fn is_blacklisted(&self) -> bool { - self.trust_state() == TrustState::BlackListed + self.trust_state() == LocalTrust::BlackListed } /// 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) { + pub(crate) fn set_trust_state(&self, state: LocalTrust) { self.trust_state.store(state, Ordering::Relaxed) } @@ -339,7 +339,7 @@ impl TryFrom<&DeviceKeys> for ReadOnlyDevice { .flatten(), ), deleted: Arc::new(AtomicBool::new(false)), - trust_state: Arc::new(Atomic::new(TrustState::Unset)), + trust_state: Arc::new(Atomic::new(LocalTrust::Unset)), }; device.verify_device_keys(device_keys)?; @@ -358,7 +358,7 @@ pub(crate) mod test { use serde_json::json; use std::convert::TryFrom; - use crate::device::{ReadOnlyDevice, TrustState}; + use crate::device::{LocalTrust, ReadOnlyDevice}; use matrix_sdk_common::{ encryption::DeviceKeys, identifiers::{user_id, DeviceKeyAlgorithm}, @@ -404,7 +404,7 @@ pub(crate) mod test { assert_eq!(&user_id, device.user_id()); assert_eq!(device_id, device.device_id()); assert_eq!(device.algorithms.len(), 2); - assert_eq!(TrustState::Unset, device.trust_state()); + assert_eq!(LocalTrust::Unset, device.trust_state()); assert_eq!( "Alice's mobile phone", device.display_name().as_ref().unwrap() diff --git a/matrix_sdk_crypto/src/lib.rs b/matrix_sdk_crypto/src/lib.rs index 8c41e88e..21a9b487 100644 --- a/matrix_sdk_crypto/src/lib.rs +++ b/matrix_sdk_crypto/src/lib.rs @@ -37,7 +37,7 @@ mod store; mod user_identity; mod verification; -pub use device::{Device, ReadOnlyDevice, TrustState, UserDevices}; +pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices}; pub use error::{MegolmError, OlmError}; pub use machine::{OlmMachine, OneTimeKeys}; pub use memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore}; diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 218c2ea2..7ea291d0 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -36,7 +36,7 @@ use zeroize::Zeroizing; use super::{CryptoStore, CryptoStoreError, Result}; use crate::{ - device::{ReadOnlyDevice, TrustState}, + device::{LocalTrust, ReadOnlyDevice}, memory_stores::{DeviceStore, GroupSessionStore, ReadOnlyUserDevices, SessionStore}, user_identity::UserIdentities, Account, IdentityKeys, InboundGroupSession, Session, @@ -486,7 +486,7 @@ impl SqliteStore { let device_id = &row.2.to_string(); let display_name = &row.3; - let trust_state = TrustState::from(row.4); + let trust_state = LocalTrust::from(row.4); let algorithm_rows: Vec<(String,)> = query_as("SELECT algorithm FROM algorithms WHERE device_id = ?") diff --git a/matrix_sdk_crypto/src/verification/sas/mod.rs b/matrix_sdk_crypto/src/verification/sas/mod.rs index c3837203..0c92d44e 100644 --- a/matrix_sdk_crypto/src/verification/sas/mod.rs +++ b/matrix_sdk_crypto/src/verification/sas/mod.rs @@ -34,8 +34,8 @@ use matrix_sdk_common::{ }; use crate::{ - user_identity::UserIdentities, Account, CryptoStore, CryptoStoreError, ReadOnlyDevice, - TrustState, + user_identity::UserIdentities, Account, CryptoStore, CryptoStoreError, LocalTrust, + ReadOnlyDevice, }; pub use helpers::content_to_request; @@ -216,7 +216,7 @@ impl Sas { device.device_id() ); - device.set_trust_state(TrustState::Verified); + device.set_trust_state(LocalTrust::Verified); self.store.save_devices(&[device]).await?; Ok(true)