From 95243003c41f5f499a8f025195db7937a51fdbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Dom=C3=ADnguez?= Date: Fri, 20 Nov 2020 19:46:23 +0100 Subject: [PATCH 1/9] Update ruma --- matrix_sdk/src/client.rs | 13 ++++++------- matrix_sdk_base/src/models/room.rs | 3 ++- matrix_sdk_common/Cargo.toml | 2 +- matrix_sdk_crypto/src/key_request.rs | 6 +++++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index b667e4a3..29f90ba1 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -1402,10 +1402,10 @@ impl Client { sync_settings: SyncSettings<'_>, ) -> Result { let request = assign!(sync_events::Request::new(), { - filter: sync_settings.filter, + filter: sync_settings.filter.as_ref(), since: sync_settings.token.as_deref(), full_state: sync_settings.full_state, - set_presence: PresenceState::Online, + set_presence: &PresenceState::Online, timeout: sync_settings.timeout, }); @@ -1496,13 +1496,11 @@ impl Client { #[instrument(skip(callback))] pub async fn sync_with_callback( &self, - sync_settings: SyncSettings<'_>, + mut sync_settings: SyncSettings<'_>, callback: impl Fn(sync_events::Response) -> C, ) where C: Future, { - let mut sync_settings = sync_settings; - let filter = sync_settings.filter; let mut last_sync_time: Option = None; if sync_settings.token.is_none() { @@ -1510,6 +1508,7 @@ impl Client { } loop { + let filter = sync_settings.filter.clone(); let response = self.sync_once(sync_settings.clone()).await; let response = match response { @@ -1577,8 +1576,8 @@ impl Client { .await .expect("No sync token found after initial sync"), ); - if let Some(f) = filter.as_ref() { - sync_settings = sync_settings.filter(*f); + if let Some(f) = filter { + sync_settings = sync_settings.filter(f); } } } diff --git a/matrix_sdk_base/src/models/room.rs b/matrix_sdk_base/src/models/room.rs index 6892c50a..b4690e37 100644 --- a/matrix_sdk_base/src/models/room.rs +++ b/matrix_sdk_base/src/models/room.rs @@ -934,7 +934,7 @@ impl Room { member.currently_active = *currently_active; member.display_name = displayname.clone(); member.last_active_ago = *last_active_ago; - member.presence = Some(*presence); + member.presence = Some(presence.clone()); member.status_msg = status_msg.clone(); true @@ -1091,6 +1091,7 @@ impl Describe for MembershipState { Self::Join => "is a member of", Self::Knock => "is requesting access to", Self::Leave => "has left", + _ => "unhandled case of MembershipState", } .to_string() } diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 7302ebfc..76ceeff0 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -21,7 +21,7 @@ js_int = "0.1.9" [dependencies.ruma] version = "0.0.1" git = "https://github.com/ruma/ruma" -rev = "50eb700571480d1440e15a387d10f98be8abab59" +rev = "d16fd4b2c1be1b06fd9be99373a3e77d74fadff3" features = ["client-api", "unstable-pre-spec", "unstable-exhaustive-types"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/matrix_sdk_crypto/src/key_request.rs b/matrix_sdk_crypto/src/key_request.rs index 84f4eab2..8cf2472e 100644 --- a/matrix_sdk_crypto/src/key_request.rs +++ b/matrix_sdk_crypto/src/key_request.rs @@ -299,7 +299,7 @@ impl KeyRequestMachine { &self, event: &ToDeviceEvent, ) -> OlmResult<()> { - let key_info = match event.content.action { + let key_info = match &event.content.action { Action::Request => { if let Some(info) = &event.content.body { info @@ -314,6 +314,10 @@ impl KeyRequestMachine { } // We ignore cancellations here since there's nothing to serve. Action::CancelRequest => return Ok(()), + action => { + warn!("Unknown room key request action: {:?}", action); + return Ok(()); + } }; let session = self From 38fec7f2b362d42dc348220b2599f060f0755e48 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 18 Oct 2020 02:01:39 +0200 Subject: [PATCH 2/9] Upgrade ruma --- matrix_sdk/src/client.rs | 8 +++++--- matrix_sdk_common/Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 5b6fc4b5..b667e4a3 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -826,7 +826,7 @@ impl Client { /// let mut client = Client::new(homeserver).unwrap(); /// /// let generic_search_term = Some("matrix-rust-sdk"); - /// let filter = Some(assign!(Filter::new(), { generic_search_term })); + /// let filter = assign!(Filter::new(), { generic_search_term }); /// let request = assign!(PublicRoomsFilterRequest::new(), { filter }); /// /// client.public_rooms_filtered(request).await; @@ -1292,7 +1292,9 @@ impl Client { let mut data = Vec::new(); reader.read_to_end(&mut data)?; - let request = create_content::Request::new(content_type.essence_str(), data); + let request = assign!(create_content::Request::new(data), { + content_type: Some(content_type.essence_str()), + }); self.http_client.upload(request).await } @@ -2325,7 +2327,7 @@ mod test { .create(); let generic_search_term = Some("cheese"); - let filter = Some(assign!(Filter::new(), { generic_search_term })); + let filter = assign!(Filter::new(), { generic_search_term }); let request = assign!(PublicRoomsFilterRequest::new(), { filter }); let get_public_rooms_filtered::Response { chunk, .. } = diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 05aded63..7302ebfc 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -21,7 +21,7 @@ js_int = "0.1.9" [dependencies.ruma] version = "0.0.1" git = "https://github.com/ruma/ruma" -rev = "3869d75837b7aab60eef58fc834e498317d1e4a4" +rev = "50eb700571480d1440e15a387d10f98be8abab59" features = ["client-api", "unstable-pre-spec", "unstable-exhaustive-types"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] From 6509e72a74ae10f2e8012c171f89ad88867baa55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 19 Oct 2020 16:58:26 +0200 Subject: [PATCH 3/9] Revert "base: Don't handle the wildcard case for member events anymore." Using the exhaustive feature in ruma enables the appservice/federation apis, adding some 10 more crates to our dependencies. Disable that feature for now. This reverts commit 41529a6bff38cc8a7cf218bacdf28cc1269a35d4. --- matrix_sdk_base/src/models/room.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/matrix_sdk_base/src/models/room.rs b/matrix_sdk_base/src/models/room.rs index 6892c50a..0b6cb619 100644 --- a/matrix_sdk_base/src/models/room.rs +++ b/matrix_sdk_base/src/models/room.rs @@ -1091,6 +1091,7 @@ impl Describe for MembershipState { Self::Join => "is a member of", Self::Knock => "is requesting access to", Self::Leave => "has left", + _ => "unhandled case of MembershipState", } .to_string() } @@ -1123,6 +1124,7 @@ impl Describe for MembershipChange { Self::None => "did nothing in", Self::NotImplemented => "NOT IMPLEMENTED", Self::Error => "ERROR", + _ => "unhandled case of MembershipChange", } .to_string() } From c40edcf2fce544b157bd75b19285464b0f5f0e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 19 Oct 2020 18:23:48 +0200 Subject: [PATCH 4/9] matrix-sdk: Try to lower our compile times, at least in the crypto part for now. --- matrix_sdk/Cargo.toml | 6 +++--- matrix_sdk_base/Cargo.toml | 6 +++--- matrix_sdk_common/Cargo.toml | 9 +++++---- matrix_sdk_common_macros/Cargo.toml | 2 +- matrix_sdk_crypto/Cargo.toml | 20 +++++++------------ matrix_sdk_crypto/src/error.rs | 13 +++--------- .../src/file_encryption/attachments.rs | 2 +- .../src/file_encryption/key_export.rs | 2 +- matrix_sdk_crypto/src/key_request.rs | 6 ++++-- matrix_sdk_crypto/src/machine.rs | 5 +---- matrix_sdk_crypto/src/olm/account.rs | 4 +--- .../src/olm/group_sessions/outbound.rs | 7 +------ matrix_sdk_crypto/src/olm/session.rs | 2 +- matrix_sdk_crypto/src/olm/utility.rs | 2 +- .../src/verification/sas/sas_state.rs | 5 +++-- matrix_sdk_test/Cargo.toml | 4 ++-- 16 files changed, 38 insertions(+), 57 deletions(-) diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index cc1ba580..76e4283f 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -31,7 +31,7 @@ docs = ["encryption", "sqlite_cryptostore", "messages"] async-trait = "0.1.41" dashmap = { version = "3.11.10", optional = true } http = "0.2.1" -serde_json = "1.0.58" +serde_json = "1.0.59" thiserror = "1.0.21" tracing = "0.1.21" url = "2.1.1" @@ -72,8 +72,8 @@ async-trait = "0.1.41" async-std = { version = "1.6.5", features = ["unstable"] } dirs = "3.0.1" matrix-sdk-test = { version = "0.1.0", path = "../matrix_sdk_test" } -tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } -serde_json = "1.0.58" +tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] } +serde_json = "1.0.59" tracing-subscriber = "0.2.13" tempfile = "3.1.0" mockito = "0.27.0" diff --git a/matrix_sdk_base/Cargo.toml b/matrix_sdk_base/Cargo.toml index 7d8de457..530ca9a3 100644 --- a/matrix_sdk_base/Cargo.toml +++ b/matrix_sdk_base/Cargo.toml @@ -25,8 +25,8 @@ docs = ["encryption", "sqlite_cryptostore", "messages"] [dependencies] async-trait = "0.1.41" -serde = "1.0.116" -serde_json = "1.0.58" +serde = "1.0.117" +serde_json = "1.0.59" zeroize = "1.1.1" tracing = "0.1.21" @@ -51,7 +51,7 @@ tempfile = "3.1.0" mockito = "0.27.0" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] -tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } +tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.18" diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 7302ebfc..3e7556ae 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -22,16 +22,17 @@ js_int = "0.1.9" version = "0.0.1" git = "https://github.com/ruma/ruma" rev = "50eb700571480d1440e15a387d10f98be8abab59" -features = ["client-api", "unstable-pre-spec", "unstable-exhaustive-types"] +default-features = false +features = ["client-api", "unstable-pre-spec", "unstable-synapse-quirks"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -uuid = { version = "0.8.1", features = ["v4", "serde"] } +uuid = { version = "0.8.1", default-features = false, features = ["v4", "serde"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] version = "0.2.22" default-features = false -features = ["sync", "time", "fs"] +features = ["sync"] [target.'cfg(target_arch = "wasm32")'.dependencies] futures-locks = { version = "0.6.0", default-features = false } -uuid = { version = "0.8.1", features = ["v4", "wasm-bindgen"] } +uuid = { version = "0.8.1", default-features = false, features = ["v4", "wasm-bindgen"] } diff --git a/matrix_sdk_common_macros/Cargo.toml b/matrix_sdk_common_macros/Cargo.toml index fab5eea7..d8219ac7 100644 --- a/matrix_sdk_common_macros/Cargo.toml +++ b/matrix_sdk_common_macros/Cargo.toml @@ -14,5 +14,5 @@ version = "0.1.0" proc-macro = true [dependencies] -syn = "1.0.44" +syn = { version = "1.0.45", features = ["proc-macro"], default-features = false } quote = "1.0.7" diff --git a/matrix_sdk_crypto/Cargo.toml b/matrix_sdk_crypto/Cargo.toml index 023c9cb3..6c1ebbee 100644 --- a/matrix_sdk_crypto/Cargo.toml +++ b/matrix_sdk_crypto/Cargo.toml @@ -27,9 +27,8 @@ matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" } olm-rs = { version = "1.0.0", features = ["serde"] } getrandom = "0.2.0" -serde = { version = "1.0.116", features = ["derive", "rc"] } -serde_json = "1.0.58" -cjson = "0.1.1" +serde = { version = "1.0.117", features = ["derive", "rc"] } +serde_json = "1.0.59" zeroize = { version = "1.1.1", features = ["zeroize_derive"] } url = "2.1.1" @@ -39,17 +38,12 @@ tracing = "0.1.21" atomic = "0.5.0" dashmap = "3.11.10" sha2 = "0.9.1" -aes-ctr = "0.5.0" -pbkdf2 = { version = "0.5.0", default-features = false } -hmac = "0.9.0" +aes-ctr = "0.6.0" +pbkdf2 = { version = "0.6.0", default-features = false } +hmac = "0.10.1" base64 = "0.13.0" byteorder = "1.3.4" -[dependencies.tracing-futures] -version = "0.2.4" -default-features = false -features = ["std", "std-future"] - [target.'cfg(not(target_arch = "wasm32"))'.dependencies.sqlx] version = "0.3.5" optional = true @@ -57,10 +51,10 @@ default-features = false features = ["runtime-tokio", "sqlite", "macros"] [dev-dependencies] -tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } +tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] } futures = "0.3.6" proptest = "0.10.1" -serde_json = "1.0.58" +serde_json = "1.0.59" tempfile = "3.1.0" http = "0.2.1" matrix-sdk-test = { version = "0.1.0", path = "../matrix_sdk_test" } diff --git a/matrix_sdk_crypto/src/error.rs b/matrix_sdk_crypto/src/error.rs index ee4e5f1f..c0e1f745 100644 --- a/matrix_sdk_crypto/src/error.rs +++ b/matrix_sdk_crypto/src/error.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use cjson::Error as CjsonError; use matrix_sdk_common::identifiers::{DeviceId, Error as IdentifierError, UserId}; use olm_rs::errors::{OlmGroupSessionError, OlmSessionError}; use serde_json::Error as SerdeError; @@ -145,11 +144,11 @@ pub enum SignatureError { #[error("the provided JSON object doesn't contain a signatures field")] NoSignatureFound, - #[error("the provided JSON object can't be converted to a canonical representation")] - CanonicalJsonError(CjsonError), - #[error("the signature didn't match the provided key")] VerificationError, + + #[error(transparent)] + JsonError(#[from] SerdeError), } #[derive(Error, Debug)] @@ -174,9 +173,3 @@ pub(crate) enum SessionCreationError { #[error("Error creating new Olm session for {0} {1}: {2:?}")] OlmError(UserId, Box, OlmSessionError), } - -impl From for SignatureError { - fn from(error: CjsonError) -> Self { - Self::CanonicalJsonError(error) - } -} diff --git a/matrix_sdk_crypto/src/file_encryption/attachments.rs b/matrix_sdk_crypto/src/file_encryption/attachments.rs index 9fbaa6ff..675e9ed7 100644 --- a/matrix_sdk_crypto/src/file_encryption/attachments.rs +++ b/matrix_sdk_crypto/src/file_encryption/attachments.rs @@ -27,7 +27,7 @@ use matrix_sdk_common::events::room::JsonWebKey; use getrandom::getrandom; use aes_ctr::{ - stream_cipher::{NewStreamCipher, SyncStreamCipher}, + cipher::{NewStreamCipher, SyncStreamCipher}, Aes256Ctr, }; use base64::DecodeError; diff --git a/matrix_sdk_crypto/src/file_encryption/key_export.rs b/matrix_sdk_crypto/src/file_encryption/key_export.rs index dcbdd440..f41d5825 100644 --- a/matrix_sdk_crypto/src/file_encryption/key_export.rs +++ b/matrix_sdk_crypto/src/file_encryption/key_export.rs @@ -20,7 +20,7 @@ use byteorder::{BigEndian, ReadBytesExt}; use getrandom::getrandom; use aes_ctr::{ - stream_cipher::{NewStreamCipher, SyncStreamCipher}, + cipher::{NewStreamCipher, SyncStreamCipher}, Aes256Ctr, }; use hmac::{Hmac, Mac, NewMac}; diff --git a/matrix_sdk_crypto/src/key_request.rs b/matrix_sdk_crypto/src/key_request.rs index 84f4eab2..73ea1a39 100644 --- a/matrix_sdk_crypto/src/key_request.rs +++ b/matrix_sdk_crypto/src/key_request.rs @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize}; use serde_json::value::to_raw_value; use std::{collections::BTreeMap, sync::Arc}; use thiserror::Error; -use tracing::{error, info, instrument, trace, warn}; +use tracing::{error, info, trace, warn}; use matrix_sdk_common::{ api::r0::to_device::DeviceIdOrAllDevices, @@ -294,7 +294,6 @@ impl KeyRequestMachine { } /// Handle a single incoming key request. - #[instrument] async fn handle_key_request( &self, event: &ToDeviceEvent, @@ -314,6 +313,9 @@ impl KeyRequestMachine { } // We ignore cancellations here since there's nothing to serve. Action::CancelRequest => return Ok(()), + // There is no other action defined, but ruma makes all enums + // non-exhaustive. + _ => return Ok(()), }; let session = self diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index cbe0acbf..cf8b8b8d 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -17,7 +17,7 @@ use std::path::Path; use std::{collections::BTreeMap, mem, sync::Arc}; use dashmap::DashMap; -use tracing::{debug, error, info, instrument, trace, warn}; +use tracing::{debug, error, info, trace, warn}; use matrix_sdk_common::{ api::r0::{ @@ -214,7 +214,6 @@ impl OlmMachine { /// /// * `device_id` - The unique id of the device that owns this machine. #[cfg(feature = "sqlite_cryptostore")] - #[instrument(skip(path, passphrase))] #[cfg_attr(feature = "docs", doc(cfg(r#sqlite_cryptostore)))] pub async fn new_with_default_store( user_id: &UserId, @@ -351,7 +350,6 @@ impl OlmMachine { /// /// * `response` - The keys upload response of the request that the client /// performed. - #[instrument] async fn receive_keys_upload_response( &self, response: &upload_keys::Response, @@ -666,7 +664,6 @@ impl OlmMachine { /// * `response` - The sync latest sync response. /// /// [`decrypt_room_event`]: #method.decrypt_room_event - #[instrument(skip(response))] pub async fn receive_sync_response(&self, response: &mut SyncResponse) { self.verification_machine.garbage_collect(); diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index 0cf5e569..c34cbdd7 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -669,9 +669,7 @@ impl ReadOnlyAccount { /// /// Panics if the json value can't be serialized. pub async fn sign_json(&self, json: &Value) -> String { - let canonical_json = cjson::to_string(json) - .unwrap_or_else(|_| panic!(format!("Can't serialize {} to canonical JSON", json))); - self.sign(&canonical_json).await + self.sign(&json.to_string()).await } /// Generate, sign and prepare one-time keys to be uploaded. diff --git a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs index d2daab7e..dce031ed 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs @@ -240,12 +240,7 @@ impl OutboundGroupSession { "type": content.event_type(), }); - let plaintext = cjson::to_string(&json_content).unwrap_or_else(|_| { - panic!(format!( - "Can't serialize {} to canonical JSON", - json_content - )) - }); + let plaintext = json_content.to_string(); let ciphertext = self.encrypt_helper(plaintext).await; diff --git a/matrix_sdk_crypto/src/olm/session.rs b/matrix_sdk_crypto/src/olm/session.rs index 554e75cb..f11cdc51 100644 --- a/matrix_sdk_crypto/src/olm/session.rs +++ b/matrix_sdk_crypto/src/olm/session.rs @@ -126,7 +126,7 @@ impl Session { "content": content, }); - let plaintext = cjson::to_string(&payload) + let plaintext = serde_json::to_string(&payload) .unwrap_or_else(|_| panic!(format!("Can't serialize {} to canonical JSON", payload))); let ciphertext = self.encrypt_helper(&plaintext).await.to_tuple(); diff --git a/matrix_sdk_crypto/src/olm/utility.rs b/matrix_sdk_crypto/src/olm/utility.rs index afa73a6b..5994a453 100644 --- a/matrix_sdk_crypto/src/olm/utility.rs +++ b/matrix_sdk_crypto/src/olm/utility.rs @@ -63,7 +63,7 @@ impl Utility { let unsigned = json_object.remove("unsigned"); let signatures = json_object.remove("signatures"); - let canonical_json = cjson::to_string(json_object)?; + let canonical_json = serde_json::to_string(json_object)?; if let Some(u) = unsigned { json_object.insert("unsigned".to_string(), u); diff --git a/matrix_sdk_crypto/src/verification/sas/sas_state.rs b/matrix_sdk_crypto/src/verification/sas/sas_state.rs index 946e03a4..e934a07f 100644 --- a/matrix_sdk_crypto/src/verification/sas/sas_state.rs +++ b/matrix_sdk_crypto/src/verification/sas/sas_state.rs @@ -351,7 +351,7 @@ impl SasState { let accepted_protocols = AcceptedProtocols::try_from(content.clone()).map_err(|c| self.clone().cancel(c))?; - let json_start_content = cjson::to_string(&self.as_content()) + let json_start_content = serde_json::to_string(&self.as_content()) .expect("Can't deserialize start event content"); Ok(SasState { @@ -396,7 +396,8 @@ impl SasState { let sas = OlmSas::new(); let utility = OlmUtility::new(); - let json_content = cjson::to_string(&event.content).expect("Can't serialize content"); + let json_content = + serde_json::to_string(&event.content).expect("Can't serialize content"); let pubkey = sas.public_key(); let commitment = utility.sha256_utf8_msg(&format!("{}{}", pubkey, json_content)); diff --git a/matrix_sdk_test/Cargo.toml b/matrix_sdk_test/Cargo.toml index 108ad599..28f88398 100644 --- a/matrix_sdk_test/Cargo.toml +++ b/matrix_sdk_test/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/matrix-org/matrix-rust-sdk" version = "0.1.0" [dependencies] -serde_json = "1.0.58" +serde_json = "1.0.59" http = "0.2.1" matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" } matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix_sdk_test_macros" } lazy_static = "1.4.0" -serde = "1.0.116" +serde = "1.0.117" From 591f031246da24a497039a6985eb2e34fc1c9cbc Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 23 Nov 2020 14:58:48 +0100 Subject: [PATCH 5/9] Don't disable default-features on ruma there are no features that are active by default, this is a no-op. --- matrix_sdk_common/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index e39be45f..5ebf345b 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -22,7 +22,6 @@ js_int = "0.1.9" version = "0.0.1" git = "https://github.com/ruma/ruma" rev = "d16fd4b2c1be1b06fd9be99373a3e77d74fadff3" -default-features = false features = ["client-api", "unstable-pre-spec", "unstable-synapse-quirks"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] From 2e387436cfd5aeece780383abbb4831f939b6242 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 23 Nov 2020 15:27:43 +0100 Subject: [PATCH 6/9] Remove unstable-synapse-quirks from default feature set for ruma otherwise there is no point in exposing that feature --- matrix_sdk_common/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 5ebf345b..f551d070 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -22,7 +22,7 @@ js_int = "0.1.9" version = "0.0.1" git = "https://github.com/ruma/ruma" rev = "d16fd4b2c1be1b06fd9be99373a3e77d74fadff3" -features = ["client-api", "unstable-pre-spec", "unstable-synapse-quirks"] +features = ["client-api", "unstable-pre-spec"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] uuid = { version = "0.8.1", default-features = false, features = ["v4", "serde"] } From 5ca66a6985fd079d6154fb769b1b686aefc870ab Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 23 Nov 2020 15:34:38 +0100 Subject: [PATCH 7/9] Upgrade ruma dependency --- matrix_sdk_common/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index f551d070..88cbc7af 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -21,7 +21,7 @@ js_int = "0.1.9" [dependencies.ruma] version = "0.0.1" git = "https://github.com/ruma/ruma" -rev = "d16fd4b2c1be1b06fd9be99373a3e77d74fadff3" +rev = "ee4280cea2f8d24c7f747fd57776fe72d50ce744" features = ["client-api", "unstable-pre-spec"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] From 27ecab85740c3a570fdab0c04d232dc1ba99d04f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 25 Nov 2020 18:50:50 +0100 Subject: [PATCH 8/9] Update ruma --- matrix_sdk/examples/command_bot.rs | 8 ++------ matrix_sdk/src/client.rs | 14 +++----------- matrix_sdk_common/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/matrix_sdk/examples/command_bot.rs b/matrix_sdk/examples/command_bot.rs index 4f2d9fea..8c12fd5a 100644 --- a/matrix_sdk/examples/command_bot.rs +++ b/matrix_sdk/examples/command_bot.rs @@ -38,12 +38,8 @@ impl EventEmitter for CommandBot { }; if msg_body.contains("!party") { - let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text( - TextMessageEventContent { - body: "🎉🎊🥳 let's PARTY!! 🥳🎊🎉".to_string(), - formatted: None, - relates_to: None, - }, + let content = AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain( + "🎉🎊🥳 let's PARTY!! 🥳🎊🎉", )); // we clone here to hold the lock for as little time as possible. let room_id = room.read().await.room_id.clone(); diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 29f90ba1..7d465fd7 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -1945,10 +1945,7 @@ mod test { }, assign, directory::Filter, - events::{ - room::message::{MessageEventContent, TextMessageEventContent}, - AnyMessageEventContent, - }, + events::{room::message::MessageEventContent, AnyMessageEventContent}, identifiers::{event_id, room_id, user_id}, thirdparty, }; @@ -2490,13 +2487,8 @@ mod test { let room_id = room_id!("!testroom:example.org"); - let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text( - TextMessageEventContent { - body: "Hello world".to_owned(), - relates_to: None, - formatted: None, - }, - )); + let content = + AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain("Hello world")); let txn_id = Uuid::new_v4(); let response = client .room_send(&room_id, content, Some(txn_id)) diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 88cbc7af..d348a0d1 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -21,7 +21,7 @@ js_int = "0.1.9" [dependencies.ruma] version = "0.0.1" git = "https://github.com/ruma/ruma" -rev = "ee4280cea2f8d24c7f747fd57776fe72d50ce744" +rev = "48d1c9747561686e1c5627405780f6de01ee17b1" features = ["client-api", "unstable-pre-spec"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] From 0422bae92485b033d4f9b56f2331909653655609 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 25 Nov 2020 18:59:15 +0100 Subject: [PATCH 9/9] Fix clippy lint rc_buffer --- matrix_sdk_crypto/src/identities/device.rs | 8 ++--- matrix_sdk_crypto/src/olm/account.rs | 8 ++--- .../src/olm/group_sessions/inbound.rs | 20 ++++++------- .../src/olm/group_sessions/outbound.rs | 4 +-- matrix_sdk_crypto/src/olm/session.rs | 8 ++--- matrix_sdk_crypto/src/store/sqlite.rs | 6 ++-- matrix_sdk_crypto/src/verification/sas/mod.rs | 12 ++++---- .../src/verification/sas/sas_state.rs | 30 +++++++++---------- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/matrix_sdk_crypto/src/identities/device.rs b/matrix_sdk_crypto/src/identities/device.rs index 73aeb22d..b9e8c8f2 100644 --- a/matrix_sdk_crypto/src/identities/device.rs +++ b/matrix_sdk_crypto/src/identities/device.rs @@ -54,7 +54,7 @@ use crate::{ pub struct ReadOnlyDevice { user_id: Arc, device_id: Arc>, - algorithms: Arc>, + algorithms: Arc<[EventEncryptionAlgorithm]>, keys: Arc>, signatures: Arc>>, display_name: Arc>, @@ -233,7 +233,7 @@ impl ReadOnlyDevice { display_name: Arc::new(display_name), trust_state: Arc::new(Atomic::new(trust_state)), signatures: Arc::new(signatures), - algorithms: Arc::new(algorithms), + algorithms: algorithms.into(), keys: Arc::new(keys), deleted: Arc::new(AtomicBool::new(false)), } @@ -396,7 +396,7 @@ impl ReadOnlyDevice { let display_name = Arc::new(device_keys.unsigned.device_display_name.clone()); - self.algorithms = Arc::new(device_keys.algorithms.clone()); + self.algorithms = device_keys.algorithms.as_slice().into(); self.keys = Arc::new(device_keys.keys.clone()); self.signatures = Arc::new(device_keys.signatures.clone()); self.display_name = display_name; @@ -467,7 +467,7 @@ impl TryFrom<&DeviceKeys> for ReadOnlyDevice { let device = Self { user_id: Arc::new(device_keys.user_id.clone()), device_id: Arc::new(device_keys.device_id.clone()), - algorithms: Arc::new(device_keys.algorithms.clone()), + algorithms: device_keys.algorithms.as_slice().into(), signatures: Arc::new(device_keys.signatures.clone()), keys: Arc::new(device_keys.keys.clone()), display_name: Arc::new(device_keys.unsigned.device_display_name.clone()), diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index c34cbdd7..c88b228f 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -746,8 +746,8 @@ impl ReadOnlyAccount { device_id: self.device_id.clone(), our_identity_keys: self.identity_keys.clone(), inner: Arc::new(Mutex::new(session)), - session_id: Arc::new(session_id), - sender_key: Arc::new(their_identity_key.to_owned()), + session_id: session_id.into(), + sender_key: their_identity_key.into(), creation_time: Arc::new(now), last_use_time: Arc::new(now), }) @@ -851,8 +851,8 @@ impl ReadOnlyAccount { device_id: self.device_id.clone(), our_identity_keys: self.identity_keys.clone(), inner: Arc::new(Mutex::new(session)), - session_id: Arc::new(session_id), - sender_key: Arc::new(their_identity_key.to_owned()), + session_id: session_id.into(), + sender_key: their_identity_key.into(), creation_time: Arc::new(now), last_use_time: Arc::new(now), }) diff --git a/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs index 9e8a5c11..a7249563 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs @@ -56,8 +56,8 @@ use crate::error::{EventError, MegolmResult}; #[derive(Clone)] pub struct InboundGroupSession { inner: Arc>, - session_id: Arc, - pub(crate) sender_key: Arc, + session_id: Arc, + pub(crate) sender_key: Arc, pub(crate) signing_key: Arc>, pub(crate) room_id: Arc, forwarding_chains: Arc>>>, @@ -95,8 +95,8 @@ impl InboundGroupSession { Ok(InboundGroupSession { inner: Arc::new(Mutex::new(session)), - session_id: Arc::new(session_id), - sender_key: Arc::new(sender_key.to_owned()), + session_id: session_id.into(), + sender_key: sender_key.to_owned().into(), signing_key: Arc::new(keys), room_id: Arc::new(room_id.clone()), forwarding_chains: Arc::new(Mutex::new(None)), @@ -145,8 +145,8 @@ impl InboundGroupSession { Ok(InboundGroupSession { inner: Arc::new(Mutex::new(session)), - session_id: Arc::new(content.session_id.clone()), - sender_key: Arc::new(content.sender_key.clone()), + session_id: content.session_id.as_str().into(), + sender_key: content.sender_key.as_str().into(), signing_key: Arc::new(sender_claimed_key), room_id: Arc::new(content.room_id.clone()), forwarding_chains: Arc::new(Mutex::new(Some(forwarding_chains))), @@ -225,8 +225,8 @@ impl InboundGroupSession { Ok(InboundGroupSession { inner: Arc::new(Mutex::new(session)), - session_id: Arc::new(session_id), - sender_key: Arc::new(pickle.sender_key), + session_id: session_id.into(), + sender_key: pickle.sender_key.into(), signing_key: Arc::new(pickle.signing_key), room_id: Arc::new(pickle.room_id), forwarding_chains: Arc::new(Mutex::new(pickle.forwarding_chains)), @@ -377,8 +377,8 @@ impl TryFrom for InboundGroupSession { Ok(InboundGroupSession { inner: Arc::new(Mutex::new(session)), - session_id: Arc::new(key.session_id), - sender_key: Arc::new(key.sender_key), + session_id: key.session_id.into(), + sender_key: key.sender_key.into(), signing_key: Arc::new(key.sender_claimed_keys), room_id: Arc::new(key.room_id), forwarding_chains: Arc::new(Mutex::new(forwarding_chains)), diff --git a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs index dce031ed..adecc4e1 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs @@ -99,7 +99,7 @@ pub struct OutboundGroupSession { inner: Arc>, device_id: Arc, account_identity_keys: Arc, - session_id: Arc, + session_id: Arc, room_id: Arc, pub(crate) creation_time: Arc, message_count: Arc, @@ -140,7 +140,7 @@ impl OutboundGroupSession { room_id: Arc::new(room_id.to_owned()), device_id, account_identity_keys: identity_keys, - session_id: Arc::new(session_id), + session_id: session_id.into(), creation_time: Arc::new(Instant::now()), message_count: Arc::new(AtomicU64::new(0)), shared: Arc::new(AtomicBool::new(false)), diff --git a/matrix_sdk_crypto/src/olm/session.rs b/matrix_sdk_crypto/src/olm/session.rs index f11cdc51..a68f8230 100644 --- a/matrix_sdk_crypto/src/olm/session.rs +++ b/matrix_sdk_crypto/src/olm/session.rs @@ -46,8 +46,8 @@ pub struct Session { pub(crate) device_id: Arc>, pub(crate) our_identity_keys: Arc, pub(crate) inner: Arc>, - pub(crate) session_id: Arc, - pub(crate) sender_key: Arc, + pub(crate) session_id: Arc, + pub(crate) sender_key: Arc, pub(crate) creation_time: Arc, pub(crate) last_use_time: Arc, } @@ -232,8 +232,8 @@ impl Session { device_id, our_identity_keys, inner: Arc::new(Mutex::new(session)), - session_id: Arc::new(session_id), - sender_key: Arc::new(pickle.sender_key), + session_id: session_id.into(), + sender_key: pickle.sender_key.into(), creation_time: Arc::new(creation_time), last_use_time: Arc::new(last_use_time), }) diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index fe67e2d6..f2497f0a 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -15,7 +15,7 @@ use std::{ collections::{BTreeMap, HashSet}, convert::TryFrom, - path::{Path, PathBuf}, + path::Path, result::Result as StdResult, sync::{Arc, Mutex as SyncMutex}, }; @@ -54,7 +54,7 @@ pub struct SqliteStore { user_id: Arc, device_id: Arc>, account_info: Arc>>, - path: Arc, + path: Arc, sessions: SessionStore, inbound_group_sessions: GroupSessionStore, @@ -153,7 +153,7 @@ impl SqliteStore { sessions: SessionStore::new(), inbound_group_sessions: GroupSessionStore::new(), devices: DeviceStore::new(), - path: Arc::new(path.as_ref().to_owned()), + path: path.as_ref().into(), connection: Arc::new(Mutex::new(connection)), pickle_passphrase: Arc::new(passphrase), tracked_users: Arc::new(DashSet::new()), diff --git a/matrix_sdk_crypto/src/verification/sas/mod.rs b/matrix_sdk_crypto/src/verification/sas/mod.rs index 95d61541..9f823baa 100644 --- a/matrix_sdk_crypto/src/verification/sas/mod.rs +++ b/matrix_sdk_crypto/src/verification/sas/mod.rs @@ -51,7 +51,7 @@ pub struct Sas { account: ReadOnlyAccount, other_device: ReadOnlyDevice, other_identity: Option, - flow_id: Arc, + flow_id: Arc, } impl Sas { @@ -399,11 +399,11 @@ impl Sas { content } - pub(crate) fn verified_devices(&self) -> Option>> { + pub(crate) fn verified_devices(&self) -> Option> { self.inner.lock().unwrap().verified_devices() } - pub(crate) fn verified_identities(&self) -> Option>> { + pub(crate) fn verified_identities(&self) -> Option> { self.inner.lock().unwrap().verified_identities() } @@ -598,7 +598,7 @@ impl InnerSas { } } - fn verification_flow_id(&self) -> Arc { + fn verification_flow_id(&self) -> Arc { match self { InnerSas::Created(s) => s.verification_flow_id.clone(), InnerSas::Started(s) => s.verification_flow_id.clone(), @@ -627,7 +627,7 @@ impl InnerSas { } } - fn verified_devices(&self) -> Option>> { + fn verified_devices(&self) -> Option> { if let InnerSas::Done(s) = self { Some(s.verified_devices()) } else { @@ -635,7 +635,7 @@ impl InnerSas { } } - fn verified_identities(&self) -> Option>> { + fn verified_identities(&self) -> Option> { if let InnerSas::Done(s) = self { Some(s.verified_identities()) } else { diff --git a/matrix_sdk_crypto/src/verification/sas/sas_state.rs b/matrix_sdk_crypto/src/verification/sas/sas_state.rs index e934a07f..9c0ba30a 100644 --- a/matrix_sdk_crypto/src/verification/sas/sas_state.rs +++ b/matrix_sdk_crypto/src/verification/sas/sas_state.rs @@ -144,7 +144,7 @@ pub struct SasState { /// /// This will be the transaction id for to-device events and the relates_to /// field for in-room events. - pub verification_flow_id: Arc, + pub verification_flow_id: Arc, /// The SAS state we're in. state: Arc, @@ -209,8 +209,8 @@ pub struct Confirmed { pub struct MacReceived { we_started: bool, their_pubkey: String, - verified_devices: Arc>, - verified_master_keys: Arc>, + verified_devices: Arc<[ReadOnlyDevice]>, + verified_master_keys: Arc<[UserIdentities]>, } /// The SAS state indicating that the verification finished successfully. @@ -219,8 +219,8 @@ pub struct MacReceived { /// the master keys in the verified devices list. #[derive(Clone, Debug)] pub struct Done { - verified_devices: Arc>, - verified_master_keys: Arc>, + verified_devices: Arc<[ReadOnlyDevice]>, + verified_master_keys: Arc<[UserIdentities]>, } #[derive(Clone, Debug)] @@ -269,7 +269,7 @@ impl SasState { } fn check_event(&self, sender: &UserId, flow_id: &str) -> Result<(), CancelCode> { - if flow_id != *self.verification_flow_id { + if *flow_id != *self.verification_flow_id { Err(CancelCode::UnknownTransaction) } else if sender != self.ids.other_device.user_id() { Err(CancelCode::UserMismatch) @@ -303,7 +303,7 @@ impl SasState { other_device, other_identity, }, - verification_flow_id: Arc::new(verification_flow_id), + verification_flow_id: verification_flow_id.into(), creation_time: Arc::new(Instant::now()), last_event_time: Arc::new(Instant::now()), @@ -413,7 +413,7 @@ impl SasState { creation_time: Arc::new(Instant::now()), last_event_time: Arc::new(Instant::now()), - verification_flow_id: Arc::new(event.content.transaction_id.clone()), + verification_flow_id: event.content.transaction_id.as_str().into(), state: Arc::new(Started { protocol_definitions: content.clone(), @@ -452,7 +452,7 @@ impl SasState { other_identity, }, - verification_flow_id: Arc::new(event.content.transaction_id.clone()), + verification_flow_id: event.content.transaction_id.as_str().into(), state: Arc::new(Canceled::new(CancelCode::UnknownMethod)), }) } @@ -657,8 +657,8 @@ impl SasState { state: Arc::new(MacReceived { we_started: self.state.we_started, their_pubkey: self.state.their_pubkey.clone(), - verified_devices: Arc::new(devices), - verified_master_keys: Arc::new(master_keys), + verified_devices: devices.into(), + verified_master_keys: master_keys.into(), }), }) } @@ -712,8 +712,8 @@ impl SasState { ids: self.ids, state: Arc::new(Done { - verified_devices: Arc::new(devices), - verified_master_keys: Arc::new(master_keys), + verified_devices: devices.into(), + verified_master_keys: master_keys.into(), }), }) } @@ -792,12 +792,12 @@ impl SasState { } /// Get the list of verified devices. - pub fn verified_devices(&self) -> Arc> { + pub fn verified_devices(&self) -> Arc<[ReadOnlyDevice]> { self.state.verified_devices.clone() } /// Get the list of verified identities. - pub fn verified_identities(&self) -> Arc> { + pub fn verified_identities(&self) -> Arc<[UserIdentities]> { self.state.verified_master_keys.clone() } }