ruma_events/key/verification/mac.rs
1//! Types for the [`m.key.verification.mac`] event.
2//!
3//! [`m.key.verification.mac`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationmac
4
5use std::collections::BTreeMap;
6
7use ruma_common::{serde::Base64, OwnedTransactionId};
8use ruma_macros::EventContent;
9use serde::{Deserialize, Serialize};
10
11use crate::relation::Reference;
12
13/// The content of a to-device `m.key.verification.` event.
14///
15/// Sends the MAC of a device's key to the partner device.
16#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
17#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
18#[ruma_event(type = "m.key.verification.mac", kind = ToDevice)]
19pub struct ToDeviceKeyVerificationMacEventContent {
20 /// An opaque identifier for the verification process.
21 ///
22 /// Must be the same as the one used for the `m.key.verification.start` message.
23 pub transaction_id: OwnedTransactionId,
24
25 /// A map of the key ID to the MAC of the key, using the algorithm in the verification process.
26 ///
27 /// The MAC is encoded as unpadded base64.
28 pub mac: BTreeMap<String, Base64>,
29
30 /// The MAC of the comma-separated, sorted, list of key IDs given in the `mac` property,
31 /// encoded as unpadded base64.
32 pub keys: Base64,
33}
34
35impl ToDeviceKeyVerificationMacEventContent {
36 /// Creates a new `ToDeviceKeyVerificationMacEventContent` with the given transaction ID, key ID
37 /// to MAC map and key MAC.
38 pub fn new(
39 transaction_id: OwnedTransactionId,
40 mac: BTreeMap<String, Base64>,
41 keys: Base64,
42 ) -> Self {
43 Self { transaction_id, mac, keys }
44 }
45}
46
47/// The content of an in-room `m.key.verification.` event.
48///
49/// Sends the MAC of a device's key to the partner device.
50#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
51#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
52#[ruma_event(type = "m.key.verification.mac", kind = MessageLike)]
53pub struct KeyVerificationMacEventContent {
54 /// A map of the key ID to the MAC of the key, using the algorithm in the verification process.
55 ///
56 /// The MAC is encoded as unpadded base64.
57 pub mac: BTreeMap<String, Base64>,
58
59 /// The MAC of the comma-separated, sorted, list of key IDs given in the `mac` property,
60 /// encoded as unpadded base64.
61 pub keys: Base64,
62
63 /// Information about the related event.
64 #[serde(rename = "m.relates_to")]
65 pub relates_to: Reference,
66}
67
68impl KeyVerificationMacEventContent {
69 /// Creates a new `KeyVerificationMacEventContent` with the given key ID to MAC map, key MAC and
70 /// reference.
71 pub fn new(mac: BTreeMap<String, Base64>, keys: Base64, relates_to: Reference) -> Self {
72 Self { mac, keys, relates_to }
73 }
74}