client-api: Update backup endpoints to the new API standards
This commit is contained in:
parent
fec07a7426
commit
cf9b83495c
@ -8,10 +8,20 @@ pub mod get_latest_backup;
|
||||
pub mod update_backup;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{DeviceKeyId, UserId};
|
||||
use ruma_identifiers::{DeviceKeyId, RoomId, 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<RoomId, BTreeMap<String, KeyData>>;
|
||||
|
||||
/// A map from room IDs to session IDs to key data.
|
||||
#[cfg(feature = "unstable-synapse-quirks")]
|
||||
pub type Rooms = BTreeMap<RoomId, Sessions>;
|
||||
|
||||
// TODO: remove
|
||||
/// A wrapper around a mapping of session IDs to key data.
|
||||
#[cfg(feature = "unstable-synapse-quirks")]
|
||||
@ -30,6 +40,7 @@ pub enum BackupAlgorithm {
|
||||
MegolmBackupV1Curve25519AesSha2 {
|
||||
/// The curve25519 public key used to encrypt the backups, encoded in unpadded base64.
|
||||
public_key: String,
|
||||
|
||||
/// Signatures of the auth_data as Signed JSON.
|
||||
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
},
|
||||
@ -40,10 +51,13 @@ pub enum BackupAlgorithm {
|
||||
pub struct KeyData {
|
||||
/// The index of the first message in the session that the key can decrypt.
|
||||
pub first_message_index: UInt,
|
||||
|
||||
/// The number of times this key has been forwarded via key-sharing between devices.
|
||||
pub forwarded_count: UInt,
|
||||
|
||||
/// Whether the device backing up the key verified the device that the key is from.
|
||||
pub is_verified: bool,
|
||||
|
||||
/// Data about the session.
|
||||
pub session_data: SessionData,
|
||||
}
|
||||
@ -53,8 +67,10 @@ pub struct KeyData {
|
||||
pub struct SessionData {
|
||||
/// Unpadded base64-encoded public half of the ephemeral key.
|
||||
pub ephemeral: String,
|
||||
|
||||
/// Ciphertext, encrypted using AES-CBC-256 with PKCS#7 padding, encoded in base64.
|
||||
pub ciphertext: String,
|
||||
|
||||
/// First 8 bytes of MAC key, encoded in base64.
|
||||
pub mac: String,
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
//! [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;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -16,22 +15,19 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The backup version. Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: String,
|
||||
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.
|
||||
#[cfg(feature = "unstable-synapse-quirks")]
|
||||
pub rooms: BTreeMap<RoomId, super::Sessions>,
|
||||
|
||||
/// A map from room IDs to session IDs to key data.
|
||||
#[cfg(not(feature = "unstable-synapse-quirks"))]
|
||||
pub rooms: BTreeMap<RoomId, BTreeMap<String, super::KeyData>>,
|
||||
pub rooms: Rooms,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
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.
|
||||
@ -43,3 +39,17 @@ ruma_api! {
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given version.
|
||||
pub fn new(version: &'a str, rooms: Rooms) -> Self {
|
||||
Self { version, rooms }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given etag and key count.
|
||||
pub fn new(etag: String, count: UInt) -> Self {
|
||||
Self { etag, count }
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::BackupAlgorithm;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Creates a new backup.",
|
||||
@ -12,12 +14,14 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The algorithm used for storing backups.
|
||||
#[serde(flatten)]
|
||||
pub algorithm: super::BackupAlgorithm,
|
||||
pub algorithm: BackupAlgorithm,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// The backup version. This is an opaque string.
|
||||
pub version: String,
|
||||
@ -25,3 +29,17 @@ ruma_api! {
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given backup algorithm.
|
||||
pub fn new(algorithm: BackupAlgorithm) -> Self {
|
||||
Self { algorithm }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given version.
|
||||
pub fn new(version: String) -> Self {
|
||||
Self { version }
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::BackupAlgorithm;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get information about an existing backup.",
|
||||
@ -13,16 +15,18 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The backup version.
|
||||
#[ruma_api(path)]
|
||||
pub version: String,
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// The algorithm used for storing backups.
|
||||
#[serde(flatten)]
|
||||
pub algorithm: super::BackupAlgorithm,
|
||||
pub algorithm: BackupAlgorithm,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
@ -37,3 +41,17 @@ ruma_api! {
|
||||
|
||||
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 a new `Response` with the gien algorithm, key count, etag and version.
|
||||
pub fn new(algorithm: BackupAlgorithm, count: UInt, etag: String, version: String) -> Self {
|
||||
Self { algorithm, count, etag, version }
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
//! [GET /_matrix/client/r0/room_keys/keys](https://matrix.org/docs/spec/client_server/unstable#get-matrix-client-r0-room-keys-keys)
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
|
||||
use super::Rooms;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -15,23 +14,34 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The backup version. Must be the current backup.
|
||||
#[ruma_api(query)]
|
||||
pub version: String,
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// A map from room IDs to session IDs to key data.
|
||||
///
|
||||
/// Note: synapse has the `sessions: {}` wrapper, the Matrix spec does not.
|
||||
#[cfg(feature = "unstable-synapse-quirks")]
|
||||
pub rooms: BTreeMap<RoomId, super::Sessions>,
|
||||
|
||||
/// A map from room IDs to session IDs to key data.
|
||||
#[cfg(not(feature = "unstable-synapse-quirks"))]
|
||||
pub rooms: BTreeMap<RoomId, BTreeMap<String, super::KeyData>>,
|
||||
pub rooms: Rooms,
|
||||
}
|
||||
|
||||
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 a new `Response` with the given rooms.
|
||||
pub fn new(rooms: Rooms) -> Self {
|
||||
Self { rooms }
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::BackupAlgorithm;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Get information about the latest backup.",
|
||||
@ -13,12 +15,15 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
request: {}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// The algorithm used for storing backups.
|
||||
#[serde(flatten)]
|
||||
pub algorithm: super::BackupAlgorithm,
|
||||
pub algorithm: BackupAlgorithm,
|
||||
|
||||
/// The number of keys stored in the backup.
|
||||
pub count: UInt,
|
||||
@ -33,3 +38,17 @@ ruma_api! {
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
Self { algorithm, count, etag, version }
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::BackupAlgorithm;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Update information about an existing backup.",
|
||||
@ -12,17 +14,34 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The backup version.
|
||||
#[ruma_api(path)]
|
||||
pub version: String,
|
||||
pub version: &'a str,
|
||||
|
||||
/// The algorithm used for storing backups.
|
||||
#[serde(flatten)]
|
||||
pub algorithm: super::BackupAlgorithm,
|
||||
pub algorithm: BackupAlgorithm,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
response: {}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given backup version and algorithm.
|
||||
pub fn new(version: &'a str, algorithm: BackupAlgorithm) -> Self {
|
||||
Self { version, algorithm }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user