diff --git a/ruma-federation-api/src/authorization/get_event_authorization/v1.rs b/ruma-federation-api/src/authorization/get_event_authorization/v1.rs index d24f3014..f7d2e823 100644 --- a/ruma-federation-api/src/authorization/get_event_authorization/v1.rs +++ b/ruma-federation-api/src/authorization/get_event_authorization/v1.rs @@ -1,6 +1,7 @@ //! [GET /_matrix/federation/v1/event_auth/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-event-auth-roomid-eventid) use ruma_api::ruma_api; +use ruma_common::Raw; use ruma_events::pdu::Pdu; use ruma_identifiers::{EventId, RoomId}; @@ -14,19 +15,35 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The room ID to get the auth chain for. #[ruma_api(path)] - pub room_id: RoomId, + pub room_id: &'a RoomId, /// The event ID to get the auth chain for. #[ruma_api(path)] - pub event_id: EventId, + pub event_id: &'a EventId, } + #[non_exhaustive] response: { /// The full set of authorization events that make up the state of the room, /// and their authorization events, recursively. pub auth_chain: Vec>, } } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given room id and event id. + pub fn new(room_id: &'a RoomId, event_id: &'a EventId) -> Self { + Self { room_id, event_id } + } +} + +impl Response { + /// Creates a new `Response` with the given auth chain. + pub fn new(auth_chain: Vec>) -> Self { + Self { auth_chain } + } +} diff --git a/ruma-federation-api/src/backfill/get_backfill/v1.rs b/ruma-federation-api/src/backfill/get_backfill/v1.rs index ccd0502f..113338ba 100644 --- a/ruma-federation-api/src/backfill/get_backfill/v1.rs +++ b/ruma-federation-api/src/backfill/get_backfill/v1.rs @@ -17,6 +17,7 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The room ID to backfill. #[ruma_api(path)] @@ -31,6 +32,7 @@ ruma_api! { pub limit: UInt, } + #[non_exhaustive] response: { /// The `server_name` of the homeserver sending this transaction. pub origin: ServerNameBox, diff --git a/ruma-federation-api/src/device/get_devices/v1.rs b/ruma-federation-api/src/device/get_devices/v1.rs index c64d5ce4..7f62a5da 100644 --- a/ruma-federation-api/src/device/get_devices/v1.rs +++ b/ruma-federation-api/src/device/get_devices/v1.rs @@ -16,12 +16,14 @@ ruma_api! { requires_authentication: true, } + #[non_exhaustive] request: { /// The user ID to retrieve devices for. Must be a user local to the receiving homeserver. #[ruma_api(path)] pub user_id: &'a UserId, } + #[non_exhaustive] response: { /// The user ID devices were requested for. pub user_id: UserId, @@ -36,8 +38,25 @@ ruma_api! { } } +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user id. + pub fn new(user_id: &'a UserId) -> Self { + Self { user_id } + } +} + +impl Response { + /// Creates a new `Response` with the given user id and stream id. + /// + /// The device list will be empty. + pub fn new(user_id: UserId, stream_id: UInt) -> Self { + Self { user_id, stream_id, devices: Vec::new() } + } +} + /// Information about a user's device. #[derive(Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] pub struct UserDevice { /// The device ID. pub device_id: DeviceIdBox, @@ -50,16 +69,9 @@ pub struct UserDevice { pub device_display_name: Option, } -impl<'a> Request<'a> { - /// Creates a new `Request` with the given user id - pub fn new(user_id: &'a UserId) -> Self { - Self { user_id } - } -} - -impl Response { - /// Creates a new `Response` with the given user id, stream id and devices. - pub fn new(user_id: UserId, stream_id: UInt, devices: Vec) -> Self { - Self { user_id, stream_id, devices } +impl UserDevice { + /// Creates a new `UserDevice` with the given device id and keys. + pub fn new(device_id: DeviceIdBox, keys: DeviceKeys) -> Self { + Self { device_id, keys, device_display_name: None } } } diff --git a/ruma-federation-api/src/discovery.rs b/ruma-federation-api/src/discovery.rs index e010b833..64801c84 100644 --- a/ruma-federation-api/src/discovery.rs +++ b/ruma-federation-api/src/discovery.rs @@ -13,13 +13,22 @@ pub mod get_server_version; /// Public key of the homeserver for verifying digital signatures. #[derive(Clone, Debug, Deserialize, Serialize)] +#[non_exhaustive] pub struct VerifyKey { /// The Unpadded Base64 encoded key. pub key: String, } +impl VerifyKey { + /// Creates a new `VerifyKey` from the given key. + pub fn new(key: String) -> Self { + Self { key } + } +} + /// A key the server used to use, but stopped using. #[derive(Clone, Debug, Deserialize, Serialize)] +#[non_exhaustive] pub struct OldVerifyKey { /// Timestamp when this key expired. #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] @@ -28,10 +37,17 @@ pub struct OldVerifyKey { pub key: String, } -// Spec is wrong, all fields are required (see -// https://github.com/matrix-org/matrix-doc/issues/2508) +impl OldVerifyKey { + /// Creates a new `OldVerifyKey` with the given expiry time and key. + pub fn new(expired_ts: SystemTime, key: String) -> Self { + Self { expired_ts, key } + } +} + +// Spec is wrong, all fields are required (see https://github.com/matrix-org/matrix-doc/issues/2508) /// Queried server key, signed by the notary server. #[derive(Clone, Debug, Deserialize, Serialize)] +#[non_exhaustive] pub struct ServerKey { /// DNS name of the homeserver. pub server_name: ServerNameBox, @@ -47,3 +63,18 @@ pub struct ServerKey { #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub valid_until_ts: SystemTime, } + +impl ServerKey { + /// Creates a new `ServerKey` with the given server name and validity timestamp. + /// + /// All other fields will be empty. + pub fn new(server_name: ServerNameBox, valid_until_ts: SystemTime) -> Self { + Self { + server_name, + verify_keys: BTreeMap::new(), + old_verify_keys: BTreeMap::new(), + signatures: BTreeMap::new(), + valid_until_ts, + } + } +} diff --git a/ruma-federation-api/src/discovery/get_server_keys/v2.rs b/ruma-federation-api/src/discovery/get_server_keys/v2.rs index fb4675c6..0d8085fa 100644 --- a/ruma-federation-api/src/discovery/get_server_keys/v2.rs +++ b/ruma-federation-api/src/discovery/get_server_keys/v2.rs @@ -13,11 +13,34 @@ ruma_api! { requires_authentication: false, } + #[derive(Default)] + #[non_exhaustive] request: {} + #[non_exhaustive] response: { /// Queried server key, signed by the notary server. #[ruma_api(body)] pub server_key: ServerKey, } } + +impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self + } +} + +impl Response { + /// Creates a new `Response` with the given server key. + pub fn new(server_key: ServerKey) -> Self { + Self { server_key } + } +} + +impl From for Response { + fn from(server_key: ServerKey) -> Self { + Self::new(server_key) + } +}