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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, OwnedEventId, PrivOwnedStr};
pub mod accept;
pub mod cancel;
pub mod done;
pub mod key;
pub mod mac;
pub mod ready;
pub mod request;
pub mod start;
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum HashAlgorithm {
Sha256,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
impl HashAlgorithm {
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum KeyAgreementProtocol {
Curve25519,
Curve25519HkdfSha256,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
impl KeyAgreementProtocol {
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum MessageAuthenticationCode {
HkdfHmacSha256,
HmacSha256,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
impl MessageAuthenticationCode {
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ShortAuthenticationString {
Decimal,
Emoji,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
impl ShortAuthenticationString {
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "rel_type", rename = "m.reference")]
pub struct Relation {
pub event_id: OwnedEventId,
}
impl Relation {
pub fn new(event_id: OwnedEventId) -> Self {
Self { event_id }
}
}
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum VerificationMethod {
#[ruma_enum(rename = "m.sas.v1")]
SasV1,
#[ruma_enum(rename = "m.qr_code.scan.v1")]
QrCodeScanV1,
#[ruma_enum(rename = "m.qr_code.show.v1")]
QrCodeShowV1,
#[ruma_enum(rename = "m.reciprocate.v1")]
ReciprocateV1,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
impl VerificationMethod {
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
#[cfg(test)]
mod tests {
use serde_json::{from_value as from_json_value, json};
use super::{KeyAgreementProtocol, MessageAuthenticationCode};
#[test]
fn serialize_key_agreement() {
let serialized =
serde_json::to_string(&KeyAgreementProtocol::Curve25519HkdfSha256).unwrap();
assert_eq!(serialized, "\"curve25519-hkdf-sha256\"");
let deserialized: KeyAgreementProtocol = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized, KeyAgreementProtocol::Curve25519HkdfSha256);
}
#[test]
fn deserialize_mac_method() {
let json = json!(["hkdf-hmac-sha256", "hmac-sha256"]);
let deserialized: Vec<MessageAuthenticationCode> = from_json_value(json).unwrap();
assert!(deserialized.contains(&MessageAuthenticationCode::HkdfHmacSha256));
}
#[test]
fn serialize_mac_method() {
let serialized = serde_json::to_string(&MessageAuthenticationCode::HkdfHmacSha256).unwrap();
let deserialized: MessageAuthenticationCode = serde_json::from_str(&serialized).unwrap();
assert_eq!(serialized, "\"hkdf-hmac-sha256\"");
assert_eq!(deserialized, MessageAuthenticationCode::HkdfHmacSha256);
let serialized = serde_json::to_string(&MessageAuthenticationCode::HmacSha256).unwrap();
let deserialized: MessageAuthenticationCode = serde_json::from_str(&serialized).unwrap();
assert_eq!(serialized, "\"hmac-sha256\"");
assert_eq!(deserialized, MessageAuthenticationCode::HmacSha256);
}
}