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.
This commit is contained in:
Damir Jelić 2021-12-03 13:15:35 +01:00 committed by Jonas Platte
parent 786ab15c0c
commit af0a8f009c
10 changed files with 40 additions and 20 deletions

View File

@ -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<String, KeyBackupData>,
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
}
impl RoomKeyBackup {
/// Creates a new `RoomKeyBackup` with the given sessions.
pub fn new(sessions: BTreeMap<String, KeyBackupData>) -> Self {
pub fn new(sessions: BTreeMap<String, Raw<KeyBackupData>>) -> Self {
Self { sessions }
}
}

View File

@ -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<KeyBackupData>,
}
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<KeyBackupData>,
) -> Self {
Self { version, room_id, session_id, session_data }
}

View File

@ -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<String, KeyBackupData>,
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
}
response: {
@ -52,7 +53,7 @@ impl<'a> Request<'a> {
pub fn new(
version: &'a str,
room_id: &'a RoomId,
sessions: BTreeMap<String, KeyBackupData>,
sessions: BTreeMap<String, Raw<KeyBackupData>>,
) -> Self {
Self { version, room_id, sessions }
}

View File

@ -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<BackupAlgorithm>,
}
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<BackupAlgorithm>) -> Self {
Self { algorithm }
}
}

View File

@ -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<BackupAlgorithm>,
/// 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<BackupAlgorithm>,
count: UInt,
etag: String,
version: String,
) -> Self {
Self { algorithm, count, etag, version }
}
}

View File

@ -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<KeyBackupData>,
}
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<KeyBackupData>) -> Self {
Self { key_data }
}
}

View File

@ -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<String, KeyBackupData>,
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
}
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<String, KeyBackupData>) -> Self {
pub fn new(sessions: BTreeMap<String, Raw<KeyBackupData>>) -> Self {
Self { sessions }
}
}

View File

@ -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<Box<RoomId>, RoomKeyBackup>,
pub rooms: BTreeMap<Box<RoomId>, Raw<RoomKeyBackup>>,
}
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<Box<RoomId>, RoomKeyBackup>) -> Self {
pub fn new(rooms: BTreeMap<Box<RoomId>, Raw<RoomKeyBackup>>) -> Self {
Self { rooms }
}
}

View File

@ -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<BackupAlgorithm>,
/// 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<BackupAlgorithm>,
count: UInt,
etag: String,
version: String,
) -> Self {
Self { algorithm, count, etag, version }
}
}

View File

@ -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<BackupAlgorithm>,
}
#[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<BackupAlgorithm>) -> Self {
Self { version, algorithm }
}
}