ruma_client_api/
backup.rs1pub mod add_backup_keys;
4pub mod add_backup_keys_for_room;
5pub mod add_backup_keys_for_session;
6pub mod create_backup_version;
7pub mod delete_backup_keys;
8pub mod delete_backup_keys_for_room;
9pub mod delete_backup_keys_for_session;
10pub mod delete_backup_version;
11pub mod get_backup_info;
12pub mod get_backup_keys;
13pub mod get_backup_keys_for_room;
14pub mod get_backup_keys_for_session;
15pub mod get_latest_backup_info;
16pub mod update_backup_version;
17
18use std::collections::BTreeMap;
19
20use js_int::UInt;
21use ruma_common::{
22 serde::{Base64, Raw},
23 CrossSigningOrDeviceSignatures,
24};
25use serde::{Deserialize, Serialize};
26
27#[derive(Clone, Debug, Serialize, Deserialize)]
29#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
30pub struct RoomKeyBackup {
31 pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
33}
34
35impl RoomKeyBackup {
36 pub fn new(sessions: BTreeMap<String, Raw<KeyBackupData>>) -> Self {
38 Self { sessions }
39 }
40}
41
42#[derive(Clone, Debug, Serialize, Deserialize)]
44#[serde(tag = "algorithm", content = "auth_data")]
45#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
46pub enum BackupAlgorithm {
47 #[serde(rename = "m.megolm_backup.v1.curve25519-aes-sha2")]
49 MegolmBackupV1Curve25519AesSha2 {
50 public_key: Base64,
52
53 signatures: CrossSigningOrDeviceSignatures,
55 },
56}
57
58#[derive(Clone, Debug, Serialize, Deserialize)]
63#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
64pub struct KeyBackupData {
65 pub first_message_index: UInt,
67
68 pub forwarded_count: UInt,
70
71 pub is_verified: bool,
73
74 pub session_data: EncryptedSessionData,
76}
77
78#[derive(Debug)]
83#[allow(clippy::exhaustive_structs)]
84pub struct KeyBackupDataInit {
85 pub first_message_index: UInt,
87
88 pub forwarded_count: UInt,
90
91 pub is_verified: bool,
93
94 pub session_data: EncryptedSessionData,
96}
97
98impl From<KeyBackupDataInit> for KeyBackupData {
99 fn from(init: KeyBackupDataInit) -> Self {
100 let KeyBackupDataInit { first_message_index, forwarded_count, is_verified, session_data } =
101 init;
102 Self { first_message_index, forwarded_count, is_verified, session_data }
103 }
104}
105
106#[derive(Clone, Debug, Serialize, Deserialize)]
111#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
112pub struct EncryptedSessionData {
113 pub ephemeral: Base64,
115
116 pub ciphertext: Base64,
118
119 pub mac: Base64,
121}
122
123#[derive(Debug)]
128#[allow(clippy::exhaustive_structs)]
129pub struct EncryptedSessionDataInit {
130 pub ephemeral: Base64,
132
133 pub ciphertext: Base64,
135
136 pub mac: Base64,
138}
139
140impl From<EncryptedSessionDataInit> for EncryptedSessionData {
141 fn from(init: EncryptedSessionDataInit) -> Self {
142 let EncryptedSessionDataInit { ephemeral, ciphertext, mac } = init;
143 Self { ephemeral, ciphertext, mac }
144 }
145}