From c769d9602d3fcf3ace27a4e21a13082f2d39853f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 2 Feb 2021 18:46:31 +0100 Subject: [PATCH] client-api: Remove unstable-synapse-quirks from key backups The spec has been adjusted to follow Synapse. --- ruma-client-api/src/r0/backup.rs | 20 ++++--------------- .../src/r0/backup/add_backup_key_session.rs | 6 +++--- .../src/r0/backup/add_backup_key_sessions.rs | 10 +++++++--- .../src/r0/backup/add_backup_keys.rs | 13 ++++++------ .../src/r0/backup/get_backup_key_session.rs | 6 +++--- .../src/r0/backup/get_backup_key_sessions.rs | 6 +++--- .../src/r0/backup/get_backup_keys.rs | 15 +++++++------- 7 files changed, 35 insertions(+), 41 deletions(-) diff --git a/ruma-client-api/src/r0/backup.rs b/ruma-client-api/src/r0/backup.rs index 7840f380..ba253fb2 100644 --- a/ruma-client-api/src/r0/backup.rs +++ b/ruma-client-api/src/r0/backup.rs @@ -17,27 +17,15 @@ pub mod get_latest_backup; pub mod update_backup; use js_int::UInt; -use ruma_identifiers::{DeviceKeyId, RoomId, UserId}; +use ruma_identifiers::{DeviceKeyId, UserId}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; -/// A map from room IDs to session IDs to key data. -/// -/// Note: synapse has the `sessions: {}` wrapper, the Matrix spec does not. -#[cfg(not(feature = "unstable-synapse-quirks"))] -pub type Rooms = BTreeMap>; - -/// A map from room IDs to session IDs to key data. -#[cfg(feature = "unstable-synapse-quirks")] -pub type Rooms = BTreeMap; - -// TODO: remove /// A wrapper around a mapping of session IDs to key data. -#[cfg(feature = "unstable-synapse-quirks")] #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Sessions { +pub struct RoomKeyBackup { /// A map of session IDs to key data. - pub sessions: BTreeMap, + pub sessions: BTreeMap, } /// The algorithm used for storing backups. @@ -57,7 +45,7 @@ pub enum BackupAlgorithm { /// Information about the backup key. #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct KeyData { +pub struct KeyBackupData { /// The index of the first message in the session that the key can decrypt. pub first_message_index: UInt, 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 index 02e8e7a6..c2c097b7 100644 --- a/ruma-client-api/src/r0/backup/add_backup_key_session.rs +++ b/ruma-client-api/src/r0/backup/add_backup_key_session.rs @@ -4,7 +4,7 @@ use js_int::UInt; use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use super::KeyData; +use super::KeyBackupData; ruma_api! { metadata: { @@ -31,7 +31,7 @@ ruma_api! { /// The key information to backup. #[ruma_api(body)] - pub session_data: KeyData, + pub session_data: KeyBackupData, } response: { @@ -52,7 +52,7 @@ impl<'a> Request<'a> { version: &'a str, room_id: &'a RoomId, session_id: &'a str, - session_data: KeyData, + session_data: KeyBackupData, ) -> Self { Self { version, room_id, session_id, session_data } } 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 index a0b2fbe5..ba30668c 100644 --- a/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs +++ b/ruma-client-api/src/r0/backup/add_backup_key_sessions.rs @@ -6,7 +6,7 @@ use js_int::UInt; use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use super::KeyData; +use super::KeyBackupData; ruma_api! { metadata: { @@ -28,7 +28,7 @@ ruma_api! { pub room_id: &'a RoomId, /// A map from session IDs to key data. - pub sessions: BTreeMap, + pub sessions: BTreeMap, } response: { @@ -45,7 +45,11 @@ ruma_api! { 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 { + pub fn new( + version: &'a str, + room_id: &'a RoomId, + sessions: BTreeMap, + ) -> Self { Self { version, room_id, sessions } } } diff --git a/ruma-client-api/src/r0/backup/add_backup_keys.rs b/ruma-client-api/src/r0/backup/add_backup_keys.rs index aeb2b259..82b5a3bb 100644 --- a/ruma-client-api/src/r0/backup/add_backup_keys.rs +++ b/ruma-client-api/src/r0/backup/add_backup_keys.rs @@ -1,9 +1,12 @@ //! [PUT /_matrix/client/r0/room_keys/keys](https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-keys) +use std::collections::BTreeMap; + use js_int::UInt; use ruma_api::ruma_api; +use ruma_identifiers::RoomId; -use super::Rooms; +use super::RoomKeyBackup; ruma_api! { metadata: { @@ -21,9 +24,7 @@ ruma_api! { pub version: &'a str, /// A map from room IDs to session IDs to key data. - /// - /// Note: synapse has the `sessions: {}` wrapper, the Matrix spec does not. - pub rooms: Rooms, + pub rooms: BTreeMap, } response: { @@ -39,8 +40,8 @@ ruma_api! { } impl<'a> Request<'a> { - /// Creates a new `Request` with the given version. - pub fn new(version: &'a str, rooms: Rooms) -> Self { + /// Creates a new `Request` with the given version and room key backups. + pub fn new(version: &'a str, rooms: BTreeMap) -> Self { Self { version, rooms } } } 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 index 6b846a51..133c594b 100644 --- a/ruma-client-api/src/r0/backup/get_backup_key_session.rs +++ b/ruma-client-api/src/r0/backup/get_backup_key_session.rs @@ -3,7 +3,7 @@ use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use super::KeyData; +use super::KeyBackupData; ruma_api! { metadata: { @@ -32,7 +32,7 @@ ruma_api! { response: { /// Information about the requested backup key. #[ruma_api(body)] - pub key_data: KeyData, + pub key_data: KeyBackupData, } error: crate::Error @@ -47,7 +47,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given key_data. - pub fn new(key_data: KeyData) -> Self { + pub fn new(key_data: KeyBackupData) -> 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 index 1d4eac9c..dccc0bd8 100644 --- a/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs +++ b/ruma-client-api/src/r0/backup/get_backup_key_sessions.rs @@ -5,7 +5,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use super::KeyData; +use super::KeyBackupData; ruma_api! { metadata: { @@ -29,7 +29,7 @@ ruma_api! { response: { /// A map of session IDs to key data. - pub sessions: BTreeMap, + pub sessions: BTreeMap, } error: crate::Error @@ -44,7 +44,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/ruma-client-api/src/r0/backup/get_backup_keys.rs b/ruma-client-api/src/r0/backup/get_backup_keys.rs index d41c2d2d..04c66ecd 100644 --- a/ruma-client-api/src/r0/backup/get_backup_keys.rs +++ b/ruma-client-api/src/r0/backup/get_backup_keys.rs @@ -1,8 +1,11 @@ //! [GET /_matrix/client/r0/room_keys/keys](https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-keys) -use ruma_api::ruma_api; +use std::collections::BTreeMap; -use super::Rooms; +use ruma_api::ruma_api; +use ruma_identifiers::RoomId; + +use super::RoomKeyBackup; ruma_api! { metadata: { @@ -22,9 +25,7 @@ ruma_api! { response: { /// A map from room IDs to session IDs to key data. - /// - /// Note: synapse has the `sessions: {}` wrapper, the Matrix spec does not. - pub rooms: Rooms, + pub rooms: BTreeMap, } error: crate::Error @@ -38,8 +39,8 @@ impl<'a> Request<'a> { } impl Response { - /// Creates a new `Response` with the given rooms. - pub fn new(rooms: Rooms) -> Self { + /// Creates a new `Response` with the given room key backups. + pub fn new(rooms: BTreeMap) -> Self { Self { rooms } } }