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] 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"