diff --git a/ruma-client-api/src/r0/backup.rs b/ruma-client-api/src/r0/backup.rs index 4427c7c9..aa3a78ce 100644 --- a/ruma-client-api/src/r0/backup.rs +++ b/ruma-client-api/src/r0/backup.rs @@ -1,8 +1,16 @@ //! Endpoints for server-side key backups. +pub mod add_backup_key_session; +pub mod add_backup_key_sessions; pub mod add_backup_keys; pub mod create_backup; +pub mod delete_backup; +pub mod delete_backup_key_session; +pub mod delete_backup_key_sessions; +pub mod delete_backup_keys; pub mod get_backup; +pub mod get_backup_key_session; +pub mod get_backup_key_sessions; pub mod get_backup_keys; pub mod get_latest_backup; pub mod update_backup; @@ -46,7 +54,7 @@ pub enum BackupAlgorithm { }, } -/// The key data. +/// Information about the backup key. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct KeyData { /// The index of the first message in the session that the key can decrypt. diff --git a/ruma-client-api/src/r0/backup/add_backup_key_session.rs b/ruma-client-api/src/r0/backup/add_backup_key_session.rs new file mode 100644 index 00000000..02e8e7a6 --- /dev/null +++ b/ruma-client-api/src/r0/backup/add_backup_key_session.rs @@ -0,0 +1,66 @@ +//! [PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}](https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-keys-roomid-sessionid) + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +use super::KeyData; + +ruma_api! { + metadata: { + description: "Store several keys in the backup.", + method: PUT, + name: "add_backup_key_session", + path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, + + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The ID of the megolm session whose key is requested. + #[ruma_api(path)] + pub session_id: &'a str, + + /// The key information to backup. + #[ruma_api(body)] + pub session_data: KeyData, + } + + response: { + /// An opaque string representing stored keys in the backup. Clients can compare it with + /// the etag value they received in the request of their last key storage request. + pub etag: String, + + /// The number of keys stored in the backup. + pub count: UInt, + } + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version, room_id, session_id and session_data. + pub fn new( + version: &'a str, + room_id: &'a RoomId, + session_id: &'a str, + session_data: KeyData, + ) -> Self { + Self { version, room_id, session_id, session_data } + } +} + +impl Response { + /// Creates an new `Response` with the given etag and count. + pub fn new(etag: String, count: UInt) -> Self { + Self { etag, count } + } +} diff --git a/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs b/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs new file mode 100644 index 00000000..a0b2fbe5 --- /dev/null +++ b/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs @@ -0,0 +1,58 @@ +//! [PUT /_matrix/client/r0/room_keys/keys/{roomId}](https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-keys-roomid) + +use std::collections::BTreeMap; + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +use super::KeyData; + +ruma_api! { + metadata: { + description: "Store several sessions in the backup.", + method: PUT, + name: "add_backup_key_sessions", + path: "/_matrix/client/r0/room_keys/keys/:room_id", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, + + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// A map from session IDs to key data. + pub sessions: BTreeMap, + } + + response: { + /// An opaque string representing stored keys in the backup. Clients can compare it with + /// the etag value they received in the request of their last key storage request. + pub etag: String, + + /// The number of keys stored in the backup. + pub count: UInt, + } + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version, room_id and sessions. + pub fn new(version: &'a str, room_id: &'a RoomId, sessions: BTreeMap) -> Self { + Self { version, room_id, sessions } + } +} + +impl Response { + /// Creates an new `Response` with the given etag and count. + pub fn new(etag: String, count: UInt) -> Self { + Self { etag, count } + } +} diff --git a/ruma-client-api/src/r0/backup/delete_backup.rs b/ruma-client-api/src/r0/backup/delete_backup.rs new file mode 100644 index 00000000..969e2ba5 --- /dev/null +++ b/ruma-client-api/src/r0/backup/delete_backup.rs @@ -0,0 +1,39 @@ +//! [DELETE /_matrix/client/r0/room_keys/version/{version}](https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-version-version) + +use ruma_api::ruma_api; + +ruma_api! { + metadata: { + description: "Delete an existing backup.", + method: DELETE, + name: "delete_backup", + path: "/_matrix/client/r0/room_keys/version/:version", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. + #[ruma_api(path)] + pub version: &'a str, + } + + #[derive(Default)] + response: {} + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version, room_id and sessions. + pub fn new(version: &'a str) -> Self { + Self { version } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/backup/delete_backup_key_session.rs b/ruma-client-api/src/r0/backup/delete_backup_key_session.rs new file mode 100644 index 00000000..ada0b2ab --- /dev/null +++ b/ruma-client-api/src/r0/backup/delete_backup_key_session.rs @@ -0,0 +1,55 @@ +//! [DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}](https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-keys-roomid-sessionid) + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +ruma_api! { + metadata: { + description: "Delete a key from the backup", + method: GET, + name: "delete_backup_key_session", + path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, + + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The ID of the megolm session whose key is requested. + #[ruma_api(path)] + pub session_id: &'a str, + } + + response: { + /// An opaque string representing stored keys in the backup. Clients can compare it with + /// the etag value they received in the request of their last key storage request. + pub etag: String, + + /// The number of keys stored in the backup. + pub count: UInt, + } + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version, room_id and session_id. + pub fn new(version: &'a str, room_id: &'a RoomId, session_id: &'a str) -> Self { + Self { version, room_id, session_id } + } +} + +impl Response { + /// Creates an new `Response` with the given etag and count. + pub fn new(etag: String, count: UInt) -> Self { + Self { etag, count } + } +} diff --git a/ruma-client-api/src/r0/backup/delete_backup_key_sessions.rs b/ruma-client-api/src/r0/backup/delete_backup_key_sessions.rs new file mode 100644 index 00000000..52756bd6 --- /dev/null +++ b/ruma-client-api/src/r0/backup/delete_backup_key_sessions.rs @@ -0,0 +1,52 @@ +//! [DELETE /_matrix/client/r0/room_keys/keys/{roomId}](https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-keys-roomid) + +use js_int::UInt; +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +ruma_api! { + metadata: { + description: "Delete keys from the backup for a given room.", + method: GET, + name: "delete_backup_key_sessions", + path: "/_matrix/client/r0/room_keys/keys/:room_id", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, + + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } + + response: { + /// An opaque string representing stored keys in the backup. Clients can compare it with + /// the etag value they received in the request of their last key storage request. + pub etag: String, + + /// The number of keys stored in the backup. + pub count: UInt, + } + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version and room_id. + + pub fn new(version: &'a str, room_id: &'a RoomId) -> Self { + Self { version, room_id } + } +} + +impl Response { + /// Creates an new `Response` with the given etag and count. + pub fn new(etag: String, count: UInt) -> Self { + Self { etag, count } + } +} diff --git a/ruma-client-api/src/r0/backup/delete_backup_keys.rs b/ruma-client-api/src/r0/backup/delete_backup_keys.rs new file mode 100644 index 00000000..6b3a88a4 --- /dev/null +++ b/ruma-client-api/src/r0/backup/delete_backup_keys.rs @@ -0,0 +1,46 @@ +//! [DELETE /_matrix/client/r0/room_keys/keys](https://matrix.org/docs/spec/client_server/unstable#delete-matrix-client-r0-room-keys-keys) + +use js_int::UInt; +use ruma_api::ruma_api; + +ruma_api! { + metadata: { + description: "Delete all keys in a backup.", + method: PUT, + name: "delete_backup_keys", + path: "/_matrix/client/r0/room_keys/keys", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, + } + + response: { + /// An opaque string representing stored keys in the backup. Clients can compare it with + /// the etag value they received in the request of their last key storage request. + pub etag: String, + + /// The number of keys stored in the backup. + pub count: UInt, + } + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version. + pub fn new(version: &'a str) -> Self { + Self { version } + } +} + +impl Response { + /// Creates an new `Response` with the given etag and count. + pub fn new(etag: String, count: UInt) -> Self { + Self { etag, count } + } +} diff --git a/ruma-client-api/src/r0/backup/get_backup_key_session.rs b/ruma-client-api/src/r0/backup/get_backup_key_session.rs new file mode 100644 index 00000000..6b846a51 --- /dev/null +++ b/ruma-client-api/src/r0/backup/get_backup_key_session.rs @@ -0,0 +1,53 @@ +//! [GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}](https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-keys-roomid-sessionid) + +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +use super::KeyData; + +ruma_api! { + metadata: { + description: "Retrieve a key from the backup", + method: GET, + name: "get_backup_key_session", + path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, + + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + + /// The ID of the megolm session whose key is requested. + #[ruma_api(path)] + pub session_id: &'a str, + } + + response: { + /// Information about the requested backup key. + #[ruma_api(body)] + pub key_data: KeyData, + } + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version, room_id and session_id. + pub fn new(version: &'a str, room_id: &'a RoomId, session_id: &'a str) -> Self { + Self { version, room_id, session_id } + } +} + +impl Response { + /// Creates a new `Response` with the given key_data. + pub fn new(key_data: KeyData) -> Self { + Self { key_data } + } +} diff --git a/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs b/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs new file mode 100644 index 00000000..1d4eac9c --- /dev/null +++ b/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs @@ -0,0 +1,50 @@ +//! [GET /_matrix/client/r0/room_keys/keys/{roomId}](https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-keys-roomid) + +use std::collections::BTreeMap; + +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +use super::KeyData; + +ruma_api! { + metadata: { + description: "Retrieve sessions from the backup for a given room.", + method: GET, + name: "get_backup_key_sessions", + path: "/_matrix/client/r0/room_keys/keys/:room_id", + rate_limited: true, + authentication: AccessToken, + } + + request: { + /// The backup version. Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, + + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } + + response: { + /// A map of session IDs to key data. + pub sessions: BTreeMap, + } + + error: crate::Error +} + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given version and room_id. + pub fn new(version: &'a str, room_id: &'a RoomId) -> Self { + Self { version, room_id } + } +} + +impl Response { + /// Creates a new `Response` with the given sessions. + pub fn new(sessions: BTreeMap) -> Self { + Self { sessions } + } +}