ruma_events/key/
verification.rs
1use std::time::Duration;
11
12use ruma_common::serde::StringEnum;
13
14use crate::PrivOwnedStr;
15
16pub mod accept;
17pub mod cancel;
18pub mod done;
19pub mod key;
20pub mod mac;
21pub mod ready;
22pub mod request;
23pub mod start;
24
25pub const REQUEST_TIMESTAMP_TIMEOUT: Duration = Duration::from_secs(10 * 60);
31
32pub const REQUEST_RECEIVED_TIMEOUT: Duration = Duration::from_secs(2 * 60);
37
38#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
40#[derive(Clone, PartialEq, Eq, StringEnum)]
41#[ruma_enum(rename_all = "snake_case")]
42#[non_exhaustive]
43pub enum HashAlgorithm {
44 Sha256,
46
47 #[doc(hidden)]
48 _Custom(PrivOwnedStr),
49}
50
51#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
53#[derive(Clone, PartialEq, Eq, StringEnum)]
54#[ruma_enum(rename_all = "kebab-case")]
55#[non_exhaustive]
56pub enum KeyAgreementProtocol {
57 Curve25519,
59
60 Curve25519HkdfSha256,
62
63 #[doc(hidden)]
64 _Custom(PrivOwnedStr),
65}
66
67#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
69#[derive(Clone, PartialEq, Eq, StringEnum)]
70#[ruma_enum(rename_all = "kebab-case")]
71#[non_exhaustive]
72pub enum MessageAuthenticationCode {
73 #[deprecated = "Since Matrix 1.6. Use HkdfHmacSha256V2 instead."]
75 HkdfHmacSha256,
76
77 #[ruma_enum(rename = "hkdf-hmac-sha256.v2")]
79 HkdfHmacSha256V2,
80
81 HmacSha256,
83
84 #[doc(hidden)]
85 _Custom(PrivOwnedStr),
86}
87
88#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
90#[derive(Clone, PartialEq, Eq, StringEnum)]
91#[ruma_enum(rename_all = "snake_case")]
92#[non_exhaustive]
93pub enum ShortAuthenticationString {
94 Decimal,
96
97 Emoji,
99
100 #[doc(hidden)]
101 _Custom(PrivOwnedStr),
102}
103
104#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
106#[derive(Clone, PartialEq, Eq, StringEnum)]
107#[non_exhaustive]
108pub enum VerificationMethod {
109 #[ruma_enum(rename = "m.sas.v1")]
111 SasV1,
112
113 #[ruma_enum(rename = "m.qr_code.scan.v1")]
115 QrCodeScanV1,
116
117 #[ruma_enum(rename = "m.qr_code.show.v1")]
119 QrCodeShowV1,
120
121 #[ruma_enum(rename = "m.reciprocate.v1")]
123 ReciprocateV1,
124
125 #[doc(hidden)]
126 _Custom(PrivOwnedStr),
127}
128
129#[cfg(test)]
130mod tests {
131 use serde_json::{from_value as from_json_value, json};
132
133 use super::{KeyAgreementProtocol, MessageAuthenticationCode};
134
135 #[test]
136 fn serialize_key_agreement() {
137 let serialized =
138 serde_json::to_string(&KeyAgreementProtocol::Curve25519HkdfSha256).unwrap();
139 assert_eq!(serialized, "\"curve25519-hkdf-sha256\"");
140
141 let deserialized: KeyAgreementProtocol = serde_json::from_str(&serialized).unwrap();
142 assert_eq!(deserialized, KeyAgreementProtocol::Curve25519HkdfSha256);
143 }
144
145 #[test]
146 #[allow(deprecated)]
147 fn deserialize_mac_method() {
148 let json = json!(["hkdf-hmac-sha256", "hmac-sha256"]);
149
150 let deserialized: Vec<MessageAuthenticationCode> = from_json_value(json).unwrap();
151 assert!(deserialized.contains(&MessageAuthenticationCode::HkdfHmacSha256));
152 }
153
154 #[test]
155 #[allow(deprecated)]
156 fn serialize_mac_method() {
157 let serialized = serde_json::to_string(&MessageAuthenticationCode::HkdfHmacSha256).unwrap();
158 let deserialized: MessageAuthenticationCode = serde_json::from_str(&serialized).unwrap();
159 assert_eq!(serialized, "\"hkdf-hmac-sha256\"");
160 assert_eq!(deserialized, MessageAuthenticationCode::HkdfHmacSha256);
161
162 let serialized = serde_json::to_string(&MessageAuthenticationCode::HmacSha256).unwrap();
163 let deserialized: MessageAuthenticationCode = serde_json::from_str(&serialized).unwrap();
164 assert_eq!(serialized, "\"hmac-sha256\"");
165 assert_eq!(deserialized, MessageAuthenticationCode::HmacSha256);
166 }
167
168 #[test]
169 fn serialize_mac_method_v2() {
170 let serialized =
171 serde_json::to_string(&MessageAuthenticationCode::HkdfHmacSha256V2).unwrap();
172 let deserialized: MessageAuthenticationCode = serde_json::from_str(&serialized).unwrap();
173
174 assert_eq!(serialized, "\"hkdf-hmac-sha256.v2\"");
175 assert_eq!(deserialized, MessageAuthenticationCode::HkdfHmacSha256V2);
176 }
177}