mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-19 06:04:31 -04:00
Merge remote-tracking branch 'upstream/main' into ben-wasm-store
This commit is contained in:
@@ -45,7 +45,7 @@ features = ["client-api-c", "appservice-api-s", "unstable-pre-spec"]
|
||||
matrix-sdk-test = { version = "0.4", path = "../matrix-sdk-test", features = ["appservice"] }
|
||||
mockito = "0.30"
|
||||
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros"] }
|
||||
tracing-subscriber = "0.2"
|
||||
tracing-subscriber = "0.3.7"
|
||||
|
||||
[[example]]
|
||||
name = "appservice_autojoin"
|
||||
|
||||
@@ -38,15 +38,15 @@ chacha20poly1305 = { version = "0.9.0", optional = true }
|
||||
dashmap = "4.0.2"
|
||||
futures-core = "0.3.15"
|
||||
futures-util = { version = "0.3.15", default-features = false }
|
||||
hmac = { version = "0.11.0", optional = true }
|
||||
lru = "0.6.5"
|
||||
hmac = { version = "0.12.0", optional = true }
|
||||
lru = "0.7.2"
|
||||
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.9.0", default-features = false, optional = true }
|
||||
pbkdf2 = { version = "0.10.0", default-features = false, optional = true }
|
||||
rand = { version = "0.8.4", optional = true }
|
||||
serde = { version = "1.0.126", features = ["rc"] }
|
||||
serde_json = "1.0.64"
|
||||
sha2 = { version = "0.9.5", optional = true }
|
||||
sha2 = { version = "0.10.1", optional = true }
|
||||
sled = { version = "0.34.6", optional = true }
|
||||
thiserror = "1.0.25"
|
||||
tracing = "0.1.26"
|
||||
@@ -71,9 +71,9 @@ matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||
atty = "0.2.14"
|
||||
clap = "2.33.3"
|
||||
clap = "3.0.13"
|
||||
rustyline = "9.0.0"
|
||||
rustyline-derive = "0.5.0"
|
||||
rustyline-derive = "0.6.0"
|
||||
syntect = "4.5.0"
|
||||
tokio = { version = "1.7.1", default-features = false, features = [
|
||||
"rt-multi-thread",
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{convert::TryFrom, fmt::Debug, sync::Arc};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use atty::Stream;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use clap::{App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches, SubCommand};
|
||||
use clap::{App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches};
|
||||
use futures::executor::block_on;
|
||||
use matrix_sdk_base::{RoomInfo, Store};
|
||||
use ruma::{events::EventType, RoomId, UserId};
|
||||
@@ -219,30 +219,26 @@ impl Inspector {
|
||||
Self { store, printer }
|
||||
}
|
||||
|
||||
async fn run(&self, matches: ArgMatches<'_>) {
|
||||
async fn run(&self, matches: ArgMatches) {
|
||||
match matches.subcommand() {
|
||||
("get-profiles", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
Some(("get-profiles", args)) => {
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
|
||||
self.get_profiles(room_id).await;
|
||||
}
|
||||
|
||||
("get-members", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
Some(("get-members", args)) => {
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
|
||||
self.get_members(room_id).await;
|
||||
}
|
||||
("list-rooms", _) => self.list_rooms().await,
|
||||
("get-display-names", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
Some(("list-rooms", _)) => self.list_rooms().await,
|
||||
Some(("get-display-names", args)) => {
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let display_name = args.value_of("display-name").unwrap().to_string();
|
||||
self.get_display_name_owners(room_id, display_name).await;
|
||||
}
|
||||
("get-state", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
Some(("get-state", args)) => {
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let event_type = EventType::try_from(args.value_of("event-type").unwrap()).unwrap();
|
||||
self.get_state(room_id, event_type).await;
|
||||
@@ -285,37 +281,33 @@ impl Inspector {
|
||||
);
|
||||
}
|
||||
|
||||
fn subcommands() -> Vec<Argparse<'static, 'static>> {
|
||||
fn subcommands() -> Vec<Argparse<'static>> {
|
||||
vec![
|
||||
SubCommand::with_name("list-rooms"),
|
||||
SubCommand::with_name("get-members").arg(
|
||||
Arg::with_name("room-id").required(true).validator(|r| {
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}),
|
||||
),
|
||||
SubCommand::with_name("get-profiles").arg(
|
||||
Arg::with_name("room-id").required(true).validator(|r| {
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}),
|
||||
),
|
||||
SubCommand::with_name("get-display-names")
|
||||
.arg(Arg::with_name("room-id").required(true).validator(|r| {
|
||||
Argparse::new("list-rooms"),
|
||||
Argparse::new("get-members").arg(Arg::new("room-id").required(true).validator(|r| {
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
})),
|
||||
Argparse::new("get-profiles").arg(Arg::new("room-id").required(true).validator(|r| {
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
})),
|
||||
Argparse::new("get-display-names")
|
||||
.arg(Arg::new("room-id").required(true).validator(|r| {
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}))
|
||||
.arg(Arg::with_name("display-name").required(true)),
|
||||
SubCommand::with_name("get-state")
|
||||
.arg(Arg::with_name("room-id").required(true).validator(|r| {
|
||||
.arg(Arg::new("display-name").required(true)),
|
||||
Argparse::new("get-state")
|
||||
.arg(Arg::new("room-id").required(true).validator(|r| {
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}))
|
||||
.arg(Arg::with_name("event-type").required(true).validator(|e| {
|
||||
.arg(Arg::new("event-type").required(true).validator(|e| {
|
||||
EventType::try_from(e).map(|_| ()).map_err(|_| "Invalid event type".to_string())
|
||||
})),
|
||||
]
|
||||
@@ -323,14 +315,13 @@ impl Inspector {
|
||||
|
||||
async fn parse_and_run(&self, input: &str) {
|
||||
let argparse = Argparse::new("state-inspector")
|
||||
.global_setting(ArgParseSettings::DisableHelpFlags)
|
||||
.global_setting(ArgParseSettings::DisableVersion)
|
||||
.global_setting(ArgParseSettings::VersionlessSubcommands)
|
||||
.global_setting(ArgParseSettings::DisableHelpFlag)
|
||||
.global_setting(ArgParseSettings::DisableVersionFlag)
|
||||
.global_setting(ArgParseSettings::NoBinaryName)
|
||||
.setting(ArgParseSettings::SubcommandRequiredElseHelp)
|
||||
.subcommands(Inspector::subcommands());
|
||||
|
||||
match argparse.get_matches_from_safe(input.split_ascii_whitespace()) {
|
||||
match argparse.try_get_matches_from(input.split_ascii_whitespace()) {
|
||||
Ok(m) => {
|
||||
self.run(m).await;
|
||||
}
|
||||
@@ -344,11 +335,10 @@ impl Inspector {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn main() {
|
||||
let argparse = Argparse::new("state-inspector")
|
||||
.global_setting(ArgParseSettings::DisableVersion)
|
||||
.global_setting(ArgParseSettings::VersionlessSubcommands)
|
||||
.arg(Arg::with_name("database").required(true))
|
||||
.global_setting(ArgParseSettings::DisableVersionFlag)
|
||||
.arg(Arg::new("database").required(true))
|
||||
.arg(
|
||||
Arg::with_name("json")
|
||||
Arg::new("json")
|
||||
.long("json")
|
||||
.help("set the output to raw json instead of Rust structs")
|
||||
.global(true)
|
||||
@@ -358,13 +348,13 @@ fn main() {
|
||||
|
||||
let matches = argparse.get_matches();
|
||||
|
||||
let database_path = matches.args.get("database").expect("No database path");
|
||||
let database_path = matches.value_of("database").expect("No database path");
|
||||
let json = matches.is_present("json");
|
||||
let color = atty::is(Stream::Stdout);
|
||||
|
||||
let inspector = Inspector::new(&database_path.vals[0].to_string_lossy(), json, color);
|
||||
let inspector = Inspector::new(database_path, json, color);
|
||||
|
||||
if matches.subcommand.is_none() {
|
||||
if matches.subcommand().is_none() {
|
||||
let config = Config::builder()
|
||||
.history_ignore_space(true)
|
||||
.completion_type(CompletionType::List)
|
||||
|
||||
@@ -33,15 +33,15 @@ byteorder = "1.4.3"
|
||||
dashmap = "4.0.2"
|
||||
futures-util = { version = "0.3.15", default-features = false, features = ["alloc"] }
|
||||
getrandom = "0.2.3"
|
||||
hmac = "0.11.0"
|
||||
hmac = "0.12.0"
|
||||
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.1", features = ["serde"] }
|
||||
pbkdf2 = { version = "0.9.0", default-features = false }
|
||||
pbkdf2 = { version = "0.10.0", default-features = false }
|
||||
rand = "0.8.4"
|
||||
serde = { version = "1.0.126", features = ["derive", "rc"] }
|
||||
serde_json = "1.0.64"
|
||||
sha2 = "0.9.5"
|
||||
sha2 = "0.10.1"
|
||||
sled = { version = "0.34.6", optional = true }
|
||||
thiserror = "1.0.25"
|
||||
tracing = "0.1.26"
|
||||
@@ -77,8 +77,7 @@ tokio = { version = "1.7.1", default-features = false, features = [
|
||||
lazy_static = "1.4"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dev-dependencies]
|
||||
criterion = { version = "0.3.4", features = ["async", "html_reports"] }
|
||||
pprof = { version = "0.5.0", features = ["flamegraph", "criterion"] }
|
||||
pprof = { version = "0.6.2", features = ["flamegraph", "criterion"] }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.24"
|
||||
|
||||
@@ -20,7 +20,7 @@ use aes::{
|
||||
};
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
use getrandom::getrandom;
|
||||
use hmac::{Hmac, Mac, NewMac};
|
||||
use hmac::{Hmac, Mac};
|
||||
use pbkdf2::pbkdf2;
|
||||
use serde_json::Error as SerdeError;
|
||||
use sha2::{Sha256, Sha512};
|
||||
@@ -220,7 +220,7 @@ fn decrypt_helper(ciphertext: &str, passphrase: &str) -> Result<String, KeyExpor
|
||||
|
||||
let mut hmac = Hmac::<Sha256>::new_from_slice(hmac_key).expect("Can't create an HMAC object");
|
||||
hmac.update(&decoded[0..ciphertext_end]);
|
||||
hmac.verify(&mac).map_err(|_| KeyExportError::InvalidMac)?;
|
||||
hmac.verify_slice(&mac).map_err(|_| KeyExportError::InvalidMac)?;
|
||||
|
||||
let key = GenericArray::from_slice(key);
|
||||
let iv = GenericArray::from_slice(&iv);
|
||||
|
||||
@@ -111,8 +111,13 @@ pub struct OlmMessageHash {
|
||||
|
||||
impl OlmMessageHash {
|
||||
fn new(sender_key: &str, message_type: u8, ciphertext: &str) -> Self {
|
||||
let sha = Sha256::new().chain(sender_key).chain(&[message_type]).chain(&ciphertext);
|
||||
Self { sender_key: sender_key.to_owned(), hash: encode(sha.finalize().as_slice()) }
|
||||
let sha = Sha256::new()
|
||||
.chain_update(sender_key)
|
||||
.chain_update(&[message_type])
|
||||
.chain_update(&ciphertext)
|
||||
.finalize();
|
||||
|
||||
Self { sender_key: sender_key.to_owned(), hash: encode(sha.as_slice()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ pub fn calculate_commitment(public_key: &Base64, content: &StartContent) -> Base
|
||||
|
||||
Base64::new(
|
||||
Sha256::new()
|
||||
.chain(public_key.encode())
|
||||
.chain(&content_string)
|
||||
.chain_update(public_key.encode())
|
||||
.chain_update(&content_string)
|
||||
.finalize()
|
||||
.as_slice()
|
||||
.to_owned(),
|
||||
|
||||
@@ -91,7 +91,7 @@ default-features = false
|
||||
optional = true
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.backoff]
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
features = ["tokio"]
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
@@ -108,7 +108,7 @@ features = ["wasm-bindgen"]
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = "1.0"
|
||||
dirs = "3.0.2"
|
||||
dirs = "4.0.0"
|
||||
futures = { version = "0.3.15", default-features = false, features = ["executor"] }
|
||||
lazy_static = "1.4.0"
|
||||
matches = "0.1.8"
|
||||
@@ -116,7 +116,7 @@ matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" }
|
||||
mockito = "0.30.0"
|
||||
serde_json = "1.0.64"
|
||||
tempfile = "3.2.0"
|
||||
tracing-subscriber = "0.2.18"
|
||||
tracing-subscriber = "0.3.7"
|
||||
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.tokio]
|
||||
|
||||
@@ -91,8 +91,7 @@ impl SasVerification {
|
||||
|
||||
/// Cancel the interactive verification flow because the short auth strings didn't match on both sides.
|
||||
pub async fn mismatch(&self) -> Result<()> {
|
||||
// FIXME: Use variant once https://github.com/ruma/ruma/pull/804 is merged
|
||||
if let Some(request) = self.inner.cancel_with_code(CancelCode::from("m.mismatched_sas")) {
|
||||
if let Some(request) = self.inner.cancel_with_code(CancelCode::MismatchedSas) {
|
||||
self.client.send_verification_request(request).await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,11 @@ async fn send_request(
|
||||
};
|
||||
|
||||
// Turn errors into permanent errors when the retry limit is reached
|
||||
let error_type = if stop { RetryError::Permanent } else { RetryError::Transient };
|
||||
let error_type = if stop {
|
||||
RetryError::Permanent
|
||||
} else {
|
||||
|err| RetryError::Transient { err, retry_after: None }
|
||||
};
|
||||
|
||||
let request = request.try_clone().ok_or(HttpError::UnableToCloneRequest)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user