ruma_client_api/backup/add_backup_keys.rs
1//! `PUT /_matrix/client/*/room_keys/keys`
2//!
3//! Store keys in the backup.
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#put_matrixclientv3room_keyskeys
9
10 use std::collections::BTreeMap;
11
12 use js_int::UInt;
13 use ruma_common::{
14 api::{request, response, Metadata},
15 metadata, OwnedRoomId,
16 };
17
18 use crate::backup::RoomKeyBackup;
19
20 const METADATA: Metadata = metadata! {
21 method: PUT,
22 rate_limited: true,
23 authentication: AccessToken,
24 history: {
25 unstable => "/_matrix/client/unstable/room_keys/keys",
26 1.1 => "/_matrix/client/v3/room_keys/keys",
27 }
28 };
29
30 /// Request type for the `add_backup_keys` endpoint.
31 #[request(error = crate::Error)]
32 pub struct Request {
33 /// The backup version to add keys to.
34 ///
35 /// Must be the current backup.
36 #[ruma_api(query)]
37 pub version: String,
38
39 /// A map of room IDs to session IDs to key data to store.
40 pub rooms: BTreeMap<OwnedRoomId, RoomKeyBackup>,
41 }
42
43 /// Response type for the `add_backup_keys` endpoint.
44 #[response(error = crate::Error)]
45 pub struct Response {
46 /// An opaque string representing stored keys in the backup.
47 ///
48 /// Clients can compare it with the etag value they received in the request of their last
49 /// key storage request.
50 pub etag: String,
51
52 /// The number of keys stored in the backup.
53 pub count: UInt,
54 }
55
56 impl Request {
57 /// Creates a new `Request` with the given version and room key backups.
58 pub fn new(version: String, rooms: BTreeMap<OwnedRoomId, RoomKeyBackup>) -> Self {
59 Self { version, rooms }
60 }
61 }
62
63 impl Response {
64 /// Creates a new `Response` with the given etag and key count.
65 pub fn new(etag: String, count: UInt) -> Self {
66 Self { etag, count }
67 }
68 }
69}