Update Ruma

Brings changes to the requests metadata. It was changed from a struct to a trait, and the authentication scheme is now an associated type.

This allows to forbid at compile time requests that use an unsupported authentication scheme.
This commit is contained in:
Kévin Commaille
2025-10-14 15:32:32 +02:00
committed by GitHub
parent c1bc814ac2
commit 1e2bf39a7c
7 changed files with 38 additions and 28 deletions
Generated
+9 -9
View File
@@ -4821,7 +4821,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.13.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"assign",
"js_int",
@@ -4838,7 +4838,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.21.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"as_variant",
"assign",
@@ -4861,7 +4861,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.16.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"as_variant",
"base64",
@@ -4894,7 +4894,7 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.31.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"as_variant",
"indexmap",
@@ -4920,7 +4920,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.12.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"headers",
"http",
@@ -4940,7 +4940,7 @@ dependencies = [
[[package]]
name = "ruma-html"
version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"as_variant",
"html5ever",
@@ -4951,7 +4951,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.11.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"js_int",
"thiserror 2.0.16",
@@ -4960,7 +4960,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.16.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"cfg-if",
"proc-macro-crate",
@@ -4975,7 +4975,7 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.18.0"
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
source = "git+https://github.com/ruma/ruma?rev=670349f66f7e3f403c6730967768472dcf1bcf60#670349f66f7e3f403c6730967768472dcf1bcf60"
dependencies = [
"base64",
"ed25519-dalek",
+1 -1
View File
@@ -66,7 +66,7 @@ rand = "0.8.5"
regex = "1.11.2"
reqwest = { version = "0.12.23", default-features = false }
rmp-serde = "1.3.0"
ruma = { git = "https://github.com/ruma/ruma", rev = "c441eccb92a36467217ff929cd71462fbeeeaf1a", features = [
ruma = { git = "https://github.com/ruma/ruma", rev = "670349f66f7e3f403c6730967768472dcf1bcf60", features = [
"client-api-c",
"compat-upload-signatures",
"compat-arbitrary-length-ids",
+4
View File
@@ -17,6 +17,10 @@ All notable changes to this project will be documented in this file.
### Refactor
- [**breaking**]: `Client::send()` has an extra bound where
`Request::Authentication: SupportedAuthScheme`. This allows to drop the
`HttpError::NotClientRequest` error in favor of a compile-time error.
([#5781](https://github.com/matrix-org/matrix-rust-sdk/pull/5781))
- [**breaking**]: The `waveform` field was moved from `AttachmentInfo::Voice` to `BaseAudioInfo`,
allowing to set it for any audio message. Its format also changed, and it is now a list of `f32`
between 0 and 1.
+2
View File
@@ -33,6 +33,7 @@ use crate::{
authentication::oauth::OAuthError,
config::RequestConfig,
error::{HttpError, HttpResult},
http_client::SupportedAuthScheme,
media::MediaError,
};
@@ -77,6 +78,7 @@ impl<R> SendRequest<R> {
impl<R> IntoFuture for SendRequest<R>
where
R: OutgoingRequest + Clone + Debug + SendOutsideWasm + SyncOutsideWasm + 'static,
R::Authentication: SupportedAuthScheme,
R::IncomingResponse: SendOutsideWasm + SyncOutsideWasm,
HttpError: From<FromHttpResponseError<R::EndpointError>>,
{
+3 -1
View File
@@ -98,7 +98,7 @@ use crate::{
EventHandler, EventHandlerContext, EventHandlerDropGuard, EventHandlerHandle,
EventHandlerStore, ObservableEventHandler, SyncEvent,
},
http_client::HttpClient,
http_client::{HttpClient, SupportedAuthScheme},
latest_events::LatestEvents,
media::MediaError,
notification_settings::NotificationSettings,
@@ -1863,6 +1863,7 @@ impl Client {
pub fn send<Request>(&self, request: Request) -> SendRequest<Request>
where
Request: OutgoingRequest + Clone + Debug,
Request::Authentication: SupportedAuthScheme,
HttpError: From<FromHttpResponseError<Request::EndpointError>>,
{
SendRequest {
@@ -1881,6 +1882,7 @@ impl Client {
) -> HttpResult<Request::IncomingResponse>
where
Request: OutgoingRequest + Debug,
Request::Authentication: SupportedAuthScheme,
HttpError: From<FromHttpResponseError<Request::EndpointError>>,
{
let homeserver = self.homeserver().to_string();
-4
View File
@@ -96,10 +96,6 @@ pub enum HttpError {
#[error(transparent)]
Reqwest(#[from] ReqwestError),
/// Queried endpoint is not meant for clients.
#[error("the queried endpoint is not meant for clients")]
NotClientRequest,
/// API response error (deserialization, or a Matrix-specific error).
// `Box` its inner value to reduce the enum size.
#[error(transparent)]
+19 -13
View File
@@ -28,7 +28,7 @@ use bytesize::ByteSize;
use eyeball::SharedObservable;
use http::Method;
use ruma::api::{
AuthScheme, OutgoingRequest, SendAccessToken, SupportedVersions,
OutgoingRequest, SendAccessToken, SupportedVersions, auth_scheme,
error::{FromHttpResponseError, IntoHttpError},
};
use tokio::sync::{Semaphore, SemaphorePermit};
@@ -151,6 +151,7 @@ impl HttpClient {
) -> Result<R::IncomingResponse, HttpError>
where
R: OutgoingRequest + Debug,
R::Authentication: SupportedAuthScheme,
HttpError: From<FromHttpResponseError<R::EndpointError>>,
{
let config = match config {
@@ -168,18 +169,6 @@ impl HttpClient {
// why we record it here, instead of in the #[instrument] macro.
span.record("config", debug(config)).record("request_id", request_id);
let auth_scheme = R::METADATA.authentication;
match auth_scheme {
AuthScheme::AccessToken
| AuthScheme::AccessTokenOptional
| AuthScheme::AppserviceToken
| AuthScheme::AppserviceTokenOptional
| AuthScheme::None => {}
AuthScheme::ServerSignatures => {
return Err(HttpError::NotClientRequest);
}
}
let request = self
.serialize_request(request, config, homeserver, access_token, supported_versions)
.map_err(HttpError::IntoHttp)?;
@@ -254,6 +243,23 @@ async fn response_to_http_response(
Ok(http_builder.body(body).expect("Can't construct a response using the given body"))
}
/// Marker trait to identify the authentication schemes that the [`HttpClient`]
/// supports.
///
/// This trait can also be implemented for custom
/// [`AuthScheme`](auth_scheme::AuthScheme)s if necessary.
pub trait SupportedAuthScheme: auth_scheme::AuthScheme {}
impl SupportedAuthScheme for auth_scheme::NoAuthentication {}
impl SupportedAuthScheme for auth_scheme::AccessToken {}
impl SupportedAuthScheme for auth_scheme::AccessTokenOptional {}
impl SupportedAuthScheme for auth_scheme::AppserviceToken {}
impl SupportedAuthScheme for auth_scheme::AppserviceTokenOptional {}
#[cfg(all(test, not(target_family = "wasm")))]
mod tests {
use std::{