ruwuma/crates/ruma-client-api/src/r0/backup/add_backup_key_session.rs
Damir Jelić af0a8f009c 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.
2021-12-06 11:26:14 +01:00

72 lines
1.9 KiB
Rust

//! [PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}](https://matrix.org/docs/spec/client_server/unstable#put-matrix-client-r0-room-keys-keys-roomid-sessionid)
use js_int::UInt;
use ruma_api::ruma_api;
use ruma_identifiers::RoomId;
use ruma_serde::Raw;
use super::KeyBackupData;
ruma_api! {
metadata: {
description: "Store several keys in the backup.",
method: PUT,
name: "add_backup_key_session",
path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id",
rate_limited: true,
authentication: AccessToken,
}
request: {
/// The backup version.
///
/// Must be the current backup.
#[ruma_api(query)]
pub version: &'a str,
/// The ID of the room that the requested key is for.
#[ruma_api(path)]
pub room_id: &'a RoomId,
/// The ID of the megolm session whose key is requested.
#[ruma_api(path)]
pub session_id: &'a str,
/// The key information to backup.
#[ruma_api(body)]
pub session_data: Raw<KeyBackupData>,
}
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.
pub etag: String,
/// The number of keys stored in the backup.
pub count: UInt,
}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given version, room_id, session_id and session_data.
pub fn new(
version: &'a str,
room_id: &'a RoomId,
session_id: &'a str,
session_data: Raw<KeyBackupData>,
) -> Self {
Self { version, room_id, session_id, session_data }
}
}
impl Response {
/// Creates an new `Response` with the given etag and count.
pub fn new(etag: String, count: UInt) -> Self {
Self { etag, count }
}
}