Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Upgrade Ruma to 0.11.0 #4171

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ once_cell = "1.16.0"
pin-project-lite = "0.2.9"
rand = "0.8.5"
reqwest = { version = "0.12.4", default-features = false }
ruma = { git = "https://github.com/ruma/ruma", rev = "26165b23fc2ae9928c5497a21db3d31f4b44cc2a", features = [
ruma = { version = "0.11.0", features = [
"client-api-c",
"compat-upload-signatures",
"compat-user-id",
Expand All @@ -59,7 +59,7 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "26165b23fc2ae9928c5497a21d
"unstable-msc4075",
"unstable-msc4140",
] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "26165b23fc2ae9928c5497a21db3d31f4b44cc2a" }
ruma-common = "0.14.0"
serde = "1.0.151"
serde_html_form = "0.2.0"
serde_json = "1.0.91"
Expand Down
11 changes: 6 additions & 5 deletions bindings/matrix-sdk-crypto-ffi/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ use ruma::{
},
serde::Raw,
to_device::DeviceIdOrAllDevices,
DeviceKeyAlgorithm, EventId, OwnedTransactionId, OwnedUserId, RoomId, UserId,
DeviceKeyAlgorithm, EventId, OneTimeKeyAlgorithm, OwnedTransactionId, OwnedUserId, RoomId,
UserId,
};
use serde::{Deserialize, Serialize};
use serde_json::{value::RawValue, Value};
Expand Down Expand Up @@ -528,20 +529,20 @@ impl OlmMachine {
) -> Result<SyncChangesResult, CryptoStoreError> {
let to_device: ToDevice = serde_json::from_str(&events)?;
let device_changes: RumaDeviceLists = device_changes.into();
let key_counts: BTreeMap<DeviceKeyAlgorithm, UInt> = key_counts
let key_counts: BTreeMap<OneTimeKeyAlgorithm, UInt> = key_counts
.into_iter()
.map(|(k, v)| {
(
DeviceKeyAlgorithm::from(k),
OneTimeKeyAlgorithm::from(k),
v.clamp(0, i32::MAX)
.try_into()
.expect("Couldn't convert key counts into an UInt"),
)
})
.collect();

let unused_fallback_keys: Option<Vec<DeviceKeyAlgorithm>> =
unused_fallback_keys.map(|u| u.into_iter().map(DeviceKeyAlgorithm::from).collect());
let unused_fallback_keys: Option<Vec<OneTimeKeyAlgorithm>> =
unused_fallback_keys.map(|u| u.into_iter().map(OneTimeKeyAlgorithm::from).collect());

let (to_device_events, room_key_infos) = self.runtime.block_on(
self.inner.receive_sync_changes(matrix_sdk_crypto::EncryptionSyncChanges {
Expand Down
47 changes: 36 additions & 11 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use ruma::{
api::client as api,
events::{
ignored_user_list::IgnoredUserListEvent,
marked_unread::MarkedUnreadEventContent,
push_rules::{PushRulesEvent, PushRulesEventContent},
room::{
member::{MembershipState, RoomMemberEventContent, SyncRoomMemberEvent},
Expand Down Expand Up @@ -683,6 +684,25 @@ impl BaseClient {
}
}

// Helper to update the unread marker for stable and unstable prefixes.
fn on_unread_marker(
room_id: &RoomId,
content: &MarkedUnreadEventContent,
room_info: &mut RoomInfo,
room_info_notable_updates: &mut BTreeMap<OwnedRoomId, RoomInfoNotableUpdateReasons>,
) {
if room_info.base_info.is_marked_unread != content.unread {
// Notify the room list about a manual read marker change if the
// value's changed.
room_info_notable_updates
.entry(room_id.to_owned())
.or_default()
.insert(RoomInfoNotableUpdateReasons::UNREAD_MARKER);
}

room_info.base_info.is_marked_unread = content.unread;
}

// Handle new events.
for raw_event in events {
match raw_event.deserialize() {
Expand All @@ -692,19 +712,24 @@ impl BaseClient {
match event {
AnyRoomAccountDataEvent::MarkedUnread(event) => {
on_room_info(room_id, changes, self, |room_info| {
if room_info.base_info.is_marked_unread != event.content.unread {
// Notify the room list about a manual read marker change if the
// value's changed.
room_info_notable_updates
.entry(room_id.to_owned())
.or_default()
.insert(RoomInfoNotableUpdateReasons::UNREAD_MARKER);
}

room_info.base_info.is_marked_unread = event.content.unread;
on_unread_marker(
room_id,
&event.content,
room_info,
room_info_notable_updates,
);
});
}
AnyRoomAccountDataEvent::UnstableMarkedUnread(event) => {
zecakeh marked this conversation as resolved.
Show resolved Hide resolved
on_room_info(room_id, changes, self, |room_info| {
on_unread_marker(
room_id,
&event.content.0,
room_info,
room_info_notable_updates,
);
});
}

AnyRoomAccountDataEvent::Tag(event) => {
on_room_info(room_id, changes, self, |room_info| {
room_info.base_info.handle_notable_tags(&event.content.tags);
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-crypto/src/backups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,19 @@ impl BackupMachine {
if device_key_id.algorithm() == DeviceKeyAlgorithm::Ed25519 {
// No need to check our own device here, we're doing that using
// the check_own_device_signature().
if device_key_id.device_id() == self.store.static_account().device_id {
if device_key_id.key_name() == self.store.static_account().device_id {
continue;
}

let state = self
.test_ed25519_device_signature(
device_key_id.device_id(),
device_key_id.key_name(),
signatures,
auth_data,
)
.await?;

result.insert(device_key_id.device_id().to_owned(), state);
result.insert(device_key_id.key_name().to_owned(), state);

// Abort the loop if we found a trusted and valid signature,
// unless we should check all of them.
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/gossiping/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use ruma::{
events::secret::request::{
RequestAction, SecretName, ToDeviceSecretRequestEvent as SecretRequestEvent,
},
DeviceId, DeviceKeyAlgorithm, OwnedDeviceId, OwnedTransactionId, OwnedUserId, RoomId,
DeviceId, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedTransactionId, OwnedUserId, RoomId,
TransactionId, UserId,
};
use tracing::{debug, field::debug, info, instrument, trace, warn, Span};
Expand Down Expand Up @@ -178,7 +178,7 @@ impl GossipMachine {
.map(|(key, value)| {
let device_map = value
.iter()
.map(|d| (d.to_owned(), DeviceKeyAlgorithm::SignedCurve25519))
.map(|d| (d.to_owned(), OneTimeKeyAlgorithm::SignedCurve25519))
.collect();

(key.to_owned(), device_map)
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-crypto/src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use ruma::{
AnyToDeviceEvent, MessageLikeEventContent,
},
serde::{JsonObject, Raw},
DeviceId, DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedDeviceKeyId,
DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedDeviceKeyId,
OwnedTransactionId, OwnedUserId, RoomId, TransactionId, UInt, UserId,
};
use serde_json::{value::to_raw_value, Value};
Expand Down Expand Up @@ -2557,9 +2557,9 @@ pub struct EncryptionSyncChanges<'a> {
/// sync response.
pub changed_devices: &'a DeviceLists,
/// The number of one time keys, as returned in the sync response.
pub one_time_keys_counts: &'a BTreeMap<DeviceKeyAlgorithm, UInt>,
pub one_time_keys_counts: &'a BTreeMap<OneTimeKeyAlgorithm, UInt>,
/// An optional list of fallback keys.
pub unused_fallback_keys: Option<&'a [DeviceKeyAlgorithm]>,
pub unused_fallback_keys: Option<&'a [OneTimeKeyAlgorithm]>,
/// A next-batch token obtained from a to-device sync query.
pub next_batch_token: Option<String>,
}
Expand Down
10 changes: 6 additions & 4 deletions crates/matrix-sdk-crypto/src/machine/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ use as_variant::as_variant;
use matrix_sdk_test::{ruma_response_from_json, test_json};
use ruma::{
api::client::keys::{
claim_keys, get_keys, get_keys::v3::Response as KeysQueryResponse, upload_keys,
claim_keys,
get_keys::{self, v3::Response as KeysQueryResponse},
upload_keys,
},
device_id,
encryption::OneTimeKey,
events::dummy::ToDeviceDummyEventContent,
serde::Raw,
user_id, DeviceId, OwnedDeviceKeyId, TransactionId, UserId,
user_id, DeviceId, OwnedOneTimeKeyId, TransactionId, UserId,
};
use serde_json::json;

Expand All @@ -37,7 +39,7 @@ use crate::{
};

/// These keys need to be periodically uploaded to the server.
type OneTimeKeys = BTreeMap<OwnedDeviceKeyId, Raw<OneTimeKey>>;
type OneTimeKeys = BTreeMap<OwnedOneTimeKeyId, Raw<OneTimeKey>>;

fn alice_device_id() -> &'static DeviceId {
device_id!("JLAFKJWSCS")
Expand Down Expand Up @@ -178,7 +180,7 @@ pub async fn create_session(
machine: &OlmMachine,
user_id: &UserId,
device_id: &DeviceId,
key_id: OwnedDeviceKeyId,
key_id: OwnedOneTimeKeyId,
one_time_key: Raw<OneTimeKey>,
) {
let one_time_keys = BTreeMap::from([(
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-crypto/src/machine/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use ruma::{
room_id,
serde::Raw,
uint, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch,
TransactionId, UserId,
OneTimeKeyAlgorithm, TransactionId, UserId,
};
use serde_json::json;
use vodozemac::{
Expand Down Expand Up @@ -174,7 +174,7 @@ async fn test_generate_one_time_keys() {
.await
.unwrap();

response.one_time_key_counts.insert(DeviceKeyAlgorithm::SignedCurve25519, uint!(50));
response.one_time_key_counts.insert(OneTimeKeyAlgorithm::SignedCurve25519, uint!(50));

machine.receive_keys_upload_response(&response).await.unwrap();

Expand Down Expand Up @@ -275,7 +275,7 @@ fn test_one_time_key_signing() {
async fn test_keys_for_upload() {
let machine = OlmMachine::new(user_id(), alice_device_id()).await;

let key_counts = BTreeMap::from([(DeviceKeyAlgorithm::SignedCurve25519, 49u8.into())]);
let key_counts = BTreeMap::from([(OneTimeKeyAlgorithm::SignedCurve25519, 49u8.into())]);
machine
.receive_sync_changes(EncryptionSyncChanges {
to_device_events: Vec::new(),
Expand Down Expand Up @@ -327,7 +327,7 @@ async fn test_keys_for_upload() {

let mut response = keys_upload_response();
response.one_time_key_counts.insert(
DeviceKeyAlgorithm::SignedCurve25519,
OneTimeKeyAlgorithm::SignedCurve25519,
account.max_one_time_keys().try_into().unwrap(),
);

Expand Down
Loading
Loading