Bump Ruma for CanonicalJson property name optimizations.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-11-02 03:56:39 +00:00
parent a14556da97
commit f59d62c01c
13 changed files with 57 additions and 53 deletions

20
Cargo.lock generated
View File

@@ -3476,7 +3476,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.13.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"assign",
"js_int",
@@ -3495,7 +3495,7 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.13.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"js_int",
"ruma-common",
@@ -3507,7 +3507,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.21.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"as_variant",
"assign",
@@ -3532,7 +3532,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.16.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"as_variant",
"base64",
@@ -3566,7 +3566,7 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.31.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"as_variant",
"indexmap",
@@ -3593,7 +3593,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.12.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"bytes",
"headers",
@@ -3616,7 +3616,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.11.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"js_int",
"thiserror 2.0.17",
@@ -3625,7 +3625,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.16.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"cfg-if",
"proc-macro-crate",
@@ -3640,7 +3640,7 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.12.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"js_int",
"ruma-common",
@@ -3652,7 +3652,7 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.18.0"
source = "git+https://github.com/matrix-construct/ruma?rev=be88c97057b28374d418394db376a7049d8b6464#be88c97057b28374d418394db376a7049d8b6464"
source = "git+https://github.com/matrix-construct/ruma?rev=db4bf59eaa1757735f38489f8924348ae05a6a17#db4bf59eaa1757735f38489f8924348ae05a6a17"
dependencies = [
"base64",
"ed25519-dalek",

View File

@@ -320,7 +320,7 @@ default-features = false
[workspace.dependencies.ruma]
git = "https://github.com/matrix-construct/ruma"
rev = "be88c97057b28374d418394db376a7049d8b6464"
rev = "db4bf59eaa1757735f38489f8924348ae05a6a17"
features = [
"__compat",
"appservice-api-c",

View File

@@ -210,11 +210,11 @@ async fn knock_room_helper_local(
})?;
knock_event_stub.insert(
"origin".to_owned(),
"origin".into(),
CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()),
);
knock_event_stub.insert(
"origin_server_ts".to_owned(),
"origin_server_ts".into(),
CanonicalJsonValue::Integer(
utils::millis_since_unix_epoch()
.try_into()
@@ -222,7 +222,7 @@ async fn knock_room_helper_local(
),
);
knock_event_stub.insert(
"content".to_owned(),
"content".into(),
to_canonical_value(RoomMemberEventContent {
displayname: services.users.displayname(sender_user).await.ok(),
avatar_url: services.users.avatar_url(sender_user).await.ok(),
@@ -244,7 +244,7 @@ async fn knock_room_helper_local(
// Add event_id
knock_event_stub
.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into()));
.insert("event_id".into(), CanonicalJsonValue::String(event_id.clone().into()));
// It has enough fields to be called a proper event now
let knock_event = knock_event_stub;
@@ -346,11 +346,11 @@ async fn knock_room_helper_remote(
})?;
knock_event_stub.insert(
"origin".to_owned(),
"origin".into(),
CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()),
);
knock_event_stub.insert(
"origin_server_ts".to_owned(),
"origin_server_ts".into(),
CanonicalJsonValue::Integer(
utils::millis_since_unix_epoch()
.try_into()
@@ -358,7 +358,7 @@ async fn knock_room_helper_remote(
),
);
knock_event_stub.insert(
"content".to_owned(),
"content".into(),
to_canonical_value(RoomMemberEventContent {
displayname: services.users.displayname(sender_user).await.ok(),
avatar_url: services.users.avatar_url(sender_user).await.ok(),
@@ -380,7 +380,7 @@ async fn knock_room_helper_remote(
// Add event_id
knock_event_stub
.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into()));
.insert("event_id".into(), CanonicalJsonValue::String(event_id.clone().into()));
// It has enough fields to be called a proper event now
let knock_event = knock_event_stub;

View File

@@ -1,6 +1,9 @@
use axum::RequestPartsExt;
use axum_extra::{TypedHeader, headers::Authorization, typed_header::TypedHeaderRejectionReason};
use ruma::{CanonicalJsonObject, CanonicalJsonValue, api::federation::authentication::XMatrix};
use ruma::{
CanonicalJsonName, CanonicalJsonObject, CanonicalJsonValue,
api::federation::authentication::XMatrix,
};
use tuwunel_core::{Err, Result, debug_error, err, warn};
use tuwunel_service::{
Services,
@@ -14,7 +17,7 @@ pub(super) async fn auth_server(
request: &mut Request,
body: Option<&CanonicalJsonValue>,
) -> Result<Auth> {
type Member = (String, CanonicalJsonValue);
type Member = (CanonicalJsonName, CanonicalJsonValue);
type Object = CanonicalJsonObject;
type Value = CanonicalJsonValue;
@@ -66,7 +69,7 @@ pub(super) async fn auth_server(
err!(Request(Forbidden(debug_warn!("Failed to fetch signing keys: {e}"))))
})?;
let keys: PubKeys = [(x_matrix.key.to_string(), key.key)].into();
let keys: PubKeys = [(x_matrix.key.as_str().into(), key.key)].into();
let keys: PubKeyMap = [(origin.as_str().into(), keys)].into();
if let Err(e) = ruma::signatures::verify_json(&keys, &authorization) {
debug_error!("Failed to verify federation request from {origin}: {e}");

View File

@@ -100,7 +100,7 @@ pub(crate) async fn create_invite_route(
let event_id = gen_event_id(&signed_event, &body.room_version)?;
// Add event_id back
signed_event.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.to_string()));
signed_event.insert("event_id".into(), CanonicalJsonValue::String(event_id.to_string()));
let sender: &UserId = signed_event
.get("sender")
@@ -127,7 +127,7 @@ pub(crate) async fn create_invite_route(
let mut event: JsonObject = serde_json::from_str(body.event.get())
.map_err(|e| err!(Request(BadJson("Invalid invite event PDU: {e}"))))?;
event.insert("event_id".to_owned(), "$placeholder".into());
event.insert("event_id".into(), "$placeholder".into());
let pdu: PduEvent = serde_json::from_value(event.into())
.map_err(|e| err!(Request(BadJson("Invalid invite event PDU: {e}"))))?;

View File

@@ -62,7 +62,7 @@ fn mutate_outgoing_reference_format(value: &mut CanonicalJsonValue) {
if let Some(event_id) = value.as_str().map(ToOwned::to_owned) {
*value = CanonicalJsonValue::Array(vec![
CanonicalJsonValue::String(event_id),
CanonicalJsonValue::Object([(String::new(), "".into())].into()),
CanonicalJsonValue::Object([(Default::default(), "".into())].into()),
]);
}
});
@@ -92,7 +92,7 @@ pub fn from_incoming_federation(
}
if !room_rules.event_format.require_event_id {
pdu_json.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.into()));
pdu_json.insert("event_id".into(), CanonicalJsonValue::String(event_id.into()));
}
PduEvent::from_val(pdu_json)

View File

@@ -364,7 +364,7 @@ mod tests {
.unwrap();
let long_string = repeat_n('a', 66_000).collect::<String>();
content.insert("big_data".to_owned(), long_string.into());
content.insert("big_data".into(), long_string.into());
check_pdu_format(&pdu, &EventFormatRules::V3).unwrap_err();
}
@@ -384,7 +384,7 @@ mod tests {
for field in &["event_id", "sender", "room_id", "type", "state_key"] {
let mut pdu = pdu_v1();
let value = repeat_n('a', 300).collect::<String>();
pdu.insert((*field).to_owned(), value.into());
pdu.insert((*field).into(), value.into());
check_pdu_format(&pdu, &EventFormatRules::V1).unwrap_err();
}
}
@@ -393,7 +393,7 @@ mod tests {
fn check_pdu_format_strings_wrong_format() {
for field in &["event_id", "sender", "room_id", "type", "state_key"] {
let mut pdu = pdu_v1();
pdu.insert((*field).to_owned(), true.into());
pdu.insert((*field).into(), true.into());
check_pdu_format(&pdu, &EventFormatRules::V1).unwrap_err();
}
}
@@ -405,7 +405,7 @@ mod tests {
let value: Vec<_> =
repeat_n(CanonicalJsonValue::from("$eventid".to_owned()), 30).collect();
pdu.insert((*field).to_owned(), value.into());
pdu.insert((*field).into(), value.into());
check_pdu_format(&pdu, &EventFormatRules::V3).unwrap_err();
}
}
@@ -414,7 +414,7 @@ mod tests {
fn check_pdu_format_arrays_wrong_format() {
for field in &["prev_events", "auth_events"] {
let mut pdu = pdu_v3();
pdu.insert((*field).to_owned(), true.into());
pdu.insert((*field).into(), true.into());
check_pdu_format(&pdu, &EventFormatRules::V3).unwrap_err();
}
}
@@ -422,7 +422,7 @@ mod tests {
#[test]
fn check_pdu_format_negative_depth() {
let mut pdu = pdu_v3();
pdu.insert("depth".to_owned(), int!(-1).into())
pdu.insert("depth".into(), int!(-1).into())
.unwrap();
check_pdu_format(&pdu, &EventFormatRules::V3).unwrap_err();
@@ -431,7 +431,7 @@ mod tests {
#[test]
fn check_pdu_format_depth_wrong_format() {
let mut pdu = pdu_v3();
pdu.insert("depth".to_owned(), true.into());
pdu.insert("depth".into(), true.into());
check_pdu_format(&pdu, &EventFormatRules::V3).unwrap_err();
}

View File

@@ -5,7 +5,7 @@ use http::{HeaderValue, header::AUTHORIZATION};
use ipaddress::IPAddress;
use reqwest::{Client, Method, Request, Response, Url};
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, ServerName, ServerSigningKeyId,
CanonicalJsonName, CanonicalJsonObject, CanonicalJsonValue, ServerName, ServerSigningKeyId,
api::{
EndpointError, IncomingResponse, MatrixVersion, OutgoingRequest, SendAccessToken,
SupportedVersions, client::error::Error as RumaError,
@@ -232,7 +232,7 @@ fn handle_error(
#[implement(super::Service)]
fn sign_request(&self, http_request: &mut http::Request<Vec<u8>>, dest: &ServerName) {
type Member = (String, Value);
type Member = (CanonicalJsonName, Value);
type Value = CanonicalJsonValue;
type Object = CanonicalJsonObject;

View File

@@ -175,7 +175,7 @@ pub async fn join_remote(
};
join_event_stub.insert(
"origin".to_owned(),
"origin".into(),
CanonicalJsonValue::String(
self.services
.globals
@@ -185,7 +185,7 @@ pub async fn join_remote(
),
);
join_event_stub.insert(
"origin_server_ts".to_owned(),
"origin_server_ts".into(),
CanonicalJsonValue::Integer(
utils::millis_since_unix_epoch()
.try_into()
@@ -193,7 +193,7 @@ pub async fn join_remote(
),
);
join_event_stub.insert(
"content".to_owned(),
"content".into(),
to_canonical_value(RoomMemberEventContent {
displayname: self
.services
@@ -306,7 +306,7 @@ pub async fn join_remote(
.expect("we created a valid pdu")
.as_object_mut()
.expect("we created a valid pdu")
.insert(remote_server.to_string(), signature.clone());
.insert(remote_server.as_str().into(), signature.clone());
},
| Err(e) => {
warn!(
@@ -649,7 +649,7 @@ pub async fn join_local(
.and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok());
join_event_stub.insert(
"origin".to_owned(),
"origin".into(),
CanonicalJsonValue::String(
self.services
.globals
@@ -659,7 +659,7 @@ pub async fn join_local(
),
);
join_event_stub.insert(
"origin_server_ts".to_owned(),
"origin_server_ts".into(),
CanonicalJsonValue::Integer(
utils::millis_since_unix_epoch()
.try_into()
@@ -667,7 +667,7 @@ pub async fn join_local(
),
);
join_event_stub.insert(
"content".to_owned(),
"content".into(),
to_canonical_value(RoomMemberEventContent {
displayname: self
.services

View File

@@ -290,7 +290,7 @@ async fn remote_leave(&self, user_id: &UserId, room_id: &RoomId) -> Result {
// TODO: Is origin needed?
leave_event_stub.insert(
"origin".to_owned(),
"origin".into(),
CanonicalJsonValue::String(
self.services
.globals
@@ -300,7 +300,7 @@ async fn remote_leave(&self, user_id: &UserId, room_id: &RoomId) -> Result {
),
);
leave_event_stub.insert(
"origin_server_ts".to_owned(),
"origin_server_ts".into(),
CanonicalJsonValue::Integer(
utils::millis_since_unix_epoch()
.try_into()

View File

@@ -68,7 +68,7 @@ impl Service {
.map_err(|e| err!(Request(InvalidParam("Thread root pdu not found: {e:?}"))))?;
if let CanonicalJsonValue::Object(unsigned) = root_pdu_json
.entry("unsigned".to_owned())
.entry("unsigned".into())
.or_insert_with(|| CanonicalJsonValue::Object(BTreeMap::default()))
{
if let Some(mut relations) = unsigned
@@ -85,7 +85,7 @@ impl Service {
let content = serde_json::to_value(relations).expect("to_value always works");
unsigned.insert(
"m.relations".to_owned(),
"m.relations".into(),
json!({ "m.thread": content })
.try_into()
.expect("thread is valid json"),
@@ -101,7 +101,7 @@ impl Service {
let content = serde_json::to_value(relations).expect("to_value always works");
unsigned.insert(
"m.relations".to_owned(),
"m.relations".into(),
json!({ "m.thread": content })
.try_into()
.expect("thread is valid json"),

View File

@@ -106,7 +106,7 @@ where
// clients can easily interpret things like membership changes
if let Some(state_key) = pdu.state_key() {
if let CanonicalJsonValue::Object(unsigned) = pdu_json
.entry("unsigned".to_owned())
.entry("unsigned".into())
.or_insert_with(|| CanonicalJsonValue::Object(BTreeMap::default()))
{
if let Ok(shortstatehash) = self
@@ -122,7 +122,7 @@ where
.await
{
unsigned.insert(
"prev_content".to_owned(),
"prev_content".into(),
CanonicalJsonValue::Object(
utils::to_canonical_object(prev_state.get_content_as_value())
.map_err(|e| {
@@ -133,11 +133,11 @@ where
),
);
unsigned.insert(
String::from("prev_sender"),
"prev_sender".into(),
CanonicalJsonValue::String(prev_state.sender().to_string()),
);
unsigned.insert(
String::from("replaces_state"),
"replaces_state".into(),
CanonicalJsonValue::String(prev_state.event_id().to_string()),
);
}

View File

@@ -39,7 +39,7 @@ where
let mut keys = PubKeyMap::new();
for (server, key_ids) in batch {
let pubkeys = self.get_pubkeys_for(server, key_ids).await;
keys.insert(server.into(), pubkeys);
keys.insert(server.as_str().into(), pubkeys);
}
keys
@@ -53,7 +53,7 @@ where
let mut keys = PubKeys::new();
for key_id in key_ids {
if let Ok(verify_key) = self.get_verify_key(origin, key_id).await {
keys.insert(key_id.into(), verify_key.key);
keys.insert(key_id.as_str().into(), verify_key.key);
}
}
@@ -71,6 +71,7 @@ pub async fn get_verify_key(
.server
.config
.query_trusted_key_servers_first;
let notary_only = self
.services
.server