Add remaining key backup endpoints

Co-authored-by: Timo Koesters <timo@koesters.xyz>
This commit is contained in:
Devin Ragotzy 2020-09-29 07:35:42 -04:00 committed by GitHub
parent 92f1fb463a
commit 648c3f5732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 428 additions and 1 deletions

View File

@ -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.

View File

@ -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 }
}
}

View File

@ -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<String, 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 and sessions.
pub fn new(version: &'a str, room_id: &'a RoomId, sessions: BTreeMap<String, KeyData>) -> 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 }
}
}

View File

@ -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
}
}

View File

@ -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 }
}
}

View File

@ -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 }
}
}

View File

@ -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 }
}
}

View File

@ -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 }
}
}

View File

@ -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<String, KeyData>,
}
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<String, KeyData>) -> Self {
Self { sessions }
}
}