diff --git a/matrix_qrcode/Cargo.toml b/matrix_qrcode/Cargo.toml index 8dc9cbd5..8bf6243d 100644 --- a/matrix_qrcode/Cargo.toml +++ b/matrix_qrcode/Cargo.toml @@ -26,5 +26,5 @@ byteorder = "1.4.3" image = { version = "0.23.14", optional = true } qrcode = { version = "0.12.0", default-features = false } rqrr = { version = "0.3.2", optional = true } -ruma-identifiers = "0.19.3" +ruma-identifiers = "0.20.0" thiserror = "1.0.25" diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index 70a5a8cf..c4cc92b5 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -55,7 +55,7 @@ version = "0.11.3" default_features = false [dependencies.ruma] -version = "0.2.0" +version = "0.3.0" features = ["client-api-c", "compat", "unstable-pre-spec"] [dependencies.tokio-stream] diff --git a/matrix_sdk/examples/cross_signing_bootstrap.rs b/matrix_sdk/examples/cross_signing_bootstrap.rs index cb6a5c74..35183ea1 100644 --- a/matrix_sdk/examples/cross_signing_bootstrap.rs +++ b/matrix_sdk/examples/cross_signing_bootstrap.rs @@ -1,30 +1,12 @@ use std::{ - collections::BTreeMap, env, io, process::exit, sync::atomic::{AtomicBool, Ordering}, }; -use matrix_sdk::{ - ruma::{api::client::r0::uiaa::AuthData, UserId}, - Client, LoopCtrl, SyncSettings, -}; -use serde_json::json; +use matrix_sdk::{ruma::UserId, Client, LoopCtrl, SyncSettings}; use url::Url; -fn auth_data<'a>(user: &UserId, password: &str, session: Option<&'a str>) -> AuthData<'a> { - let mut auth_parameters = BTreeMap::new(); - let identifier = json!({ - "type": "m.id.user", - "user": user, - }); - - auth_parameters.insert("identifier".to_owned(), identifier); - auth_parameters.insert("password".to_owned(), password.to_owned().into()); - - AuthData::DirectRequest { kind: "m.login.password", auth_parameters, session } -} - async fn bootstrap(client: Client, user_id: UserId, password: String) { println!("Bootstrapping a new cross signing identity, press enter to continue."); @@ -34,8 +16,14 @@ async fn bootstrap(client: Client, user_id: UserId, password: String) { #[cfg(feature = "encryption")] if let Err(e) = client.bootstrap_cross_signing(None).await { + use matrix_sdk::ruma::{api::client::r0::uiaa, assign}; + if let Some(response) = e.uiaa_response() { - let auth_data = auth_data(&user_id, &password, response.session.as_deref()); + let auth_data = uiaa::AuthData::Password(assign!( + uiaa::Password::new(uiaa::UserIdentifier::MatrixId(user_id.as_str()), &password), + { session: response.session.as_deref() } + )); + client .bootstrap_cross_signing(Some(auth_data)) .await diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 45ddb9e9..ffdccdf9 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -118,7 +118,7 @@ use ruma::{ room::create_room, session::{get_login_types, login, sso_login}, sync::sync_events, - uiaa::AuthData, + uiaa::{AuthData, UserIdentifier}, }, unversioned::{discover_homeserver, get_supported_versions}, }, @@ -1070,14 +1070,12 @@ impl Client { ) -> Result { info!("Logging in to {} as {:?}", self.homeserver().await, user); - let request = assign!( - login::Request::new( - login::LoginInfo::Password { identifier: login::UserIdentifier::MatrixId(user), password }, - ), { - device_id: device_id.map(|d| d.into()), - initial_device_display_name, - } - ); + let login_info = + login::LoginInfo::Password { identifier: UserIdentifier::MatrixId(user), password }; + let request = assign!(login::Request::new(login_info), { + device_id: device_id.map(|d| d.into()), + initial_device_display_name, + }); let response = self.send(request, None).await?; self.base_client.receive_login_response(&response).await?; @@ -1383,7 +1381,7 @@ impl Client { /// # use matrix_sdk::ruma::{ /// # api::client::r0::{ /// # account::register::{Request as RegistrationRequest, RegistrationKind}, - /// # uiaa::AuthData, + /// # uiaa, /// # }, /// # assign, DeviceId, /// # }; @@ -1395,7 +1393,9 @@ impl Client { /// let request = assign!(RegistrationRequest::new(), { /// username: Some("user"), /// password: Some("password"), - /// auth: Some(AuthData::FallbackAcknowledgement { session: "foobar" }), + /// auth: Some(uiaa::AuthData::FallbackAcknowledgement( + /// uiaa::FallbackAcknowledgement::new("foobar"), + /// )), /// }); /// let client = Client::new(homeserver).unwrap(); /// client.register(request).await; @@ -1886,9 +1886,12 @@ impl Client { /// /// ```no_run /// # use matrix_sdk::{ - /// # ruma::api::{ - /// # client::r0::uiaa::{UiaaResponse, AuthData}, - /// # error::{FromHttpResponseError, ServerError}, + /// # ruma::{ + /// # api::{ + /// # client::r0::uiaa, + /// # error::{FromHttpResponseError, ServerError}, + /// # }, + /// # assign, /// # }, /// # Client, Error, SyncSettings, /// # }; @@ -1903,20 +1906,10 @@ impl Client { /// /// if let Err(e) = client.delete_devices(devices, None).await { /// if let Some(info) = e.uiaa_response() { - /// let mut auth_parameters = BTreeMap::new(); - /// - /// let identifier = json!({ - /// "type": "m.id.user", - /// "user": "example", - /// }); - /// auth_parameters.insert("identifier".to_owned(), identifier); - /// auth_parameters.insert("password".to_owned(), "wordpass".into()); - /// - /// let auth_data = AuthData::DirectRequest { - /// kind: "m.login.password", - /// auth_parameters, - /// session: info.session.as_deref(), - /// }; + /// let auth_data = uiaa::AuthData::Password(assign!( + /// uiaa::Password::new(uiaa::UserIdentifier::MatrixId("example"), "wordpass"), + /// { session: info.session.as_deref() } + /// )); /// /// client /// .delete_devices(devices, Some(auth_data)) @@ -2320,8 +2313,10 @@ impl Client { /// # Examples /// ```no_run /// # use std::{convert::TryFrom, collections::BTreeMap}; - /// # use matrix_sdk::{Client, ruma::UserId}; - /// # use matrix_sdk::ruma::api::client::r0::uiaa::AuthData; + /// # use matrix_sdk::{ + /// # ruma::{api::client::r0::uiaa, assign, UserId}, + /// # Client, + /// # }; /// # use url::Url; /// # use futures::executor::block_on; /// # use serde_json::json; @@ -2329,30 +2324,17 @@ impl Client { /// # let homeserver = Url::parse("http://example.com").unwrap(); /// # let client = Client::new(homeserver).unwrap(); /// # block_on(async { - /// - /// fn auth_data<'a>(user: &UserId, password: &str, session: Option<&'a str>) -> AuthData<'a> { - /// let mut auth_parameters = BTreeMap::new(); - /// let identifier = json!({ - /// "type": "m.id.user", - /// "user": user, - /// }); - /// auth_parameters.insert("identifier".to_owned(), identifier); - /// auth_parameters.insert("password".to_owned(), password.to_owned().into()); - /// - /// AuthData::DirectRequest { - /// kind: "m.login.password", - /// auth_parameters, - /// session, - /// } - /// } - /// /// if let Err(e) = client.bootstrap_cross_signing(None).await { /// if let Some(response) = e.uiaa_response() { - /// let auth_data = auth_data(&user_id, "wordpass", response.session.as_deref()); - /// client - /// .bootstrap_cross_signing(Some(auth_data)) - /// .await - /// .expect("Couldn't bootstrap cross signing") + /// let auth_data = uiaa::AuthData::Password(assign!( + /// uiaa::Password::new(uiaa::UserIdentifier::MatrixId("example"), "wordpass"), + /// { session: response.session.as_deref() } + /// )); + /// + /// client + /// .bootstrap_cross_signing(Some(auth_data)) + /// .await + /// .expect("Couldn't bootstrap cross signing") /// } else { /// panic!("Error durign cross signing bootstrap {:#?}", e); /// } @@ -2797,7 +2779,7 @@ mod test { media::get_content_thumbnail::Method, membership::Invite3pidInit, session::get_login_types::LoginType, - uiaa::{AuthData, UiaaResponse}, + uiaa::{self, UiaaResponse}, }, }, error::{FromHttpResponseError, ServerError}, @@ -3137,7 +3119,9 @@ mod test { let user = assign!(RegistrationRequest::new(), { username: Some("user"), password: Some("password"), - auth: Some(AuthData::FallbackAcknowledgement { session: "foobar" }), + auth: Some(uiaa::AuthData::FallbackAcknowledgement( + uiaa::FallbackAcknowledgement::new("foobar"), + )), kind: RegistrationKind::User, }); @@ -3813,11 +3797,10 @@ mod test { auth_parameters.insert("identifier".to_owned(), identifier); auth_parameters.insert("password".to_owned(), "wordpass".into()); - let auth_data = AuthData::DirectRequest { - kind: "m.login.password", - auth_parameters, - session: info.session.as_deref(), - }; + let auth_data = uiaa::AuthData::Password(assign!( + uiaa::Password::new(uiaa::UserIdentifier::MatrixId("example"), "wordpass"), + { session: info.session.as_deref() } + )); client.delete_devices(devices, Some(auth_data)).await.unwrap(); } diff --git a/matrix_sdk_appservice/Cargo.toml b/matrix_sdk_appservice/Cargo.toml index bb1d41c5..7a3a98e3 100644 --- a/matrix_sdk_appservice/Cargo.toml +++ b/matrix_sdk_appservice/Cargo.toml @@ -29,7 +29,7 @@ warp = { git = "https://github.com/seanmonstar/warp.git", rev = "629405", option matrix-sdk = { version = "0.3", path = "../matrix_sdk", default-features = false, features = ["appservice", "native-tls"] } [dependencies.ruma] -version = "0.2.0" +version = "0.3.0" features = ["client-api-c", "appservice-api-s", "unstable-pre-spec"] [dev-dependencies] diff --git a/matrix_sdk_base/Cargo.toml b/matrix_sdk_base/Cargo.toml index cd7b08fb..43a3367c 100644 --- a/matrix_sdk_base/Cargo.toml +++ b/matrix_sdk_base/Cargo.toml @@ -26,7 +26,7 @@ docs = ["encryption", "sled_cryptostore"] [dependencies] dashmap = "4.0.2" lru = "0.6.5" -ruma = { version = "0.2.0", features = ["client-api-c", "unstable-pre-spec"] } +ruma = { version = "0.3.0", features = ["client-api-c", "unstable-pre-spec"] } serde = { version = "1.0.126", features = ["rc"] } serde_json = "1.0.64" tracing = "0.1.26" diff --git a/matrix_sdk_base/src/rooms/mod.rs b/matrix_sdk_base/src/rooms/mod.rs index 8b417e04..ca2294fd 100644 --- a/matrix_sdk_base/src/rooms/mod.rs +++ b/matrix_sdk_base/src/rooms/mod.rs @@ -83,7 +83,7 @@ impl BaseRoomInfo { true } AnyStateEventContent::RoomName(n) => { - self.name = n.name().map(|n| n.to_string()); + self.name = n.name.as_ref().map(|n| n.to_string()); true } AnyStateEventContent::RoomCreate(c) => { diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 2a003cf8..6913b707 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -13,7 +13,7 @@ version = "0.3.0" [dependencies] async-trait = "0.1.50" instant = { version = "0.1.9", features = ["wasm-bindgen", "now"] } -ruma = { version = "0.2.0", features = ["client-api-c"] } +ruma = { version = "0.3.0", features = ["client-api-c"] } serde = "1.0.126" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/matrix_sdk_crypto/Cargo.toml b/matrix_sdk_crypto/Cargo.toml index 80d168e4..6aae90c5 100644 --- a/matrix_sdk_crypto/Cargo.toml +++ b/matrix_sdk_crypto/Cargo.toml @@ -22,7 +22,7 @@ docs = ["sled_cryptostore"] [dependencies] matrix-qrcode = { version = "0.1.0", path = "../matrix_qrcode" } matrix-sdk-common = { version = "0.3.0", path = "../matrix_sdk_common" } -ruma = { version = "0.2.0", features = ["client-api-c", "unstable-pre-spec"] } +ruma = { version = "0.3.0", features = ["client-api-c", "unstable-pre-spec"] } olm-rs = { version = "1.0.1", features = ["serde"] } getrandom = "0.2.3" diff --git a/matrix_sdk_crypto/src/identities/device.rs b/matrix_sdk_crypto/src/identities/device.rs index 5f782a60..22871059 100644 --- a/matrix_sdk_crypto/src/identities/device.rs +++ b/matrix_sdk_crypto/src/identities/device.rs @@ -28,7 +28,7 @@ use ruma::{ encryption::{DeviceKeys, SignedKey}, events::{ forwarded_room_key::ForwardedRoomKeyToDeviceEventContent, - key::verification::VerificationMethod, room::encrypted::EncryptedEventContent, + key::verification::VerificationMethod, room::encrypted::EncryptedToDeviceEventContent, AnyToDeviceEventContent, }, DeviceId, DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, UserId, @@ -231,7 +231,7 @@ impl Device { pub(crate) async fn encrypt( &self, content: AnyToDeviceEventContent, - ) -> OlmResult<(Session, EncryptedEventContent)> { + ) -> OlmResult<(Session, EncryptedToDeviceEventContent)> { self.inner.encrypt(&*self.verification_machine.store, content).await } @@ -241,7 +241,7 @@ impl Device { &self, session: InboundGroupSession, message_index: Option, - ) -> OlmResult<(Session, EncryptedEventContent)> { + ) -> OlmResult<(Session, EncryptedToDeviceEventContent)> { let export = if let Some(index) = message_index { session.export_at_index(index).await } else { @@ -464,7 +464,7 @@ impl ReadOnlyDevice { &self, store: &dyn CryptoStore, content: AnyToDeviceEventContent, - ) -> OlmResult<(Session, EncryptedEventContent)> { + ) -> OlmResult<(Session, EncryptedToDeviceEventContent)> { let sender_key = if let Some(k) = self.get_key(DeviceKeyAlgorithm::Curve25519) { k } else { diff --git a/matrix_sdk_crypto/src/key_request.rs b/matrix_sdk_crypto/src/key_request.rs index 570837d0..fad3d68a 100644 --- a/matrix_sdk_crypto/src/key_request.rs +++ b/matrix_sdk_crypto/src/key_request.rs @@ -772,7 +772,7 @@ mod test { use ruma::{ events::{ forwarded_room_key::ForwardedRoomKeyToDeviceEventContent, - room::encrypted::EncryptedEventContent, + room::encrypted::EncryptedToDeviceEventContent, room_key_request::RoomKeyRequestToDeviceEventContent, AnyToDeviceEvent, ToDeviceEvent, }, room_id, @@ -1214,7 +1214,7 @@ mod test { .unwrap() .get(&DeviceIdOrAllDevices::DeviceId(alice_device_id())) .unwrap(); - let content: EncryptedEventContent = content.deserialize_as().unwrap(); + let content: EncryptedToDeviceEventContent = content.deserialize_as().unwrap(); bob_machine.mark_outgoing_request_as_sent(id).await.unwrap(); @@ -1362,7 +1362,7 @@ mod test { .unwrap() .get(&DeviceIdOrAllDevices::DeviceId(alice_device_id())) .unwrap(); - let content: EncryptedEventContent = content.deserialize_as().unwrap(); + let content: EncryptedToDeviceEventContent = content.deserialize_as().unwrap(); bob_machine.mark_outgoing_request_as_sent(id).await.unwrap(); diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 1fe30a6b..c6f2461c 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -34,7 +34,9 @@ use ruma::{ }, assign, events::{ - room::encrypted::{EncryptedEventContent, EncryptedEventScheme}, + room::encrypted::{ + EncryptedEventContent, EncryptedEventScheme, EncryptedToDeviceEventContent, + }, room_key::RoomKeyToDeviceEventContent, AnyMessageEventContent, AnyRoomEvent, AnyToDeviceEvent, SyncMessageEvent, ToDeviceEvent, }, @@ -534,7 +536,7 @@ impl OlmMachine { /// * `event` - The to-device event that should be decrypted. async fn decrypt_to_device_event( &self, - event: &ToDeviceEvent, + event: &ToDeviceEvent, ) -> OlmResult { let mut decrypted = self.account.decrypt_to_device_event(event).await?; // Handle the decrypted event, e.g. fetch out Megolm sessions out of @@ -1249,7 +1251,7 @@ pub(crate) mod test { events::{ dummy::DummyToDeviceEventContent, room::{ - encrypted::EncryptedEventContent, + encrypted::EncryptedToDeviceEventContent, message::{MessageEventContent, MessageType}, }, AnyMessageEventContent, AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, @@ -1298,7 +1300,9 @@ pub(crate) mod test { .expect("Can't parse the keys upload response") } - fn to_device_requests_to_content(requests: Vec>) -> EncryptedEventContent { + fn to_device_requests_to_content( + requests: Vec>, + ) -> EncryptedToDeviceEventContent { let to_device_request = &requests[0]; to_device_request diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index 2931d789..7b6baa66 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -34,7 +34,7 @@ use ruma::{ api::client::r0::keys::{upload_keys, upload_signatures::Request as SignatureUploadRequest}, encryption::{DeviceKeys, OneTimeKey, SignedKey}, events::{ - room::encrypted::{EncryptedEventContent, EncryptedEventScheme}, + room::encrypted::{EncryptedEventScheme, EncryptedToDeviceEventContent}, AnyToDeviceEvent, ToDeviceEvent, }, serde::{CanonicalJsonValue, Raw}, @@ -114,7 +114,7 @@ impl Deref for Account { impl Account { pub async fn decrypt_to_device_event( &self, - event: &ToDeviceEvent, + event: &ToDeviceEvent, ) -> OlmResult { debug!("Decrypting to-device event"); diff --git a/matrix_sdk_crypto/src/olm/session.rs b/matrix_sdk_crypto/src/olm/session.rs index a34d901f..c8a05803 100644 --- a/matrix_sdk_crypto/src/olm/session.rs +++ b/matrix_sdk_crypto/src/olm/session.rs @@ -23,7 +23,7 @@ pub use olm_rs::{ use ruma::{ events::{ room::encrypted::{ - CiphertextInfo, EncryptedEventContent, EncryptedEventScheme, + CiphertextInfo, EncryptedEventScheme, EncryptedToDeviceEventContent, OlmV1Curve25519AesSha2Content, }, AnyToDeviceEventContent, EventContent, @@ -110,7 +110,7 @@ impl Session { &mut self, recipient_device: &ReadOnlyDevice, content: AnyToDeviceEventContent, - ) -> OlmResult { + ) -> OlmResult { let recipient_signing_key = recipient_device .get_key(DeviceKeyAlgorithm::Ed25519) .ok_or(EventError::MissingSigningKey)?; @@ -140,13 +140,11 @@ impl Session { let mut content = BTreeMap::new(); content.insert((&*self.sender_key).to_owned(), ciphertext); - Ok(EncryptedEventContent::new( - EncryptedEventScheme::OlmV1Curve25519AesSha2(OlmV1Curve25519AesSha2Content::new( - content, - self.our_identity_keys.curve25519().to_string(), - )), - None, + Ok(EncryptedEventScheme::OlmV1Curve25519AesSha2(OlmV1Curve25519AesSha2Content::new( + content, + self.our_identity_keys.curve25519().to_string(), )) + .into()) } /// Check if a pre-key Olm message was encrypted for this session. diff --git a/matrix_sdk_test/Cargo.toml b/matrix_sdk_test/Cargo.toml index 6eaa9cc4..aa892329 100644 --- a/matrix_sdk_test/Cargo.toml +++ b/matrix_sdk_test/Cargo.toml @@ -18,6 +18,6 @@ http = "0.2.4" lazy_static = "1.4.0" matrix-sdk-common = { version = "0.3.0", path = "../matrix_sdk_common" } matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix_sdk_test_macros" } -ruma = { version = "0.2.0", features = ["client-api-c"] } +ruma = { version = "0.3.0", features = ["client-api-c"] } serde = "1.0.126" serde_json = "1.0.64"