From e20bdfa2b52cd058672e1bf3e6676397a56d18c7 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 23 Feb 2022 21:33:31 +0100 Subject: [PATCH] cleaning up more cryptocrate --- crates/matrix-sdk-base/src/lib.rs | 9 --------- crates/matrix-sdk-base/src/store/mod.rs | 8 ++------ crates/matrix-sdk-crypto/Cargo.toml | 2 -- crates/matrix-sdk-crypto/src/identities/manager.rs | 4 +--- crates/matrix-sdk-crypto/src/identities/user.rs | 10 ++++------ crates/matrix-sdk-crypto/src/lib.rs | 4 ++-- crates/matrix-sdk-crypto/src/machine.rs | 8 +------- crates/matrix-sdk-crypto/src/olm/account.rs | 6 ++---- .../matrix-sdk-crypto/src/olm/group_sessions/mod.rs | 3 ++- .../src/olm/group_sessions/outbound.rs | 6 ++---- crates/matrix-sdk-crypto/src/olm/mod.rs | 3 ++- crates/matrix-sdk-crypto/src/store/mod.rs | 11 ----------- crates/matrix-sdk/src/config/client.rs | 6 +++--- 13 files changed, 21 insertions(+), 59 deletions(-) diff --git a/crates/matrix-sdk-base/src/lib.rs b/crates/matrix-sdk-base/src/lib.rs index 8a4b9f046..f7ea034a9 100644 --- a/crates/matrix-sdk-base/src/lib.rs +++ b/crates/matrix-sdk-base/src/lib.rs @@ -25,15 +25,6 @@ unused_qualifications )] -#[cfg(all(feature = "sled_state_store", feature = "indexeddb_state_store"))] -compile_error!("sled_state_store and indexeddb_state_store are mutually exclusive and cannot be enabled together"); - -#[cfg(all(feature = "indexeddb_state_store", not(target_arch = "wasm32")))] -compile_error!("indexeddb_state_store only works for wasm32 target"); - -#[cfg(all(feature = "sled_cryptostore", feature = "indexeddb_state_store"))] -compile_error!("sled_cryptostore and indexeddb_state_store are mutually exclusive and cannot be enabled together"); - pub use matrix_sdk_common::*; pub use crate::{ diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index e76d6199a..fa475d0d4 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -13,9 +13,6 @@ // limitations under the License. /// Implementing the state store - -#[cfg(feature = "sled_state_store")] -use std::path::Path; use std::{ collections::{BTreeMap, BTreeSet}, ops::Deref, @@ -58,14 +55,13 @@ use crate::{ pub(crate) mod ambiguity_map; mod memory_store; -#[cfg(not(any(feature = "sled_state_store", feature = "indexeddb_state_store")))] -use self::memory_store::MemoryStore; +pub use self::memory_store::MemoryStore; /// State store specific error type. #[derive(Debug, thiserror::Error)] pub enum StoreError { #[error(transparent)] - /// An error happened in the underlying sled database. + /// An error happened in the underlying database backend. Backend(#[from] anyhow::Error), /// An error happened while serializing or deserializing some data. #[error(transparent)] diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index d71e4aff0..b95c2b386 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -19,7 +19,6 @@ rustdoc-args = ["--cfg", "docsrs"] default = [] qrcode = ["matrix-qrcode"] backups_v1 = [] -sled_cryptostore = [] docsrs = [] indexeddb_cryptostore = [] @@ -87,4 +86,3 @@ pprof = { version = "0.6.2", features = ["flamegraph", "criterion"] } [[bench]] name = "crypto_bench" harness = false -required-features = ["sled_cryptostore"] diff --git a/crates/matrix-sdk-crypto/src/identities/manager.rs b/crates/matrix-sdk-crypto/src/identities/manager.rs index fba50b953..84374bce7 100644 --- a/crates/matrix-sdk-crypto/src/identities/manager.rs +++ b/crates/matrix-sdk-crypto/src/identities/manager.rs @@ -733,15 +733,13 @@ pub(crate) mod test { }; use serde_json::json; + use super::testing::{device_id, other_key_query, other_user_id, own_key_query, user_id}; use crate::{ identities::IdentityManager, olm::{PrivateCrossSigningIdentity, ReadOnlyAccount}, store::{CryptoStore, MemoryStore, Store}, verification::VerificationMachine, }; - use super::testing::{ - user_id, other_user_id, device_id, other_key_query, own_key_query, - }; #[async_test] async fn test_manager_creation() { diff --git a/crates/matrix-sdk-crypto/src/identities/user.rs b/crates/matrix-sdk-crypto/src/identities/user.rs index ce28b861d..457d9614a 100644 --- a/crates/matrix-sdk-crypto/src/identities/user.rs +++ b/crates/matrix-sdk-crypto/src/identities/user.rs @@ -941,10 +941,9 @@ pub(crate) mod testing { use ruma::{api::client::r0::keys::get_keys::Response as KeyQueryResponse, user_id}; use super::{ReadOnlyOwnUserIdentity, ReadOnlyUserIdentity}; - use crate::{ - identities::{ - manager::testing::{other_key_query, own_key_query}, ReadOnlyDevice, - }, + use crate::identities::{ + manager::testing::{other_key_query, own_key_query}, + ReadOnlyDevice, }; fn device(response: &KeyQueryResponse) -> (ReadOnlyDevice, ReadOnlyDevice) { @@ -982,7 +981,6 @@ pub(crate) mod testing { } } - #[cfg(test)] pub(crate) mod test { use std::{convert::TryFrom, sync::Arc}; @@ -991,6 +989,7 @@ pub(crate) mod test { use matrix_sdk_test::async_test; use ruma::{api::client::r0::keys::get_keys::Response as KeyQueryResponse, user_id}; + use super::testing::{get_other_identity, get_own_identity}; use super::{ReadOnlyOwnUserIdentity, ReadOnlyUserIdentities, ReadOnlyUserIdentity}; use crate::{ identities::{ @@ -1001,7 +1000,6 @@ pub(crate) mod test { store::MemoryStore, verification::VerificationMachine, }; - use super::testing::{get_other_identity, get_own_identity}; #[test] fn own_identity_create() { diff --git a/crates/matrix-sdk-crypto/src/lib.rs b/crates/matrix-sdk-crypto/src/lib.rs index 57bef0fc1..8c7813563 100644 --- a/crates/matrix-sdk-crypto/src/lib.rs +++ b/crates/matrix-sdk-crypto/src/lib.rs @@ -84,6 +84,7 @@ pub use file_encryption::{ decrypt_key_export, encrypt_key_export, AttachmentDecryptor, AttachmentEncryptor, DecryptorError, KeyExportError, MediaEncryptionInfo, }; +pub use gossiping::GossipRequest; pub use identities::{ Device, LocalTrust, MasterPubkey, OwnUserIdentity, ReadOnlyDevice, ReadOnlyOwnUserIdentity, ReadOnlyUserIdentities, ReadOnlyUserIdentity, UserDevices, UserIdentities, UserIdentity, @@ -93,12 +94,11 @@ pub use machine::OlmMachine; pub use matrix_qrcode; pub use olm::ReadOnlyAccount; pub use olm::{CrossSigningStatus, EncryptionSettings}; -pub use gossiping::GossipRequest; pub use requests::{ IncomingResponse, KeysBackupRequest, KeysQueryRequest, OutgoingRequest, OutgoingRequests, OutgoingVerificationRequest, RoomMessageRequest, ToDeviceRequest, UploadSigningKeysRequest, }; -pub use store::{CrossSigningKeyExport, CryptoStoreError, SecretInfo, SecretImportError}; +pub use store::{CrossSigningKeyExport, CryptoStoreError, SecretImportError, SecretInfo}; pub use verification::{AcceptSettings, CancelInfo, Emoji, Sas, Verification, VerificationRequest}; #[cfg(feature = "qrcode")] pub use verification::{QrVerification, ScanError}; diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index c0d27cae3..575787623 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(feature = "sled_cryptostore")] -use std::path::Path; use std::{ collections::{BTreeMap, BTreeSet, HashSet}, mem, @@ -54,8 +52,6 @@ use tracing::{debug, error, info, trace, warn}; #[cfg(feature = "backups_v1")] use crate::backups::BackupMachine; -#[cfg(feature = "sled_cryptostore")] -use crate::store::sled::SledStore; use crate::{ error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}, gossiping::GossipMachine, @@ -1559,8 +1555,6 @@ pub(crate) mod testing { pub fn response_from_file(json: &serde_json::Value) -> Response> { Response::builder().status(200).body(json.to_string().as_bytes().to_vec()).unwrap() } - - } #[cfg(test)] @@ -1568,6 +1562,7 @@ pub(crate) mod test { use std::{collections::BTreeMap, convert::TryInto, iter, sync::Arc}; + use super::testing::response_from_file; use matrix_sdk_common::util::milli_seconds_since_unix_epoch; use matrix_sdk_test::{async_test, test_json}; use ruma::{ @@ -1593,7 +1588,6 @@ pub(crate) mod test { uint, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId, }; use serde_json::json; - use super::testing::response_from_file; use crate::{ machine::OlmMachine, diff --git a/crates/matrix-sdk-crypto/src/olm/account.rs b/crates/matrix-sdk-crypto/src/olm/account.rs index 5ddac819c..dceab90aa 100644 --- a/crates/matrix-sdk-crypto/src/olm/account.rs +++ b/crates/matrix-sdk-crypto/src/olm/account.rs @@ -481,7 +481,7 @@ impl Account { pub struct ReadOnlyAccount { /// The user_id this account belongs to pub user_id: Arc, - /// The device_id of this entry + /// The device_id of this entry pub device_id: Arc, inner: Arc>, /// The associated identity keys @@ -868,9 +868,7 @@ impl ReadOnlyAccount { self.sign(&canonical_json.to_string()).await } - pub async fn signed_one_time_keys_helper( - &self, - ) -> BTreeMap, Raw> { + pub async fn signed_one_time_keys_helper(&self) -> BTreeMap, Raw> { let one_time_keys = self.one_time_keys().await; let mut one_time_key_map = BTreeMap::new(); diff --git a/crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs b/crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs index b446a8c46..bd66e1c6d 100644 --- a/crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs +++ b/crates/matrix-sdk-crypto/src/olm/group_sessions/mod.rs @@ -28,7 +28,8 @@ mod outbound; pub use inbound::{InboundGroupSession, InboundGroupSessionPickle, PickledInboundGroupSession}; pub use outbound::{ - OlmOutboundGroupSession, EncryptionSettings, OutboundGroupSession, PickledOutboundGroupSession, ShareInfo, ShareState, + EncryptionSettings, OlmOutboundGroupSession, OutboundGroupSession, PickledOutboundGroupSession, + ShareInfo, ShareState, }; /// The private session key of a group session. diff --git a/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs b/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs index af4ed5ed2..92d70723f 100644 --- a/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs +++ b/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs @@ -27,13 +27,11 @@ use dashmap::DashMap; use matrix_sdk_common::{instant::Instant, locks::Mutex}; pub use olm_rs::{ account::IdentityKeys, - session::{OlmMessage, PreKeyMessage}, outbound_group_session::OlmOutboundGroupSession, + session::{OlmMessage, PreKeyMessage}, utility::OlmUtility, }; -use olm_rs::{ - errors::OlmGroupSessionError, PicklingMode, -}; +use olm_rs::{errors::OlmGroupSessionError, PicklingMode}; use ruma::{ events::{ room::{ diff --git a/crates/matrix-sdk-crypto/src/olm/mod.rs b/crates/matrix-sdk-crypto/src/olm/mod.rs index 9ccaa34a9..f46fe1a79 100644 --- a/crates/matrix-sdk-crypto/src/olm/mod.rs +++ b/crates/matrix-sdk-crypto/src/olm/mod.rs @@ -27,7 +27,8 @@ pub(crate) use account::{Account, OlmDecryptionInfo, SessionType}; pub use account::{AccountPickle, OlmMessageHash, PickledAccount, ReadOnlyAccount}; pub use group_sessions::{ EncryptionSettings, ExportedRoomKey, InboundGroupSession, InboundGroupSessionPickle, - OlmOutboundGroupSession, OutboundGroupSession, PickledInboundGroupSession, PickledOutboundGroupSession, ShareInfo, + OlmOutboundGroupSession, OutboundGroupSession, PickledInboundGroupSession, + PickledOutboundGroupSession, ShareInfo, }; pub use group_sessions::{GroupSessionKey, ShareState}; use matrix_sdk_common::instant::{Duration, Instant}; diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 4ff83c4b2..6dd82499a 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -45,8 +45,6 @@ mod pickle_key; #[macro_use] #[allow(missing_docs)] pub mod integration_tests; -#[cfg(feature = "sled_cryptostore")] -pub(crate) mod sled; use std::{ collections::{HashMap, HashSet}, @@ -73,10 +71,6 @@ use zeroize::Zeroize; #[allow(unused_imports)] pub use olm_rs::{account::IdentityKeys, PicklingMode}; -#[cfg(feature = "indexeddb_cryptostore")] -pub use self::indexeddb::IndexeddbStore; -#[cfg(feature = "sled_cryptostore")] -pub use self::sled::SledStore; use crate::{ error::SessionUnpicklingError, identities::{ @@ -539,11 +533,6 @@ pub enum CryptoStoreError { #[error("can't save/load sessions or group sessions in the store before an account is stored")] AccountUnset, - /// Error in the internal database - #[cfg(feature = "sled_cryptostore")] - #[error(transparent)] - Database(#[from] sled::Error), - /// An IO error occurred. #[error(transparent)] Io(#[from] IoError), diff --git a/crates/matrix-sdk/src/config/client.rs b/crates/matrix-sdk/src/config/client.rs index fab3496dc..840aa1f72 100644 --- a/crates/matrix-sdk/src/config/client.rs +++ b/crates/matrix-sdk/src/config/client.rs @@ -144,10 +144,10 @@ mod store_helpers { #[cfg(not(any(feature = "indexeddb_stores", feature = "sled_state_store")))] mod store_helpers { use super::Result; - use matrix_sdk_base::state::MemoryStore as StateStore; + use matrix_sdk_base::store::MemoryStore as StateStore; /// Open a new in-memory StateStore pub async fn default_store() -> Result> { - Ok(Box::new(StateStore::default())) + Ok(Box::new(StateStore::new())) } /// Alias for `default_store` - in Memory Stores are never named @@ -155,7 +155,7 @@ mod store_helpers { _name: &str, _passphrase: Option<&str>, ) -> Result> { - Ok(Box::new(StateStore::default())) + Ok(Box::new(StateStore::new())) } }