From af0a8f009cc62fa4fd2fab7c2ac9eb99fc6cee8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 3 Dec 2021 13:15:35 +0100 Subject: [PATCH] client-api: Update the backup API to use raw variants of types Similarly to the way structs holding public keys require signature verification, the BackupAlgorithm struct may require verification as well. This lets users know if a certain device trusts the BackupAlgorithm and if it should be used to upload room keys to the backup. --- crates/ruma-client-api/src/r0/backup.rs | 5 +++-- .../src/r0/backup/add_backup_key_session.rs | 5 +++-- .../src/r0/backup/add_backup_key_sessions.rs | 5 +++-- crates/ruma-client-api/src/r0/backup/create_backup.rs | 5 +++-- crates/ruma-client-api/src/r0/backup/get_backup.rs | 10 ++++++++-- .../src/r0/backup/get_backup_key_session.rs | 5 +++-- .../src/r0/backup/get_backup_key_sessions.rs | 5 +++-- .../ruma-client-api/src/r0/backup/get_backup_keys.rs | 5 +++-- .../ruma-client-api/src/r0/backup/get_latest_backup.rs | 10 ++++++++-- crates/ruma-client-api/src/r0/backup/update_backup.rs | 5 +++-- 10 files changed, 40 insertions(+), 20 deletions(-) diff --git a/crates/ruma-client-api/src/r0/backup.rs b/crates/ruma-client-api/src/r0/backup.rs index 0881f6b8..c2e9f0cd 100644 --- a/crates/ruma-client-api/src/r0/backup.rs +++ b/crates/ruma-client-api/src/r0/backup.rs @@ -19,6 +19,7 @@ use std::collections::BTreeMap; use js_int::UInt; use ruma_identifiers::{DeviceKeyId, UserId}; +use ruma_serde::Raw; use serde::{Deserialize, Serialize}; /// A wrapper around a mapping of session IDs to key data. @@ -26,12 +27,12 @@ use serde::{Deserialize, Serialize}; #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct RoomKeyBackup { /// A map of session IDs to key data. - pub sessions: BTreeMap, + pub sessions: BTreeMap>, } impl RoomKeyBackup { /// Creates a new `RoomKeyBackup` with the given sessions. - pub fn new(sessions: BTreeMap) -> Self { + pub fn new(sessions: BTreeMap>) -> Self { Self { sessions } } } diff --git a/crates/ruma-client-api/src/r0/backup/add_backup_key_session.rs b/crates/ruma-client-api/src/r0/backup/add_backup_key_session.rs index 326a820b..8cb5161a 100644 --- a/crates/ruma-client-api/src/r0/backup/add_backup_key_session.rs +++ b/crates/ruma-client-api/src/r0/backup/add_backup_key_session.rs @@ -3,6 +3,7 @@ use js_int::UInt; use ruma_api::ruma_api; use ruma_identifiers::RoomId; +use ruma_serde::Raw; use super::KeyBackupData; @@ -33,7 +34,7 @@ ruma_api! { /// The key information to backup. #[ruma_api(body)] - pub session_data: KeyBackupData, + pub session_data: Raw, } response: { @@ -56,7 +57,7 @@ impl<'a> Request<'a> { version: &'a str, room_id: &'a RoomId, session_id: &'a str, - session_data: KeyBackupData, + session_data: Raw, ) -> Self { Self { version, room_id, session_id, session_data } } diff --git a/crates/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs b/crates/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs index 4866d52a..dea7f3fd 100644 --- a/crates/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs +++ b/crates/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs @@ -5,6 +5,7 @@ use std::collections::BTreeMap; use js_int::UInt; use ruma_api::ruma_api; use ruma_identifiers::RoomId; +use ruma_serde::Raw; use super::KeyBackupData; @@ -30,7 +31,7 @@ ruma_api! { pub room_id: &'a RoomId, /// A map from session IDs to key data. - pub sessions: BTreeMap, + pub sessions: BTreeMap>, } response: { @@ -52,7 +53,7 @@ impl<'a> Request<'a> { pub fn new( version: &'a str, room_id: &'a RoomId, - sessions: BTreeMap, + sessions: BTreeMap>, ) -> Self { Self { version, room_id, sessions } } diff --git a/crates/ruma-client-api/src/r0/backup/create_backup.rs b/crates/ruma-client-api/src/r0/backup/create_backup.rs index d53c04da..60499b89 100644 --- a/crates/ruma-client-api/src/r0/backup/create_backup.rs +++ b/crates/ruma-client-api/src/r0/backup/create_backup.rs @@ -1,6 +1,7 @@ //! [POST /_matrix/client/r0/room_keys/version](https://matrix.org/docs/spec/client_server/unstable#post-matrix-client-r0-room-keys-version) use ruma_api::ruma_api; +use ruma_serde::Raw; use super::BackupAlgorithm; @@ -17,7 +18,7 @@ ruma_api! { request: { /// The algorithm used for storing backups. #[serde(flatten)] - pub algorithm: BackupAlgorithm, + pub algorithm: Raw, } response: { @@ -30,7 +31,7 @@ ruma_api! { impl Request { /// Creates a new `Request` with the given backup algorithm. - pub fn new(algorithm: BackupAlgorithm) -> Self { + pub fn new(algorithm: Raw) -> Self { Self { algorithm } } } diff --git a/crates/ruma-client-api/src/r0/backup/get_backup.rs b/crates/ruma-client-api/src/r0/backup/get_backup.rs index 94e1c508..d27681cc 100644 --- a/crates/ruma-client-api/src/r0/backup/get_backup.rs +++ b/crates/ruma-client-api/src/r0/backup/get_backup.rs @@ -2,6 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; +use ruma_serde::Raw; use super::BackupAlgorithm; @@ -24,7 +25,7 @@ ruma_api! { response: { /// The algorithm used for storing backups. #[serde(flatten)] - pub algorithm: BackupAlgorithm, + pub algorithm: Raw, /// The number of keys stored in the backup. pub count: UInt, @@ -51,7 +52,12 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the gien algorithm, key count, etag and version. - pub fn new(algorithm: BackupAlgorithm, count: UInt, etag: String, version: String) -> Self { + pub fn new( + algorithm: Raw, + count: UInt, + etag: String, + version: String, + ) -> Self { Self { algorithm, count, etag, version } } } diff --git a/crates/ruma-client-api/src/r0/backup/get_backup_key_session.rs b/crates/ruma-client-api/src/r0/backup/get_backup_key_session.rs index aba08173..751dd6e5 100644 --- a/crates/ruma-client-api/src/r0/backup/get_backup_key_session.rs +++ b/crates/ruma-client-api/src/r0/backup/get_backup_key_session.rs @@ -2,6 +2,7 @@ use ruma_api::ruma_api; use ruma_identifiers::RoomId; +use ruma_serde::Raw; use super::KeyBackupData; @@ -34,7 +35,7 @@ ruma_api! { response: { /// Information about the requested backup key. #[ruma_api(body)] - pub key_data: KeyBackupData, + pub key_data: Raw, } error: crate::Error @@ -49,7 +50,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given key_data. - pub fn new(key_data: KeyBackupData) -> Self { + pub fn new(key_data: Raw) -> Self { Self { key_data } } } diff --git a/crates/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs b/crates/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs index 78a13e1c..e2469db7 100644 --- a/crates/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs +++ b/crates/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs @@ -4,6 +4,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_identifiers::RoomId; +use ruma_serde::Raw; use super::KeyBackupData; @@ -31,7 +32,7 @@ ruma_api! { response: { /// A map of session IDs to key data. - pub sessions: BTreeMap, + pub sessions: BTreeMap>, } error: crate::Error @@ -46,7 +47,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given sessions. - pub fn new(sessions: BTreeMap) -> Self { + pub fn new(sessions: BTreeMap>) -> Self { Self { sessions } } } diff --git a/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs b/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs index ec02a48a..d3bad070 100644 --- a/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs +++ b/crates/ruma-client-api/src/r0/backup/get_backup_keys.rs @@ -4,6 +4,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_identifiers::RoomId; +use ruma_serde::Raw; use super::RoomKeyBackup; @@ -27,7 +28,7 @@ ruma_api! { response: { /// A map from room IDs to session IDs to key data. - pub rooms: BTreeMap, RoomKeyBackup>, + pub rooms: BTreeMap, Raw>, } error: crate::Error @@ -42,7 +43,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given room key backups. - pub fn new(rooms: BTreeMap, RoomKeyBackup>) -> Self { + pub fn new(rooms: BTreeMap, Raw>) -> Self { Self { rooms } } } diff --git a/crates/ruma-client-api/src/r0/backup/get_latest_backup.rs b/crates/ruma-client-api/src/r0/backup/get_latest_backup.rs index c855ed4d..3a0d9124 100644 --- a/crates/ruma-client-api/src/r0/backup/get_latest_backup.rs +++ b/crates/ruma-client-api/src/r0/backup/get_latest_backup.rs @@ -2,6 +2,7 @@ use js_int::UInt; use ruma_api::ruma_api; +use ruma_serde::Raw; use super::BackupAlgorithm; @@ -21,7 +22,7 @@ ruma_api! { response: { /// The algorithm used for storing backups. #[serde(flatten)] - pub algorithm: BackupAlgorithm, + pub algorithm: Raw, /// The number of keys stored in the backup. pub count: UInt, @@ -48,7 +49,12 @@ impl Request { impl Response { /// Creates a new `Response` with the given algorithm, key count, etag and version. - pub fn new(algorithm: BackupAlgorithm, count: UInt, etag: String, version: String) -> Self { + pub fn new( + algorithm: Raw, + count: UInt, + etag: String, + version: String, + ) -> Self { Self { algorithm, count, etag, version } } } diff --git a/crates/ruma-client-api/src/r0/backup/update_backup.rs b/crates/ruma-client-api/src/r0/backup/update_backup.rs index 789ccc2b..3f423287 100644 --- a/crates/ruma-client-api/src/r0/backup/update_backup.rs +++ b/crates/ruma-client-api/src/r0/backup/update_backup.rs @@ -1,6 +1,7 @@ //! [POST /_matrix/client/r0/room_keys/version](https://matrix.org/docs/spec/client_server/unstable#post-matrix-client-r0-room-keys-version) use ruma_api::ruma_api; +use ruma_serde::Raw; use super::BackupAlgorithm; @@ -21,7 +22,7 @@ ruma_api! { /// The algorithm used for storing backups. #[serde(flatten)] - pub algorithm: BackupAlgorithm, + pub algorithm: Raw, } #[derive(Default)] @@ -32,7 +33,7 @@ ruma_api! { impl<'a> Request<'a> { /// Creates a new `Request` with the given backup version and algorithm. - pub fn new(version: &'a str, algorithm: BackupAlgorithm) -> Self { + pub fn new(version: &'a str, algorithm: Raw) -> Self { Self { version, algorithm } } }