1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pub mod add_backup_keys;
pub mod add_backup_keys_for_room;
pub mod add_backup_keys_for_session;
pub mod create_backup_version;
pub mod delete_backup_keys;
pub mod delete_backup_keys_for_room;
pub mod delete_backup_keys_for_session;
pub mod delete_backup_version;
pub mod get_backup_info;
pub mod get_backup_keys;
pub mod get_backup_keys_for_room;
pub mod get_backup_keys_for_session;
pub mod get_latest_backup_info;
pub mod update_backup_version;
use std::collections::BTreeMap;
use js_int::UInt;
use ruma_common::{
serde::{Base64, Raw},
OwnedDeviceKeyId, OwnedUserId,
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct RoomKeyBackup {
pub sessions: BTreeMap<String, Raw<KeyBackupData>>,
}
impl RoomKeyBackup {
pub fn new(sessions: BTreeMap<String, Raw<KeyBackupData>>) -> Self {
Self { sessions }
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "algorithm", content = "auth_data")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum BackupAlgorithm {
#[serde(rename = "m.megolm_backup.v1.curve25519-aes-sha2")]
MegolmBackupV1Curve25519AesSha2 {
public_key: Base64,
signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>,
},
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct KeyBackupData {
pub first_message_index: UInt,
pub forwarded_count: UInt,
pub is_verified: bool,
pub session_data: SessionData,
}
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct KeyBackupDataInit {
pub first_message_index: UInt,
pub forwarded_count: UInt,
pub is_verified: bool,
pub session_data: SessionData,
}
impl From<KeyBackupDataInit> for KeyBackupData {
fn from(init: KeyBackupDataInit) -> Self {
let KeyBackupDataInit { first_message_index, forwarded_count, is_verified, session_data } =
init;
Self { first_message_index, forwarded_count, is_verified, session_data }
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct SessionData {
pub ephemeral: Base64,
pub ciphertext: Base64,
pub mac: Base64,
}
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct SessionDataInit {
pub ephemeral: Base64,
pub ciphertext: Base64,
pub mac: Base64,
}
impl From<SessionDataInit> for SessionData {
fn from(init: SessionDataInit) -> Self {
let SessionDataInit { ephemeral, ciphertext, mac } = init;
Self { ephemeral, ciphertext, mac }
}
}