From 70174e1fea07b354ceae455dc2fc432d24214b01 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 11:07:17 +0200 Subject: [PATCH 1/9] Upgrade Ruma to 0.6.0 --- benchmarks/Cargo.toml | 2 +- crates/matrix-crypto-ffi/Cargo.toml | 6 +----- crates/matrix-qrcode/Cargo.toml | 2 +- crates/matrix-sdk-appservice/Cargo.toml | 2 +- crates/matrix-sdk-base/Cargo.toml | 2 +- crates/matrix-sdk-common/Cargo.toml | 2 +- crates/matrix-sdk-crypto/Cargo.toml | 3 +-- crates/matrix-sdk-crypto/src/verification/event_enums.rs | 4 ++-- crates/matrix-sdk-crypto/src/verification/machine.rs | 2 +- crates/matrix-sdk-test/Cargo.toml | 2 +- crates/matrix-sdk/Cargo.toml | 3 +-- 11 files changed, 12 insertions(+), 18 deletions(-) diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index 3f43179ca..ecc66e791 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -12,7 +12,7 @@ criterion = { version = "0.3.5", features = ["async", "async_tokio", "html_repor matrix-sdk-crypto = { path = "../crates/matrix-sdk-crypto" } matrix-sdk-sled = { path = "../crates/matrix-sdk-sled", default-features = false, features = ["crypto-store"] } matrix-sdk-test = { path = "../crates/matrix-sdk-test" } -ruma = { git = "https://github.com/ruma/ruma", rev = "4014e6959" } +ruma = "0.6.0" serde_json = "1.0.79" tempfile = "3.3.0" tokio = { version = "1.17.0", default-features = false, features = ["rt-multi-thread"] } diff --git a/crates/matrix-crypto-ffi/Cargo.toml b/crates/matrix-crypto-ffi/Cargo.toml index 87bcc3e50..4bc2937e5 100644 --- a/crates/matrix-crypto-ffi/Cargo.toml +++ b/crates/matrix-crypto-ffi/Cargo.toml @@ -15,6 +15,7 @@ hmac = "0.12.1" http = "0.2.6" pbkdf2 = "0.11.0" rand = "0.8.5" +ruma = { version = "0.6.0", features = ["client-api-c"] } serde = "1.0.136" serde_json = "1.0.79" sha2 = "0.10.2" @@ -49,11 +50,6 @@ version = "1.17.0" default_features = false features = ["rt-multi-thread"] -[dependencies.ruma] -git = "https://github.com/ruma/ruma" -rev = "4014e6959" -features = ["client-api-c"] - [build-dependencies] uniffi_build = { version = "0.17.0", features = ["builtin-bindgen"] } diff --git a/crates/matrix-qrcode/Cargo.toml b/crates/matrix-qrcode/Cargo.toml index e323a2d15..c39ad1c6a 100644 --- a/crates/matrix-qrcode/Cargo.toml +++ b/crates/matrix-qrcode/Cargo.toml @@ -24,7 +24,7 @@ base64 = "0.13.0" byteorder = "1.4.3" image = { version = "0.23.0", optional = true } qrcode = { version = "0.12.0", default-features = false } -ruma-common = { git = "https://github.com/ruma/ruma", rev = "4014e6959" } +ruma-common = "0.9.0" rqrr = { version = "0.4.0", optional = true } thiserror = "1.0.30" diff --git a/crates/matrix-sdk-appservice/Cargo.toml b/crates/matrix-sdk-appservice/Cargo.toml index 87212f692..e0689387d 100644 --- a/crates/matrix-sdk-appservice/Cargo.toml +++ b/crates/matrix-sdk-appservice/Cargo.toml @@ -29,7 +29,7 @@ http = "0.2.6" matrix-sdk = { version = "0.4", path = "../matrix-sdk", default-features = false, features = ["appservice"] } percent-encoding = "2.1.0" regex = "1.5.5" -ruma = { git = "https://github.com/ruma/ruma", rev = "4014e6959", features = ["client-api-c", "appservice-api-s"] } +ruma = { version = "0.6.0", features = ["client-api-c", "appservice-api-s"] } serde = "1.0.136" serde_json = "1.0.79" serde_yaml = "0.8.23" diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index a799df51b..bdb8e399e 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -36,7 +36,7 @@ matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" } matrix-sdk-crypto = { version = "0.4.0", path = "../matrix-sdk-crypto", optional = true } pbkdf2 = { version = "0.11.0", default-features = false, optional = true } rand = { version = "0.8.5", optional = true } -ruma = { git = "https://github.com/ruma/ruma", rev = "4014e6959", features = ["client-api-c", "signatures"] } +ruma = { version = "0.6.0", features = ["client-api-c", "signatures"] } serde = { version = "1.0.136", features = ["rc"] } serde_json = "1.0.79" sha2 = { version = "0.10.2", optional = true } diff --git a/crates/matrix-sdk-common/Cargo.toml b/crates/matrix-sdk-common/Cargo.toml index 6dc9d037c..9a5f75cb7 100644 --- a/crates/matrix-sdk-common/Cargo.toml +++ b/crates/matrix-sdk-common/Cargo.toml @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [dependencies] async-trait = "0.1.53" -ruma = { git = "https://github.com/ruma/ruma", rev = "4014e6959", features = ["client-api-c"] } +ruma = { version = "0.6.0", features = ["client-api-c"] } serde = "1.0.136" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index 5bf1062d5..942e602ff 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -65,8 +65,7 @@ rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" features = ["js"] [dependencies.ruma] -git = "https://github.com/ruma/ruma" -rev = "4014e6959" +version = "0.6.0" features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] [dev-dependencies] diff --git a/crates/matrix-sdk-crypto/src/verification/event_enums.rs b/crates/matrix-sdk-crypto/src/verification/event_enums.rs index f45fffca2..137b1bdec 100644 --- a/crates/matrix-sdk-crypto/src/verification/event_enums.rs +++ b/crates/matrix-sdk-crypto/src/verification/event_enums.rs @@ -63,11 +63,11 @@ impl AnyEvent<'_> { } } - pub fn timestamp(&self) -> Option<&MilliSecondsSinceUnixEpoch> { + pub fn timestamp(&self) -> Option { match self { AnyEvent::Room(e) => Some(e.origin_server_ts()), AnyEvent::ToDevice(e) => match e { - AnyToDeviceEvent::KeyVerificationRequest(e) => Some(&e.content.timestamp), + AnyToDeviceEvent::KeyVerificationRequest(e) => Some(e.content.timestamp), _ => None, }, } diff --git a/crates/matrix-sdk-crypto/src/verification/machine.rs b/crates/matrix-sdk-crypto/src/verification/machine.rs index e004c898d..d92f41ceb 100644 --- a/crates/matrix-sdk-crypto/src/verification/machine.rs +++ b/crates/matrix-sdk-crypto/src/verification/machine.rs @@ -191,7 +191,7 @@ impl VerificationMachine { self.verifications.get_sas(user_id, flow_id) } - fn is_timestamp_valid(timestamp: &MilliSecondsSinceUnixEpoch) -> bool { + fn is_timestamp_valid(timestamp: MilliSecondsSinceUnixEpoch) -> bool { use ruma::{uint, UInt}; // The event should be ignored if the event is older than 10 minutes diff --git a/crates/matrix-sdk-test/Cargo.toml b/crates/matrix-sdk-test/Cargo.toml index c5bba1d1e..54a3c5c1d 100644 --- a/crates/matrix-sdk-test/Cargo.toml +++ b/crates/matrix-sdk-test/Cargo.toml @@ -18,6 +18,6 @@ appservice = [] http = "0.2.6" matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix-sdk-test-macros" } once_cell = "1.10.0" -ruma = { git = "https://github.com/ruma/ruma", rev = "4014e6959", features = ["client-api-c"] } +ruma = { version = "0.6.0", features = ["client-api-c"] } serde = "1.0.136" serde_json = "1.0.79" diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index 6209da4b6..d6531b1ab 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -102,8 +102,7 @@ version = "0.11.10" default_features = false [dependencies.ruma] -git = "https://github.com/ruma/ruma" -rev = "4014e6959" +version = "0.6.0" features = ["client-api-c", "compat", "rand", "unstable-msc2448"] [dependencies.tokio-stream] From aae8989f99a5ba687048d6c388f38203dd6ba22b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 11:09:14 +0200 Subject: [PATCH 2/9] chore(sdk): Merge local import with file-level imports --- crates/matrix-sdk-crypto/src/verification/machine.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/verification/machine.rs b/crates/matrix-sdk-crypto/src/verification/machine.rs index d92f41ceb..031206f13 100644 --- a/crates/matrix-sdk-crypto/src/verification/machine.rs +++ b/crates/matrix-sdk-crypto/src/verification/machine.rs @@ -25,8 +25,8 @@ use ruma::{ ToDeviceEvent, }, serde::Raw, - DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId, - TransactionId, UserId, + uint, DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId, + TransactionId, UInt, UserId, }; use tracing::{info, trace, warn}; @@ -192,8 +192,6 @@ impl VerificationMachine { } fn is_timestamp_valid(timestamp: MilliSecondsSinceUnixEpoch) -> bool { - use ruma::{uint, UInt}; - // The event should be ignored if the event is older than 10 minutes let old_timestamp_threshold: UInt = uint!(600); // The event should be ignored if the event is 5 minutes or more into the From 097cb99ae556097aed9fd9571dc89bd423b277bb Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 11:27:30 +0200 Subject: [PATCH 3/9] chore: Make target-specific dependency formatting more consistent * Put target-specific dependencies last * Put cfg(wasm) before cfg(not(wasm)) * Use long table names only where lines get too long otherwise --- crates/matrix-sdk-common/Cargo.toml | 9 ++++----- crates/matrix-sdk-crypto/Cargo.toml | 17 +++++++---------- crates/matrix-sdk/Cargo.toml | 20 ++++++-------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/crates/matrix-sdk-common/Cargo.toml b/crates/matrix-sdk-common/Cargo.toml index 9a5f75cb7..70a1b70b3 100644 --- a/crates/matrix-sdk-common/Cargo.toml +++ b/crates/matrix-sdk-common/Cargo.toml @@ -20,13 +20,12 @@ async-trait = "0.1.53" ruma = { version = "0.6.0", features = ["client-api-c"] } serde = "1.0.136" -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -tokio = { version = "1.17.0", default-features = false, features = ["rt", "sync"] } -instant = { version = "0.1.12", features = ["now"] } - - [target.'cfg(target_arch = "wasm32")'.dependencies] async-lock = "2.5.0" instant = { version = "0.1.12", features = ["wasm-bindgen", "inaccurate"] } futures-util = { version = "0.3.21", default-features = false, features = ["channel"] } wasm-bindgen-futures = "0.4.30" + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tokio = { version = "1.17.0", default-features = false, features = ["rt", "sync"] } +instant = { version = "0.1.12", features = ["now"] } diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index 942e602ff..5030fb250 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -51,22 +51,18 @@ anyhow = "1.0.57" # feature = testing only http = { version = "0.2.6", optional = true } -[target.'cfg(not(target_arch = "wasm32"))'.dependencies.vodozemac] -git = "https://github.com/matrix-org/vodozemac" -rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" - -[target.'cfg(target_arch = "wasm32")'.dev-dependencies.getrandom] -version = "0.2.6" -features = ["js"] +[dependencies.ruma] +version = "0.6.0" +features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] [target.'cfg(target_arch = "wasm32")'.dependencies.vodozemac] git = "https://github.com/matrix-org/vodozemac" rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" features = ["js"] -[dependencies.ruma] -version = "0.6.0" -features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.vodozemac] +git = "https://github.com/matrix-org/vodozemac" +rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" [dev-dependencies] futures = { version = "0.3.21", default-features = false, features = ["executor"] } @@ -79,4 +75,5 @@ proptest = { version = "1.0.0", default-features = false, features = ["std"] } tokio = { version = "1.7.0", default-features = false, features = ["macros", "rt-multi-thread"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] +getrandom = { version = "0.2.6", features = ["js"] } wasm-bindgen-test = "0.3.24" diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index d6531b1ab..25ef8395b 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -118,14 +118,9 @@ optional = true [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-timer= "0.2.5" -[target.'cfg(not(target_arch = "wasm32"))'.dependencies.backoff] -version = "0.4.0" -features = ["tokio"] - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] -version = "1.17.0" -default-features = false -features = ["fs", "rt"] +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +backoff = { version = "0.4.0", features = ["tokio"] } +tokio = { version = "1.17.0", default-features = false, features = ["fs", "rt"] } [dev-dependencies] anyhow = "1.0.57" @@ -139,16 +134,13 @@ serde_json = "1.0.79" tempfile = "3.3.0" tracing-subscriber = { version = "0.3.11", features = ["env-filter"] } - -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.tokio] -version = "1.17.0" -default-features = false -features = ["rt-multi-thread", "macros"] - [target.'cfg(target_arch = "wasm32")'.dev-dependencies] getrandom = { version = "0.2.6", default-features = false, features = ["js"] } wasm-bindgen-test = "0.3.30" +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +tokio = { version = "1.17.0", default-features = false, features = ["rt-multi-thread", "macros"] } + [[example]] name = "cross_signing_bootstrap" required-features = ["encryption"] From 4b1c77ec5af92bb2c0634ebf637cfd869179e1c9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 12:00:58 +0200 Subject: [PATCH 4/9] chore: Use js `Date.now()` support from Ruma --- benchmarks/Cargo.toml | 2 +- crates/matrix-crypto-ffi/Cargo.toml | 2 +- crates/matrix-sdk-appservice/Cargo.toml | 2 +- crates/matrix-sdk-base/Cargo.toml | 7 ++++- crates/matrix-sdk-base/src/client.rs | 5 ++-- crates/matrix-sdk-common/Cargo.toml | 2 +- crates/matrix-sdk-common/src/lib.rs | 1 - crates/matrix-sdk-common/src/util.rs | 28 ------------------- crates/matrix-sdk-crypto/Cargo.toml | 10 +++++-- crates/matrix-sdk-crypto/src/machine.rs | 7 ++--- crates/matrix-sdk-crypto/src/olm/account.rs | 8 +++--- .../src/olm/group_sessions/outbound.rs | 15 +++++----- crates/matrix-sdk-crypto/src/olm/session.rs | 6 ++-- .../src/session_manager/sessions.rs | 5 ++-- .../src/verification/machine.rs | 6 ++-- .../src/verification/requests.rs | 7 +++-- crates/matrix-sdk-test/Cargo.toml | 2 +- crates/matrix-sdk/Cargo.toml | 2 +- 18 files changed, 48 insertions(+), 69 deletions(-) delete mode 100644 crates/matrix-sdk-common/src/util.rs diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index ecc66e791..f90e6ce67 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -12,7 +12,7 @@ criterion = { version = "0.3.5", features = ["async", "async_tokio", "html_repor matrix-sdk-crypto = { path = "../crates/matrix-sdk-crypto" } matrix-sdk-sled = { path = "../crates/matrix-sdk-sled", default-features = false, features = ["crypto-store"] } matrix-sdk-test = { path = "../crates/matrix-sdk-test" } -ruma = "0.6.0" +ruma = "0.6.1" serde_json = "1.0.79" tempfile = "3.3.0" tokio = { version = "1.17.0", default-features = false, features = ["rt-multi-thread"] } diff --git a/crates/matrix-crypto-ffi/Cargo.toml b/crates/matrix-crypto-ffi/Cargo.toml index 4bc2937e5..c0c0bf415 100644 --- a/crates/matrix-crypto-ffi/Cargo.toml +++ b/crates/matrix-crypto-ffi/Cargo.toml @@ -15,7 +15,7 @@ hmac = "0.12.1" http = "0.2.6" pbkdf2 = "0.11.0" rand = "0.8.5" -ruma = { version = "0.6.0", features = ["client-api-c"] } +ruma = { version = "0.6.1", features = ["client-api-c"] } serde = "1.0.136" serde_json = "1.0.79" sha2 = "0.10.2" diff --git a/crates/matrix-sdk-appservice/Cargo.toml b/crates/matrix-sdk-appservice/Cargo.toml index e0689387d..f5accc4e8 100644 --- a/crates/matrix-sdk-appservice/Cargo.toml +++ b/crates/matrix-sdk-appservice/Cargo.toml @@ -29,7 +29,7 @@ http = "0.2.6" matrix-sdk = { version = "0.4", path = "../matrix-sdk", default-features = false, features = ["appservice"] } percent-encoding = "2.1.0" regex = "1.5.5" -ruma = { version = "0.6.0", features = ["client-api-c", "appservice-api-s"] } +ruma = { version = "0.6.1", features = ["client-api-c", "appservice-api-s"] } serde = "1.0.136" serde_json = "1.0.79" serde_yaml = "0.8.23" diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index bdb8e399e..19abc54fb 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -36,7 +36,6 @@ matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" } matrix-sdk-crypto = { version = "0.4.0", path = "../matrix-sdk-crypto", optional = true } pbkdf2 = { version = "0.11.0", default-features = false, optional = true } rand = { version = "0.8.5", optional = true } -ruma = { version = "0.6.0", features = ["client-api-c", "signatures"] } serde = { version = "1.0.136", features = ["rc"] } serde_json = "1.0.79" sha2 = { version = "0.10.2", optional = true } @@ -46,6 +45,12 @@ zeroize = { version = "1.3.0", features = ["zeroize_derive"] } anyhow = "1.0.57" http = { version = "0.2.6", optional = true } +[target.'cfg(target_arch = "wasm32")'.dependencies] +ruma = { version = "0.6.1", features = ["client-api-c", "js", "signatures"] } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +ruma = { version = "0.6.1", features = ["client-api-c", "signatures"] } + [dev-dependencies] futures = { version = "0.3.21", default-features = false, features = ["executor"] } http = "0.2.6" diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 5246f9460..8fe8318a1 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -31,7 +31,6 @@ use matrix_sdk_common::{ }, instant::Instant, locks::RwLock, - util::milli_seconds_since_unix_epoch, }; #[cfg(feature = "encryption")] use matrix_sdk_crypto::{ @@ -61,7 +60,7 @@ use ruma::{ }, push::{Action, PushConditionRoomCtx, Ruleset}, serde::Raw, - OwnedUserId, RoomId, UInt, UserId, + MilliSecondsSinceUnixEpoch, OwnedUserId, RoomId, UInt, UserId, }; use tracing::{info, trace, warn}; @@ -365,7 +364,7 @@ impl BaseClient { event.event.clone(), false, room_id.to_owned(), - milli_seconds_since_unix_epoch(), + MilliSecondsSinceUnixEpoch::now(), ), ); } diff --git a/crates/matrix-sdk-common/Cargo.toml b/crates/matrix-sdk-common/Cargo.toml index 70a1b70b3..237213ffa 100644 --- a/crates/matrix-sdk-common/Cargo.toml +++ b/crates/matrix-sdk-common/Cargo.toml @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [dependencies] async-trait = "0.1.53" -ruma = { version = "0.6.0", features = ["client-api-c"] } +ruma = { version = "0.6.1", features = ["client-api-c"] } serde = "1.0.136" [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/crates/matrix-sdk-common/src/lib.rs b/crates/matrix-sdk-common/src/lib.rs index 3eea6bd01..f1b36aefc 100644 --- a/crates/matrix-sdk-common/src/lib.rs +++ b/crates/matrix-sdk-common/src/lib.rs @@ -8,7 +8,6 @@ pub use ruma; pub mod deserialized_responses; pub mod executor; pub mod locks; -pub mod util; /// Super trait that is used for our store traits, this trait will differ if /// it's used on WASM. WASM targets will not require `Send` and `Sync` to have diff --git a/crates/matrix-sdk-common/src/util.rs b/crates/matrix-sdk-common/src/util.rs deleted file mode 100644 index c9e1dc142..000000000 --- a/crates/matrix-sdk-common/src/util.rs +++ /dev/null @@ -1,28 +0,0 @@ -use instant::{Duration, SystemTime}; -use ruma::{MilliSecondsSinceUnixEpoch, SecondsSinceUnixEpoch}; - -/// Platform agnostic helper function to create MilliSecondsSinceUnixEpoch -pub fn milli_seconds_since_unix_epoch() -> MilliSecondsSinceUnixEpoch { - let duration = - SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).expect("now is always higher"); - let millis = - duration.as_millis().try_into().expect("can't convert milliseconds since UNIXEPOCH"); - MilliSecondsSinceUnixEpoch(millis) -} - -/// Platform agnostic helper function to create SecondsSinceUnixEpoch -pub fn seconds_since_unix_epoch() -> SecondsSinceUnixEpoch { - modified_seconds_since_unix_epoch(|e| e) -} - -/// Platform agnostic helper function to create SecondsSinceUnixEpoch with -/// modifications -pub fn modified_seconds_since_unix_epoch Duration>( - f: F, -) -> SecondsSinceUnixEpoch { - let duration = - f(SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).expect("now is always higher")); - - let millis = duration.as_secs().try_into().expect("can't convert seconds since UNIXEPOCH"); - SecondsSinceUnixEpoch(millis) -} diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index 5030fb250..f1382bc32 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -51,15 +51,19 @@ anyhow = "1.0.57" # feature = testing only http = { version = "0.2.6", optional = true } -[dependencies.ruma] -version = "0.6.0" -features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] +[target.'cfg(target_arch = "wasm32")'.dependencies.ruma] +version = "0.6.1" +features = ["client-api-c", "js", "rand", "unstable-msc2676", "unstable-msc2677"] [target.'cfg(target_arch = "wasm32")'.dependencies.vodozemac] git = "https://github.com/matrix-org/vodozemac" rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" features = ["js"] +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.ruma] +version = "0.6.1" +features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] + [target.'cfg(not(target_arch = "wasm32"))'.dependencies.vodozemac] git = "https://github.com/matrix-org/vodozemac" rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 8ceda3c3e..f38641d7d 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -1526,10 +1526,8 @@ pub(crate) mod testing { #[cfg(test)] pub(crate) mod tests { - use std::{collections::BTreeMap, convert::TryInto, iter, sync::Arc}; - use matrix_sdk_common::util::milli_seconds_since_unix_epoch; use matrix_sdk_test::{async_test, test_json}; use ruma::{ api::{ @@ -1552,7 +1550,8 @@ pub(crate) mod tests { }, room_id, serde::Raw, - uint, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, OwnedDeviceKeyId, UserId, + uint, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, + OwnedDeviceKeyId, UserId, }; use serde_json::json; use vodozemac::Ed25519PublicKey; @@ -1970,7 +1969,7 @@ pub(crate) mod tests { let event = OriginalSyncMessageLikeEvent { event_id: event_id!("$xxxxx:example.org").to_owned(), - origin_server_ts: milli_seconds_since_unix_epoch(), + origin_server_ts: MilliSecondsSinceUnixEpoch::now(), sender: alice.user_id().to_owned(), content: encrypted_content, unsigned: MessageLikeUnsigned::default(), diff --git a/crates/matrix-sdk-crypto/src/olm/account.rs b/crates/matrix-sdk-crypto/src/olm/account.rs index dd79d594b..50bee4db3 100644 --- a/crates/matrix-sdk-crypto/src/olm/account.rs +++ b/crates/matrix-sdk-crypto/src/olm/account.rs @@ -23,7 +23,7 @@ use std::{ }, }; -use matrix_sdk_common::{locks::Mutex, util::seconds_since_unix_epoch}; +use matrix_sdk_common::locks::Mutex; use ruma::{ api::client::keys::{ upload_keys, @@ -37,7 +37,7 @@ use ruma::{ }, serde::{CanonicalJsonValue, Raw}, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, OwnedDeviceId, - OwnedDeviceKeyId, OwnedUserId, RoomId, UInt, UserId, + OwnedDeviceKeyId, OwnedUserId, RoomId, SecondsSinceUnixEpoch, UInt, UserId, }; use serde::{Deserialize, Serialize}; use serde_json::{value::RawValue as RawJsonValue, Value}; @@ -927,7 +927,7 @@ impl ReadOnlyAccount { ) -> Session { let session = self.inner.lock().await.create_outbound_session(identity_key, one_time_key); - let now = seconds_since_unix_epoch(); + let now = SecondsSinceUnixEpoch::now(); let session_id = session.session_id(); Session { @@ -1023,7 +1023,7 @@ impl ReadOnlyAccount { let result = self.inner.lock().await.create_inbound_session(&their_identity_key, message)?; - let now = seconds_since_unix_epoch(); + let now = SecondsSinceUnixEpoch::now(); let session_id = result.session.session_id(); let session = 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 a7c36539d..b30674a79 100644 --- a/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs +++ b/crates/matrix-sdk-crypto/src/olm/group_sessions/outbound.rs @@ -24,7 +24,7 @@ use std::{ }; use dashmap::DashMap; -use matrix_sdk_common::{locks::Mutex, util::seconds_since_unix_epoch}; +use matrix_sdk_common::locks::Mutex; use ruma::{ events::{ room::{ @@ -175,7 +175,7 @@ impl OutboundGroupSession { device_id, account_identity_keys: identity_keys, session_id: session_id.into(), - creation_time: seconds_since_unix_epoch(), + creation_time: SecondsSinceUnixEpoch::now(), message_count: Arc::new(AtomicU64::new(0)), shared: Arc::new(AtomicBool::new(false)), invalidated: Arc::new(AtomicBool::new(false)), @@ -307,7 +307,7 @@ impl OutboundGroupSession { fn elapsed(&self) -> bool { let creation_time = Duration::from_secs(self.creation_time.get().into()); - let now = Duration::from_secs(seconds_since_unix_epoch().get().into()); + let now = Duration::from_secs(SecondsSinceUnixEpoch::now().get().into()); // Since the encryption settings are provided by users and not // checked someone could set a really low rotation period so @@ -608,7 +608,6 @@ mod tests { use std::time::Duration; use atomic::Ordering; - use matrix_sdk_common::util::modified_seconds_since_unix_epoch; use matrix_sdk_test::async_test; use ruma::{ device_id, @@ -643,6 +642,8 @@ mod tests { #[async_test] #[cfg(any(target_os = "linux", target_arch = "wasm32"))] async fn expiration() -> Result<(), MegolmError> { + use ruma::SecondsSinceUnixEpoch; + let settings = EncryptionSettings { rotation_period_msgs: 1, ..Default::default() }; let account = ReadOnlyAccount::new(user_id!("@alice:example.org"), device_id!("DEVICEID")); @@ -671,9 +672,9 @@ mod tests { .unwrap(); assert!(!session.expired()); - // FIXME: this might break on macosx and windows - session.creation_time = - modified_seconds_since_unix_epoch(|e| e - Duration::from_secs(60 * 60)); + + let now = SecondsSinceUnixEpoch::now(); + session.creation_time = SecondsSinceUnixEpoch(now.get() - uint!(3600)); assert!(session.expired()); let settings = EncryptionSettings { rotation_period_msgs: 0, ..Default::default() }; diff --git a/crates/matrix-sdk-crypto/src/olm/session.rs b/crates/matrix-sdk-crypto/src/olm/session.rs index 9bdfea6ba..e9d2a2a70 100644 --- a/crates/matrix-sdk-crypto/src/olm/session.rs +++ b/crates/matrix-sdk-crypto/src/olm/session.rs @@ -14,7 +14,7 @@ use std::{collections::BTreeMap, fmt, sync::Arc}; -use matrix_sdk_common::{locks::Mutex, util::seconds_since_unix_epoch}; +use matrix_sdk_common::locks::Mutex; use ruma::{ events::{ room::encrypted::{ @@ -83,7 +83,7 @@ impl Session { /// * `message` - The Olm message that should be decrypted. pub async fn decrypt(&mut self, message: &OlmMessage) -> Result { let plaintext = self.inner.lock().await.decrypt(message)?; - self.last_use_time = seconds_since_unix_epoch(); + self.last_use_time = SecondsSinceUnixEpoch::now(); Ok(plaintext) } @@ -101,7 +101,7 @@ impl Session { /// * `plaintext` - The plaintext that should be encrypted. pub(crate) async fn encrypt_helper(&mut self, plaintext: &str) -> OlmMessage { let message = self.inner.lock().await.encrypt(plaintext); - self.last_use_time = seconds_since_unix_epoch(); + self.last_use_time = SecondsSinceUnixEpoch::now(); message } diff --git a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs index 12226e844..060fbeb8f 100644 --- a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs +++ b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs @@ -19,7 +19,6 @@ use std::{ }; use dashmap::{DashMap, DashSet}; -use matrix_sdk_common::util::seconds_since_unix_epoch; use ruma::{ api::client::keys::claim_keys::v3::{ Request as KeysClaimRequest, Response as KeysClaimResponse, @@ -27,7 +26,7 @@ use ruma::{ assign, events::{dummy::ToDeviceDummyEventContent, AnyToDeviceEventContent}, DeviceId, DeviceKeyAlgorithm, EventEncryptionAlgorithm, OwnedDeviceId, OwnedTransactionId, - OwnedUserId, TransactionId, UserId, + OwnedUserId, SecondsSinceUnixEpoch, TransactionId, UserId, }; use tracing::{debug, error, info, warn}; @@ -97,7 +96,7 @@ impl SessionManager { ); let creation_time = Duration::from_secs(session.creation_time.get().into()); - let now = Duration::from_secs(seconds_since_unix_epoch().get().into()); + let now = Duration::from_secs(SecondsSinceUnixEpoch::now().get().into()); let should_unwedge = now .checked_sub(creation_time) diff --git a/crates/matrix-sdk-crypto/src/verification/machine.rs b/crates/matrix-sdk-crypto/src/verification/machine.rs index 031206f13..01abae7fa 100644 --- a/crates/matrix-sdk-crypto/src/verification/machine.rs +++ b/crates/matrix-sdk-crypto/src/verification/machine.rs @@ -18,7 +18,7 @@ use std::{ }; use dashmap::DashMap; -use matrix_sdk_common::{locks::Mutex, util::milli_seconds_since_unix_epoch}; +use matrix_sdk_common::locks::Mutex; use ruma::{ events::{ key::verification::VerificationMethod, AnyToDeviceEvent, AnyToDeviceEventContent, @@ -26,7 +26,7 @@ use ruma::{ }, serde::Raw, uint, DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId, - TransactionId, UInt, UserId, + SecondsSinceUnixEpoch, TransactionId, UInt, UserId, }; use tracing::{info, trace, warn}; @@ -199,7 +199,7 @@ impl VerificationMachine { let timestamp_threshold: UInt = uint!(300); let timestamp = timestamp.as_secs(); - let now = milli_seconds_since_unix_epoch().as_secs(); + let now = SecondsSinceUnixEpoch::now().get(); !(now.saturating_sub(timestamp) > old_timestamp_threshold || timestamp.saturating_sub(now) > timestamp_threshold) diff --git a/crates/matrix-sdk-crypto/src/verification/requests.rs b/crates/matrix-sdk-crypto/src/verification/requests.rs index 15a8f7e98..9582bee3f 100644 --- a/crates/matrix-sdk-crypto/src/verification/requests.rs +++ b/crates/matrix-sdk-crypto/src/verification/requests.rs @@ -19,7 +19,7 @@ use std::{ #[cfg(feature = "qrcode")] use matrix_qrcode::QrVerificationData; -use matrix_sdk_common::{instant::Instant, util::milli_seconds_since_unix_epoch}; +use matrix_sdk_common::instant::Instant; use ruma::{ events::{ key::verification::{ @@ -33,7 +33,8 @@ use ruma::{ AnyMessageLikeEventContent, AnyToDeviceEventContent, }, to_device::DeviceIdOrAllDevices, - DeviceId, OwnedDeviceId, OwnedUserId, RoomId, TransactionId, UserId, + DeviceId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId, TransactionId, + UserId, }; use tracing::{info, trace, warn}; @@ -159,7 +160,7 @@ impl VerificationRequest { self.account.device_id().into(), self.flow_id().as_str().into(), methods, - milli_seconds_since_unix_epoch(), + MilliSecondsSinceUnixEpoch::now(), ); ToDeviceRequest::for_recipients( diff --git a/crates/matrix-sdk-test/Cargo.toml b/crates/matrix-sdk-test/Cargo.toml index 54a3c5c1d..0682c8c94 100644 --- a/crates/matrix-sdk-test/Cargo.toml +++ b/crates/matrix-sdk-test/Cargo.toml @@ -18,6 +18,6 @@ appservice = [] http = "0.2.6" matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix-sdk-test-macros" } once_cell = "1.10.0" -ruma = { version = "0.6.0", features = ["client-api-c"] } +ruma = { version = "0.6.1", features = ["client-api-c"] } serde = "1.0.136" serde_json = "1.0.79" diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index 25ef8395b..450d3b583 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -102,7 +102,7 @@ version = "0.11.10" default_features = false [dependencies.ruma] -version = "0.6.0" +version = "0.6.1" features = ["client-api-c", "compat", "rand", "unstable-msc2448"] [dependencies.tokio-stream] From 82164b098abc314e380cddaebe9e1764269f94d2 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 12:16:23 +0200 Subject: [PATCH 5/9] chore: Sort dependencies Mostly automated (cargo sort --workspace). --- crates/matrix-crypto-ffi/Cargo.toml | 8 ++++---- crates/matrix-qrcode/Cargo.toml | 2 +- crates/matrix-sdk-base/Cargo.toml | 8 ++++---- crates/matrix-sdk-crypto/Cargo.toml | 6 ++---- crates/matrix-sdk-indexeddb/Cargo.toml | 8 +++----- crates/matrix-sdk-sled/Cargo.toml | 12 ++++++------ crates/matrix-sdk/Cargo.toml | 9 ++++----- 7 files changed, 24 insertions(+), 29 deletions(-) diff --git a/crates/matrix-crypto-ffi/Cargo.toml b/crates/matrix-crypto-ffi/Cargo.toml index c0c0bf415..325f79bf3 100644 --- a/crates/matrix-crypto-ffi/Cargo.toml +++ b/crates/matrix-crypto-ffi/Cargo.toml @@ -41,15 +41,15 @@ path = "../matrix-sdk-sled" default_features = false features = ["crypto-store"] -[dependencies.vodozemac] -git = "https://github.com/matrix-org/vodozemac" -rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" - [dependencies.tokio] version = "1.17.0" default_features = false features = ["rt-multi-thread"] +[dependencies.vodozemac] +git = "https://github.com/matrix-org/vodozemac" +rev = "e09c93f2c8df9770793abeec57ed984d5e1f3834" + [build-dependencies] uniffi_build = { version = "0.17.0", features = ["builtin-bindgen"] } diff --git a/crates/matrix-qrcode/Cargo.toml b/crates/matrix-qrcode/Cargo.toml index c39ad1c6a..40df1fbd6 100644 --- a/crates/matrix-qrcode/Cargo.toml +++ b/crates/matrix-qrcode/Cargo.toml @@ -24,8 +24,8 @@ base64 = "0.13.0" byteorder = "1.4.3" image = { version = "0.23.0", optional = true } qrcode = { version = "0.12.0", default-features = false } -ruma-common = "0.9.0" rqrr = { version = "0.4.0", optional = true } +ruma-common = "0.9.0" thiserror = "1.0.30" [dependencies.vodozemac] diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index 19abc54fb..553eb14e1 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -21,16 +21,18 @@ encryption = ["matrix-sdk-crypto"] qrcode = ["matrix-sdk-crypto/qrcode"] # helpers for testing features build upon this -testing = [ "http" ] +testing = ["http"] [dependencies] +anyhow = "1.0.57" async-stream = "0.3.3" chacha20poly1305 = { version = "0.9.0", optional = true } dashmap = "5.2.0" +futures-channel = "0.3.21" futures-core = "0.3.21" futures-util = { version = "0.3.21", default-features = false } -futures-channel = "0.3.21" hmac = { version = "0.12.1", optional = true } +http = { version = "0.2.6", optional = true } lru = "0.7.5" matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" } matrix-sdk-crypto = { version = "0.4.0", path = "../matrix-sdk-crypto", optional = true } @@ -42,8 +44,6 @@ sha2 = { version = "0.10.2", optional = true } thiserror = "1.0.30" tracing = "0.1.34" zeroize = { version = "1.3.0", features = ["zeroize_derive"] } -anyhow = "1.0.57" -http = { version = "0.2.6", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] ruma = { version = "0.6.1", features = ["client-api-c", "js", "signatures"] } diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index f1382bc32..7ac174674 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -27,6 +27,7 @@ testing = ["http"] [dependencies] aes = "0.8.1" aes-gcm = "0.9.4" +anyhow = "1.0.57" atomic = "0.5.1" base64 = "0.13.0" bs58 = { version = "0.4.0", optional = true } @@ -35,6 +36,7 @@ ctr = "0.9.1" dashmap = "5.2.0" futures-util = { version = "0.3.21", default-features = false, features = ["alloc"] } hmac = "0.12.1" +http = { version = "0.2.6", optional = true } # feature = testing only matrix-qrcode = { version = "0.2.0", path = "../matrix-qrcode", optional = true } matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" } olm-rs = { version = "2.2.0", features = ["serde"], optional = true } @@ -46,10 +48,6 @@ sha2 = "0.10.2" thiserror = "1.0.30" tracing = "0.1.34" zeroize = { version = "1.3.0", features = ["zeroize_derive"] } -anyhow = "1.0.57" - -# feature = testing only -http = { version = "0.2.6", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies.ruma] version = "0.6.1" diff --git a/crates/matrix-sdk-indexeddb/Cargo.toml b/crates/matrix-sdk-indexeddb/Cargo.toml index 7cdaca024..48863044e 100644 --- a/crates/matrix-sdk-indexeddb/Cargo.toml +++ b/crates/matrix-sdk-indexeddb/Cargo.toml @@ -17,6 +17,7 @@ dashmap = "5.2.0" futures-util = { version = "0.3.21", default-features = false } indexed_db_futures = "0.2.3" matrix-sdk-base = { path = "../matrix-sdk-base" } +matrix-sdk-crypto = { path = "../matrix-sdk-crypto", optional = true } matrix-sdk-store-encryption = { path = "../matrix-sdk-store-encryption" } serde = "1.0.136" serde_json = "1.0.79" @@ -25,17 +26,14 @@ tracing = "0.1.34" wasm-bindgen = { version = "0.2.80", features = ["serde-serialize"] } web-sys = { version = "0.3.57", features = ["IdbKeyRange"] } -matrix-sdk-crypto = { path = "../matrix-sdk-crypto", optional = true } - - [target.'cfg(target_arch = "wasm32")'.dependencies] # for wasm32 we need to activate this getrandom = { version = "0.2.6", features = ["js"] } [dev-dependencies] -matrix-sdk-base = { path = "../matrix-sdk-base", features = ["testing"] } +matrix-sdk-base = { path = "../matrix-sdk-base", features = ["testing"] } +matrix-sdk-common = { path = "../matrix-sdk-common" } matrix-sdk-crypto = { path = "../matrix-sdk-crypto", features = ["testing"] } matrix-sdk-test = { path = "../matrix-sdk-test" } -matrix-sdk-common = { path = "../matrix-sdk-common" } uuid = "1.0.0" wasm-bindgen-test = "0.3.30" diff --git a/crates/matrix-sdk-sled/Cargo.toml b/crates/matrix-sdk-sled/Cargo.toml index bdbe9539d..6f6b2a279 100644 --- a/crates/matrix-sdk-sled/Cargo.toml +++ b/crates/matrix-sdk-sled/Cargo.toml @@ -10,28 +10,28 @@ state-store = ["matrix-sdk-base"] crypto-store = ["matrix-sdk-crypto"] [dependencies] +anyhow = "1.0.57" +async-stream = "0.3.3" +dashmap = "5.2.0" futures-core = "0.3.21" futures-util = { version = "0.3.21", default-features = false } matrix-sdk-base = { path = "../matrix-sdk-base", optional = true } matrix-sdk-common = { path = "../matrix-sdk-common" } matrix-sdk-crypto = { path = "../matrix-sdk-crypto", optional = true } matrix-sdk-store-encryption = { path = "../matrix-sdk-store-encryption" } -async-stream = "0.3.3" serde = "1.0.136" serde_json = "1.0.79" sled = "0.34.7" thiserror = "1.0.30" tokio = { version = "1.17.0", default-features = false, features = ["sync", "fs"] } tracing = "0.1.34" -anyhow = "1.0.57" -dashmap = "5.2.0" [dev-dependencies] +matrix-sdk-base = { path = "../matrix-sdk-base", features = ["testing"] } +matrix-sdk-crypto = { path = "../matrix-sdk-crypto", features = ["testing"] } +matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" } once_cell = "1.10.0" tempfile = "3.3.0" -matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" } -matrix-sdk-crypto = { path = "../matrix-sdk-crypto", features = ["testing"] } -matrix-sdk-base = { path = "../matrix-sdk-base", features = ["testing"] } tokio = { version = "1.17.0", default-features = false, features = [ "rt-multi-thread", "macros", diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index 450d3b583..431808c41 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -51,6 +51,7 @@ docsrs = [ [dependencies] anyhow = { version = "1.0.57", optional = true } anymap2 = "0.13.0" +async-stream = "0.3.3" bytes = "1.1.0" dashmap = "5.2.0" event-listener = "2.5.2" @@ -59,6 +60,8 @@ futures-core = "0.3.21" futures-util = { version = "0.3.21", default-features = false } http = "0.2.6" matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" } +matrix-sdk-indexeddb = { path = "../matrix-sdk-indexeddb", default-features = false, optional = true } +matrix-sdk-sled = { path = "../matrix-sdk-sled", default-features = false, optional = true } mime = "0.3.16" rand = { version = "0.8.5", optional = true } serde = "1.0.136" @@ -67,10 +70,6 @@ thiserror = "1.0.30" tracing = "0.1.34" url = "2.2.2" zeroize = "1.3.0" -async-stream = "0.3.3" - -matrix-sdk-sled = { path = "../matrix-sdk-sled", default-features = false, optional = true } -matrix-sdk-indexeddb = { path = "../matrix-sdk-indexeddb", default-features = false, optional = true } [dependencies.image] version = "0.24.2" @@ -116,7 +115,7 @@ default-features = false optional = true [target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-timer= "0.2.5" +wasm-timer = "0.2.5" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] backoff = { version = "0.4.0", features = ["tokio"] } From dfd193e3b01de13ce9f9cb3a8cdc75cbe5067901 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 12:17:53 +0200 Subject: [PATCH 6/9] chore: Change TOML inline tables to be single-line consistently --- crates/matrix-sdk-base/Cargo.toml | 5 +---- crates/matrix-sdk-sled/Cargo.toml | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index 553eb14e1..5303eb916 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -55,10 +55,7 @@ ruma = { version = "0.6.1", features = ["client-api-c", "signatures"] } futures = { version = "0.3.21", default-features = false, features = ["executor"] } http = "0.2.6" matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" } -tokio = { version = "1.17.0", default-features = false, features = [ - "rt-multi-thread", - "macros", -] } +tokio = { version = "1.17.0", default-features = false, features = ["rt-multi-thread", "macros"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.30" diff --git a/crates/matrix-sdk-sled/Cargo.toml b/crates/matrix-sdk-sled/Cargo.toml index 6f6b2a279..95e58769b 100644 --- a/crates/matrix-sdk-sled/Cargo.toml +++ b/crates/matrix-sdk-sled/Cargo.toml @@ -32,7 +32,4 @@ matrix-sdk-crypto = { path = "../matrix-sdk-crypto", features = ["testing"] } matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" } once_cell = "1.10.0" tempfile = "3.3.0" -tokio = { version = "1.17.0", default-features = false, features = [ - "rt-multi-thread", - "macros", -] } +tokio = { version = "1.17.0", default-features = false, features = ["rt-multi-thread", "macros"] } From 814e415374ba2a2f49cbd9b48e9e939421e784a5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 12:27:50 +0200 Subject: [PATCH 7/9] chore: Use new Ruma helper methods for some events --- crates/matrix-sdk-base/src/rooms/mod.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/matrix-sdk-base/src/rooms/mod.rs b/crates/matrix-sdk-base/src/rooms/mod.rs index bd2f0e85c..bef5bfd36 100644 --- a/crates/matrix-sdk-base/src/rooms/mod.rs +++ b/crates/matrix-sdk-base/src/rooms/mod.rs @@ -89,10 +89,7 @@ impl BaseRoomInfo { self.create = Some(c.content.clone()); } AnySyncStateEvent::RoomHistoryVisibility(h) => { - self.history_visibility = match h { - SyncStateEvent::Original(h) => h.content.history_visibility.clone(), - SyncStateEvent::Redacted(h) => h.content.history_visibility.clone(), - }; + self.history_visibility = h.history_visibility().clone(); } AnySyncStateEvent::RoomGuestAccess(g) => { self.guest_access = g @@ -100,10 +97,7 @@ impl BaseRoomInfo { .map_or(GuestAccess::Forbidden, |g| g.content.guest_access.clone()); } AnySyncStateEvent::RoomJoinRules(c) => { - self.join_rule = match c { - SyncStateEvent::Original(c) => c.content.join_rule.clone(), - SyncStateEvent::Redacted(c) => c.content.join_rule.clone(), - }; + self.join_rule = c.join_rule().clone(); } AnySyncStateEvent::RoomCanonicalAlias(a) => { self.canonical_alias = a.as_original().and_then(|a| a.content.alias.clone()); From c3d9a60067607b88c2a49c8726c049f62b8aa887 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 12:54:57 +0200 Subject: [PATCH 8/9] chore: Remove async_trait from matrix-sdk-common --- crates/matrix-sdk-base/Cargo.toml | 1 + .../matrix-sdk-base/src/store/memory_store.rs | 3 +- crates/matrix-sdk-base/src/store/mod.rs | 3 +- crates/matrix-sdk-common/Cargo.toml | 1 - crates/matrix-sdk-common/src/lib.rs | 1 - crates/matrix-sdk-crypto/Cargo.toml | 1 + .../src/store/memorystore.rs | 3 +- crates/matrix-sdk-crypto/src/store/mod.rs | 3 +- crates/matrix-sdk-indexeddb/Cargo.toml | 1 + .../matrix-sdk-indexeddb/src/cryptostore.rs | 2 +- .../matrix-sdk-indexeddb/src/state_store.rs | 2 +- crates/matrix-sdk-sled/Cargo.toml | 1 + crates/matrix-sdk-sled/src/cryptostore.rs | 2 +- crates/matrix-sdk-sled/src/state_store.rs | 32 +++++++++---------- crates/matrix-sdk/Cargo.toml | 1 + crates/matrix-sdk/src/http_client.rs | 3 +- crates/matrix-sdk/src/lib.rs | 1 + 17 files changed, 34 insertions(+), 27 deletions(-) diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index 5303eb916..9525b9a64 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -26,6 +26,7 @@ testing = ["http"] [dependencies] anyhow = "1.0.57" async-stream = "0.3.3" +async-trait = "0.1.53" chacha20poly1305 = { version = "0.9.0", optional = true } dashmap = "5.2.0" futures-channel = "0.3.21" diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index c2779682c..d37ddb362 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -18,10 +18,11 @@ use std::{ }; use async_stream::stream; +use async_trait::async_trait; use dashmap::{DashMap, DashSet}; use lru::LruCache; #[allow(unused_imports)] -use matrix_sdk_common::{async_trait, instant::Instant, locks::Mutex}; +use matrix_sdk_common::{instant::Instant, locks::Mutex}; use ruma::{ events::{ presence::PresenceEvent, diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index 4ee58d145..b032ccbd2 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -32,8 +32,9 @@ use std::{ #[macro_use] pub mod integration_tests; +use async_trait::async_trait; use dashmap::DashMap; -use matrix_sdk_common::{async_trait, locks::RwLock, AsyncTraitDeps}; +use matrix_sdk_common::{locks::RwLock, AsyncTraitDeps}; #[cfg(feature = "encryption")] use matrix_sdk_crypto::store::CryptoStore; use ruma::{ diff --git a/crates/matrix-sdk-common/Cargo.toml b/crates/matrix-sdk-common/Cargo.toml index 237213ffa..b4885ac34 100644 --- a/crates/matrix-sdk-common/Cargo.toml +++ b/crates/matrix-sdk-common/Cargo.toml @@ -16,7 +16,6 @@ default-target = "x86_64-unknown-linux-gnu" targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"] [dependencies] -async-trait = "0.1.53" ruma = { version = "0.6.1", features = ["client-api-c"] } serde = "1.0.136" diff --git a/crates/matrix-sdk-common/src/lib.rs b/crates/matrix-sdk-common/src/lib.rs index f1b36aefc..abb63caa5 100644 --- a/crates/matrix-sdk-common/src/lib.rs +++ b/crates/matrix-sdk-common/src/lib.rs @@ -1,7 +1,6 @@ #![doc = include_str!("../README.md")] #![warn(missing_debug_implementations)] -pub use async_trait::async_trait; pub use instant; pub use ruma; diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index 7ac174674..3756c701d 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -29,6 +29,7 @@ aes = "0.8.1" aes-gcm = "0.9.4" anyhow = "1.0.57" atomic = "0.5.1" +async-trait = "0.1.53" base64 = "0.13.0" bs58 = { version = "0.4.0", optional = true } byteorder = "1.4.3" diff --git a/crates/matrix-sdk-crypto/src/store/memorystore.rs b/crates/matrix-sdk-crypto/src/store/memorystore.rs index 9631713de..c7cccd588 100644 --- a/crates/matrix-sdk-crypto/src/store/memorystore.rs +++ b/crates/matrix-sdk-crypto/src/store/memorystore.rs @@ -17,8 +17,9 @@ use std::{ sync::Arc, }; +use async_trait::async_trait; use dashmap::{DashMap, DashSet}; -use matrix_sdk_common::{async_trait, locks::Mutex}; +use matrix_sdk_common::locks::Mutex; use ruma::{ DeviceId, OwnedDeviceId, OwnedTransactionId, OwnedUserId, RoomId, TransactionId, UserId, }; diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 2c1d8f9d9..4e0cee7fc 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -54,7 +54,8 @@ use std::{ sync::Arc, }; -use matrix_sdk_common::{async_trait, locks::Mutex, AsyncTraitDeps}; +use async_trait::async_trait; +use matrix_sdk_common::{locks::Mutex, AsyncTraitDeps}; pub use memorystore::MemoryStore; pub use pickle_key::{EncryptedPickleKey, PickleKey}; use ruma::{ diff --git a/crates/matrix-sdk-indexeddb/Cargo.toml b/crates/matrix-sdk-indexeddb/Cargo.toml index 48863044e..fb3a3f2bd 100644 --- a/crates/matrix-sdk-indexeddb/Cargo.toml +++ b/crates/matrix-sdk-indexeddb/Cargo.toml @@ -12,6 +12,7 @@ default-target = "wasm32-unknown-unknown" [dependencies] anyhow = "1.0.57" +async-trait = "0.1.53" base64 = "0.13.0" dashmap = "5.2.0" futures-util = { version = "0.3.21", default-features = false } diff --git a/crates/matrix-sdk-indexeddb/src/cryptostore.rs b/crates/matrix-sdk-indexeddb/src/cryptostore.rs index dc34da5b9..6b13eaeef 100644 --- a/crates/matrix-sdk-indexeddb/src/cryptostore.rs +++ b/crates/matrix-sdk-indexeddb/src/cryptostore.rs @@ -18,10 +18,10 @@ use std::{ }; use anyhow::anyhow; +use async_trait::async_trait; use dashmap::DashSet; use indexed_db_futures::prelude::*; use matrix_sdk_base::{ - async_trait, locks::Mutex, ruma::{DeviceId, OwnedDeviceId, OwnedUserId, RoomId, TransactionId, UserId}, }; diff --git a/crates/matrix-sdk-indexeddb/src/state_store.rs b/crates/matrix-sdk-indexeddb/src/state_store.rs index bdd97b7d0..f57de2c2c 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store.rs @@ -15,10 +15,10 @@ use std::{collections::BTreeSet, sync::Arc}; use anyhow::anyhow; +use async_trait::async_trait; use futures_util::stream; use indexed_db_futures::prelude::*; use matrix_sdk_base::{ - async_trait, deserialized_responses::SyncRoomEvent, media::{MediaRequest, UniqueKey}, ruma::{ diff --git a/crates/matrix-sdk-sled/Cargo.toml b/crates/matrix-sdk-sled/Cargo.toml index 95e58769b..557198567 100644 --- a/crates/matrix-sdk-sled/Cargo.toml +++ b/crates/matrix-sdk-sled/Cargo.toml @@ -12,6 +12,7 @@ crypto-store = ["matrix-sdk-crypto"] [dependencies] anyhow = "1.0.57" async-stream = "0.3.3" +async-trait = "0.1.53" dashmap = "5.2.0" futures-core = "0.3.21" futures-util = { version = "0.3.21", default-features = false } diff --git a/crates/matrix-sdk-sled/src/cryptostore.rs b/crates/matrix-sdk-sled/src/cryptostore.rs index 0372fb91b..9287baab3 100644 --- a/crates/matrix-sdk-sled/src/cryptostore.rs +++ b/crates/matrix-sdk-sled/src/cryptostore.rs @@ -20,9 +20,9 @@ use std::{ }; use anyhow::anyhow; +use async_trait::async_trait; use dashmap::DashSet; use matrix_sdk_common::{ - async_trait, locks::Mutex, ruma::{ events::room_key_request::RequestedKeyInfo, DeviceId, OwnedDeviceId, OwnedUserId, RoomId, diff --git a/crates/matrix-sdk-sled/src/state_store.rs b/crates/matrix-sdk-sled/src/state_store.rs index 34658e56f..39f905ca5 100644 --- a/crates/matrix-sdk-sled/src/state_store.rs +++ b/crates/matrix-sdk-sled/src/state_store.rs @@ -21,6 +21,7 @@ use std::{ use anyhow::anyhow; use async_stream::stream; +use async_trait::async_trait; use futures_core::stream::Stream; use futures_util::stream::{self, StreamExt, TryStreamExt}; use matrix_sdk_base::{ @@ -29,25 +30,22 @@ use matrix_sdk_base::{ store::{BoxStream, Result as StoreResult, StateChanges, StateStore, StoreError}, RoomInfo, }; -use matrix_sdk_common::{ - async_trait, - ruma::{ - events::{ - presence::PresenceEvent, - receipt::Receipt, - room::{ - member::{MembershipState, OriginalSyncRoomMemberEvent, RoomMemberEventContent}, - redaction::SyncRoomRedactionEvent, - }, - AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageLikeEvent, - AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType, - RoomAccountDataEventType, StateEventType, +use matrix_sdk_common::ruma::{ + events::{ + presence::PresenceEvent, + receipt::Receipt, + room::{ + member::{MembershipState, OriginalSyncRoomMemberEvent, RoomMemberEventContent}, + redaction::SyncRoomRedactionEvent, }, - receipt::ReceiptType, - serde::Raw, - signatures::{redact_in_place, CanonicalJsonObject}, - EventId, IdParseError, MxcUri, OwnedEventId, OwnedUserId, RoomId, RoomVersionId, UserId, + AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageLikeEvent, + AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, + StateEventType, }, + receipt::ReceiptType, + serde::Raw, + signatures::{redact_in_place, CanonicalJsonObject}, + EventId, IdParseError, MxcUri, OwnedEventId, OwnedUserId, RoomId, RoomVersionId, UserId, }; use matrix_sdk_store_encryption::{Error as KeyEncryptionError, StoreCipher}; use serde::{Deserialize, Serialize}; diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index 431808c41..7cef3c02c 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -52,6 +52,7 @@ docsrs = [ anyhow = { version = "1.0.57", optional = true } anymap2 = "0.13.0" async-stream = "0.3.3" +async-trait = "0.1.53" bytes = "1.1.0" dashmap = "5.2.0" event-listener = "2.5.2" diff --git a/crates/matrix-sdk/src/http_client.rs b/crates/matrix-sdk/src/http_client.rs index ad3401fd5..9161e76a1 100644 --- a/crates/matrix-sdk/src/http_client.rs +++ b/crates/matrix-sdk/src/http_client.rs @@ -14,9 +14,10 @@ use std::{any::type_name, convert::TryFrom, fmt::Debug, sync::Arc, time::Duration}; +use async_trait::async_trait; use bytes::{Bytes, BytesMut}; use http::Response as HttpResponse; -use matrix_sdk_common::{async_trait, locks::RwLock, AsyncTraitDeps}; +use matrix_sdk_common::{locks::RwLock, AsyncTraitDeps}; use reqwest::Response; use ruma::api::{ error::FromHttpResponseError, AuthScheme, IncomingResponse, MatrixVersion, OutgoingRequest, diff --git a/crates/matrix-sdk/src/lib.rs b/crates/matrix-sdk/src/lib.rs index 051a29606..651786ac4 100644 --- a/crates/matrix-sdk/src/lib.rs +++ b/crates/matrix-sdk/src/lib.rs @@ -29,6 +29,7 @@ compile_error!("'sso-login' cannot be enabled on 'wasm32' arch"); #[cfg(all(feature = "image-rayon", target_arch = "wasm32"))] compile_error!("'image-rayon' cannot be enabled on 'wasm32' arch"); +pub use async_trait::async_trait; pub use bytes; pub use matrix_sdk_base::{ media, Room as BaseRoom, RoomInfo, RoomMember as BaseRoomMember, RoomType, Session, From f8b9ec962602ed38221755b8ffeb7d6061c40d3c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 29 Apr 2022 13:02:51 +0200 Subject: [PATCH 9/9] chore: Remove ruma re-export from matrix-sdk-common The user-facing re-exports in matrix-sdk-base and matrix-sdk remain. --- .../src/store/integration_tests.rs | 2 +- crates/matrix-sdk-common/src/lib.rs | 1 - .../src/store/integration_tests.rs | 2 +- crates/matrix-sdk-indexeddb/Cargo.toml | 1 + .../matrix-sdk-indexeddb/src/cryptostore.rs | 6 ++-- .../matrix-sdk-indexeddb/src/safe_encode.rs | 4 +-- .../matrix-sdk-indexeddb/src/state_store.rs | 34 +++++++++---------- crates/matrix-sdk-sled/Cargo.toml | 1 + crates/matrix-sdk-sled/src/cryptostore.rs | 12 +++---- crates/matrix-sdk-sled/src/encode_key.rs | 4 +-- crates/matrix-sdk-sled/src/state_store.rs | 4 +-- labs/sled-state-inspector/Cargo.toml | 1 + labs/sled-state-inspector/src/main.rs | 6 ++-- 13 files changed, 37 insertions(+), 41 deletions(-) diff --git a/crates/matrix-sdk-base/src/store/integration_tests.rs b/crates/matrix-sdk-base/src/store/integration_tests.rs index 44d5f7d8e..c873f8643 100644 --- a/crates/matrix-sdk-base/src/store/integration_tests.rs +++ b/crates/matrix-sdk-base/src/store/integration_tests.rs @@ -35,7 +35,7 @@ macro_rules! statestore_integration_tests { use futures_util::StreamExt; use matrix_sdk_test::{async_test, test_json}; - use matrix_sdk_common::ruma::{ + use ruma::{ api::{ client::{ media::get_content_thumbnail::v3::Method, diff --git a/crates/matrix-sdk-common/src/lib.rs b/crates/matrix-sdk-common/src/lib.rs index abb63caa5..2d17609eb 100644 --- a/crates/matrix-sdk-common/src/lib.rs +++ b/crates/matrix-sdk-common/src/lib.rs @@ -2,7 +2,6 @@ #![warn(missing_debug_implementations)] pub use instant; -pub use ruma; pub mod deserialized_responses; pub mod executor; diff --git a/crates/matrix-sdk-crypto/src/store/integration_tests.rs b/crates/matrix-sdk-crypto/src/store/integration_tests.rs index 66aef6552..54d00632f 100644 --- a/crates/matrix-sdk-crypto/src/store/integration_tests.rs +++ b/crates/matrix-sdk-crypto/src/store/integration_tests.rs @@ -7,7 +7,7 @@ macro_rules! cryptostore_integration_tests { use super::get_store; use matrix_sdk_test::async_test; - use matrix_sdk_common::ruma::{ + use ruma::{ encryption::SignedKey, events::room_key_request::RequestedKeyInfo, serde::Base64, user_id, TransactionId, DeviceId, EventEncryptionAlgorithm, UserId, room_id, device_id, diff --git a/crates/matrix-sdk-indexeddb/Cargo.toml b/crates/matrix-sdk-indexeddb/Cargo.toml index fb3a3f2bd..18b22bb02 100644 --- a/crates/matrix-sdk-indexeddb/Cargo.toml +++ b/crates/matrix-sdk-indexeddb/Cargo.toml @@ -20,6 +20,7 @@ indexed_db_futures = "0.2.3" matrix-sdk-base = { path = "../matrix-sdk-base" } matrix-sdk-crypto = { path = "../matrix-sdk-crypto", optional = true } matrix-sdk-store-encryption = { path = "../matrix-sdk-store-encryption" } +ruma = "0.6.1" serde = "1.0.136" serde_json = "1.0.79" thiserror = "1.0.30" diff --git a/crates/matrix-sdk-indexeddb/src/cryptostore.rs b/crates/matrix-sdk-indexeddb/src/cryptostore.rs index 6b13eaeef..1e1b6701f 100644 --- a/crates/matrix-sdk-indexeddb/src/cryptostore.rs +++ b/crates/matrix-sdk-indexeddb/src/cryptostore.rs @@ -21,10 +21,7 @@ use anyhow::anyhow; use async_trait::async_trait; use dashmap::DashSet; use indexed_db_futures::prelude::*; -use matrix_sdk_base::{ - locks::Mutex, - ruma::{DeviceId, OwnedDeviceId, OwnedUserId, RoomId, TransactionId, UserId}, -}; +use matrix_sdk_base::locks::Mutex; use matrix_sdk_crypto::{ olm::{ IdentityKeys, InboundGroupSession, OlmMessageHash, OutboundGroupSession, @@ -36,6 +33,7 @@ use matrix_sdk_crypto::{ GossipRequest, ReadOnlyAccount, ReadOnlyDevice, ReadOnlyUserIdentities, SecretInfo, }; use matrix_sdk_store_encryption::StoreCipher; +use ruma::{DeviceId, OwnedDeviceId, OwnedUserId, RoomId, TransactionId, UserId}; use serde::{Deserialize, Serialize}; use wasm_bindgen::JsValue; diff --git a/crates/matrix-sdk-indexeddb/src/safe_encode.rs b/crates/matrix-sdk-indexeddb/src/safe_encode.rs index 442aee576..c6927e707 100644 --- a/crates/matrix-sdk-indexeddb/src/safe_encode.rs +++ b/crates/matrix-sdk-indexeddb/src/safe_encode.rs @@ -1,12 +1,12 @@ #![allow(dead_code)] use base64::{encode_config as base64_encode, STANDARD_NO_PAD}; -use matrix_sdk_base::ruma::{ +use matrix_sdk_store_encryption::StoreCipher; +use ruma::{ events::{GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType}, receipt::ReceiptType, DeviceId, EventId, MxcUri, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, TransactionId, UserId, }; -use matrix_sdk_store_encryption::StoreCipher; use wasm_bindgen::JsValue; use web_sys::IdbKeyRange; diff --git a/crates/matrix-sdk-indexeddb/src/state_store.rs b/crates/matrix-sdk-indexeddb/src/state_store.rs index f57de2c2c..6fad8541c 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store.rs @@ -21,27 +21,27 @@ use indexed_db_futures::prelude::*; use matrix_sdk_base::{ deserialized_responses::SyncRoomEvent, media::{MediaRequest, UniqueKey}, - ruma::{ - events::{ - presence::PresenceEvent, - receipt::Receipt, - room::{ - member::{MembershipState, OriginalSyncRoomMemberEvent, RoomMemberEventContent}, - redaction::SyncRoomRedactionEvent, - }, - AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageLikeEvent, - AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType, - RoomAccountDataEventType, StateEventType, - }, - receipt::ReceiptType, - serde::Raw, - signatures::{redact_in_place, CanonicalJsonObject}, - EventId, MxcUri, OwnedEventId, OwnedUserId, RoomId, RoomVersionId, UserId, - }, store::{BoxStream, Result as StoreResult, StateChanges, StateStore, StoreError}, RoomInfo, }; use matrix_sdk_store_encryption::{Error as EncryptionError, StoreCipher}; +use ruma::{ + events::{ + presence::PresenceEvent, + receipt::Receipt, + room::{ + member::{MembershipState, OriginalSyncRoomMemberEvent, RoomMemberEventContent}, + redaction::SyncRoomRedactionEvent, + }, + AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageLikeEvent, + AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, + StateEventType, + }, + receipt::ReceiptType, + serde::Raw, + signatures::{redact_in_place, CanonicalJsonObject}, + EventId, MxcUri, OwnedEventId, OwnedUserId, RoomId, RoomVersionId, UserId, +}; use serde::{Deserialize, Serialize}; use tracing::{info, warn}; use wasm_bindgen::JsValue; diff --git a/crates/matrix-sdk-sled/Cargo.toml b/crates/matrix-sdk-sled/Cargo.toml index 557198567..96df6361e 100644 --- a/crates/matrix-sdk-sled/Cargo.toml +++ b/crates/matrix-sdk-sled/Cargo.toml @@ -20,6 +20,7 @@ matrix-sdk-base = { path = "../matrix-sdk-base", optional = true } matrix-sdk-common = { path = "../matrix-sdk-common" } matrix-sdk-crypto = { path = "../matrix-sdk-crypto", optional = true } matrix-sdk-store-encryption = { path = "../matrix-sdk-store-encryption" } +ruma = "0.6.1" serde = "1.0.136" serde_json = "1.0.79" sled = "0.34.7" diff --git a/crates/matrix-sdk-sled/src/cryptostore.rs b/crates/matrix-sdk-sled/src/cryptostore.rs index 9287baab3..c6e6d2c64 100644 --- a/crates/matrix-sdk-sled/src/cryptostore.rs +++ b/crates/matrix-sdk-sled/src/cryptostore.rs @@ -22,13 +22,7 @@ use std::{ use anyhow::anyhow; use async_trait::async_trait; use dashmap::DashSet; -use matrix_sdk_common::{ - locks::Mutex, - ruma::{ - events::room_key_request::RequestedKeyInfo, DeviceId, OwnedDeviceId, OwnedUserId, RoomId, - TransactionId, UserId, - }, -}; +use matrix_sdk_common::locks::Mutex; use matrix_sdk_crypto::{ olm::{ IdentityKeys, InboundGroupSession, OutboundGroupSession, PickledInboundGroupSession, @@ -41,6 +35,10 @@ use matrix_sdk_crypto::{ GossipRequest, ReadOnlyAccount, ReadOnlyDevice, ReadOnlyUserIdentities, SecretInfo, }; use matrix_sdk_store_encryption::StoreCipher; +use ruma::{ + events::room_key_request::RequestedKeyInfo, DeviceId, OwnedDeviceId, OwnedUserId, RoomId, + TransactionId, UserId, +}; use serde::{Deserialize, Serialize}; pub use sled::Error; use sled::{ diff --git a/crates/matrix-sdk-sled/src/encode_key.rs b/crates/matrix-sdk-sled/src/encode_key.rs index 0d862bc3d..3b2a85cc3 100644 --- a/crates/matrix-sdk-sled/src/encode_key.rs +++ b/crates/matrix-sdk-sled/src/encode_key.rs @@ -1,6 +1,7 @@ use std::{borrow::Cow, ops::Deref}; -use matrix_sdk_common::ruma::{ +use matrix_sdk_store_encryption::StoreCipher; +use ruma::{ events::{ secret::request::SecretName, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType, @@ -9,7 +10,6 @@ use matrix_sdk_common::ruma::{ DeviceId, EventEncryptionAlgorithm, EventId, MxcUri, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, TransactionId, UserId, }; -use matrix_sdk_store_encryption::StoreCipher; pub const ENCODE_SEPARATOR: u8 = 0xff; diff --git a/crates/matrix-sdk-sled/src/state_store.rs b/crates/matrix-sdk-sled/src/state_store.rs index 39f905ca5..d0f88fc92 100644 --- a/crates/matrix-sdk-sled/src/state_store.rs +++ b/crates/matrix-sdk-sled/src/state_store.rs @@ -30,7 +30,8 @@ use matrix_sdk_base::{ store::{BoxStream, Result as StoreResult, StateChanges, StateStore, StoreError}, RoomInfo, }; -use matrix_sdk_common::ruma::{ +use matrix_sdk_store_encryption::{Error as KeyEncryptionError, StoreCipher}; +use ruma::{ events::{ presence::PresenceEvent, receipt::Receipt, @@ -47,7 +48,6 @@ use matrix_sdk_common::ruma::{ signatures::{redact_in_place, CanonicalJsonObject}, EventId, IdParseError, MxcUri, OwnedEventId, OwnedUserId, RoomId, RoomVersionId, UserId, }; -use matrix_sdk_store_encryption::{Error as KeyEncryptionError, StoreCipher}; use serde::{Deserialize, Serialize}; use sled::{ transaction::{ConflictableTransactionError, TransactionError}, diff --git a/labs/sled-state-inspector/Cargo.toml b/labs/sled-state-inspector/Cargo.toml index 1ebf36d99..70c908f05 100644 --- a/labs/sled-state-inspector/Cargo.toml +++ b/labs/sled-state-inspector/Cargo.toml @@ -10,6 +10,7 @@ clap = "3.1.12" futures = { version = "0.3.21", default-features = false, features = ["executor"] } matrix-sdk-base = { path = "../../crates/matrix-sdk-base" } matrix-sdk-sled = { path = "../../crates/matrix-sdk-sled" } +ruma = "0.6.1" rustyline = "9.1.2" rustyline-derive = "0.6.0" serde = "1.0.136" diff --git a/labs/sled-state-inspector/src/main.rs b/labs/sled-state-inspector/src/main.rs index a737f2095..766afb2ee 100644 --- a/labs/sled-state-inspector/src/main.rs +++ b/labs/sled-state-inspector/src/main.rs @@ -3,11 +3,9 @@ use std::{convert::TryFrom, fmt::Debug, sync::Arc}; use atty::Stream; use clap::{Arg, ArgMatches, Command as Argparse}; use futures::executor::block_on; -use matrix_sdk_base::{ - ruma::{events::StateEventType, OwnedRoomId, OwnedUserId, RoomId}, - RoomInfo, Store, -}; +use matrix_sdk_base::{RoomInfo, Store}; use matrix_sdk_sled::StateStore; +use ruma::{events::StateEventType, OwnedRoomId, OwnedUserId, RoomId}; use rustyline::{ completion::{Completer, Pair}, error::ReadlineError,