matrix-sdk: Try to lower our compile times, at least in the crypto part for now.

This commit is contained in:
Damir Jelić 2020-10-19 18:23:48 +02:00
parent 6509e72a74
commit c40edcf2fc
16 changed files with 38 additions and 57 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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" }

View file

@ -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<DeviceId>, OlmSessionError),
}
impl From<CjsonError> for SignatureError {
fn from(error: CjsonError) -> Self {
Self::CanonicalJsonError(error)
}
}

View file

@ -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;

View file

@ -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};

View file

@ -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<RoomKeyRequestEventContent>,
@ -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

View file

@ -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();

View file

@ -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.

View file

@ -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;

View file

@ -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();

View file

@ -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);

View file

@ -351,7 +351,7 @@ impl SasState<Created> {
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<Started> {
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));

View file

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