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:
parent
786ab15c0c
commit
af0a8f009c
@ -19,6 +19,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_identifiers::{DeviceKeyId, UserId};
|
use ruma_identifiers::{DeviceKeyId, UserId};
|
||||||
|
use ruma_serde::Raw;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A wrapper around a mapping of session IDs to key data.
|
/// 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)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct RoomKeyBackup {
|
pub struct RoomKeyBackup {
|
||||||
/// A map of session IDs to key data.
|
/// A map of session IDs to key data.
|
||||||
pub sessions: BTreeMap<String, KeyBackupData>,
|
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoomKeyBackup {
|
impl RoomKeyBackup {
|
||||||
/// Creates a new `RoomKeyBackup` with the given sessions.
|
/// 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 }
|
Self { sessions }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::KeyBackupData;
|
use super::KeyBackupData;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The key information to backup.
|
/// The key information to backup.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub session_data: KeyBackupData,
|
pub session_data: Raw<KeyBackupData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {
|
response: {
|
||||||
@ -56,7 +57,7 @@ impl<'a> Request<'a> {
|
|||||||
version: &'a str,
|
version: &'a str,
|
||||||
room_id: &'a RoomId,
|
room_id: &'a RoomId,
|
||||||
session_id: &'a str,
|
session_id: &'a str,
|
||||||
session_data: KeyBackupData,
|
session_data: Raw<KeyBackupData>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { version, room_id, session_id, session_data }
|
Self { version, room_id, session_id, session_data }
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ use std::collections::BTreeMap;
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::KeyBackupData;
|
use super::KeyBackupData;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ ruma_api! {
|
|||||||
pub room_id: &'a RoomId,
|
pub room_id: &'a RoomId,
|
||||||
|
|
||||||
/// A map from session IDs to key data.
|
/// A map from session IDs to key data.
|
||||||
pub sessions: BTreeMap<String, KeyBackupData>,
|
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {
|
response: {
|
||||||
@ -52,7 +53,7 @@ impl<'a> Request<'a> {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
version: &'a str,
|
version: &'a str,
|
||||||
room_id: &'a RoomId,
|
room_id: &'a RoomId,
|
||||||
sessions: BTreeMap<String, KeyBackupData>,
|
sessions: BTreeMap<String, Raw<KeyBackupData>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { version, room_id, sessions }
|
Self { version, room_id, sessions }
|
||||||
}
|
}
|
||||||
|
@ -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)
|
//! [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_api::ruma_api;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::BackupAlgorithm;
|
use super::BackupAlgorithm;
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// The algorithm used for storing backups.
|
/// The algorithm used for storing backups.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub algorithm: BackupAlgorithm,
|
pub algorithm: Raw<BackupAlgorithm>,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {
|
response: {
|
||||||
@ -30,7 +31,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
/// Creates a new `Request` with the given backup algorithm.
|
/// Creates a new `Request` with the given backup algorithm.
|
||||||
pub fn new(algorithm: BackupAlgorithm) -> Self {
|
pub fn new(algorithm: Raw<BackupAlgorithm>) -> Self {
|
||||||
Self { algorithm }
|
Self { algorithm }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::BackupAlgorithm;
|
use super::BackupAlgorithm;
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ ruma_api! {
|
|||||||
response: {
|
response: {
|
||||||
/// The algorithm used for storing backups.
|
/// The algorithm used for storing backups.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub algorithm: BackupAlgorithm,
|
pub algorithm: Raw<BackupAlgorithm>,
|
||||||
|
|
||||||
/// The number of keys stored in the backup.
|
/// The number of keys stored in the backup.
|
||||||
pub count: UInt,
|
pub count: UInt,
|
||||||
@ -51,7 +52,12 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the gien algorithm, key count, etag and version.
|
/// 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 }
|
Self { algorithm, count, etag, version }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::KeyBackupData;
|
use super::KeyBackupData;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ ruma_api! {
|
|||||||
response: {
|
response: {
|
||||||
/// Information about the requested backup key.
|
/// Information about the requested backup key.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub key_data: KeyBackupData,
|
pub key_data: Raw<KeyBackupData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
error: crate::Error
|
error: crate::Error
|
||||||
@ -49,7 +50,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given key_data.
|
/// 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 }
|
Self { key_data }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::KeyBackupData;
|
use super::KeyBackupData;
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// A map of session IDs to key data.
|
/// A map of session IDs to key data.
|
||||||
pub sessions: BTreeMap<String, KeyBackupData>,
|
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
error: crate::Error
|
error: crate::Error
|
||||||
@ -46,7 +47,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given sessions.
|
/// 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 }
|
Self { sessions }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::RoomKeyBackup;
|
use super::RoomKeyBackup;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// A map from room IDs to session IDs to key data.
|
/// 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
|
error: crate::Error
|
||||||
@ -42,7 +43,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given room key backups.
|
/// 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 }
|
Self { rooms }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::BackupAlgorithm;
|
use super::BackupAlgorithm;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ ruma_api! {
|
|||||||
response: {
|
response: {
|
||||||
/// The algorithm used for storing backups.
|
/// The algorithm used for storing backups.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub algorithm: BackupAlgorithm,
|
pub algorithm: Raw<BackupAlgorithm>,
|
||||||
|
|
||||||
/// The number of keys stored in the backup.
|
/// The number of keys stored in the backup.
|
||||||
pub count: UInt,
|
pub count: UInt,
|
||||||
@ -48,7 +49,12 @@ impl Request {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given algorithm, key count, etag and version.
|
/// 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 }
|
Self { algorithm, count, etag, version }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
//! [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_api::ruma_api;
|
||||||
|
use ruma_serde::Raw;
|
||||||
|
|
||||||
use super::BackupAlgorithm;
|
use super::BackupAlgorithm;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The algorithm used for storing backups.
|
/// The algorithm used for storing backups.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub algorithm: BackupAlgorithm,
|
pub algorithm: Raw<BackupAlgorithm>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -32,7 +33,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given backup version and algorithm.
|
/// 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 }
|
Self { version, algorithm }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user