ruma_events/forwarded_room_key.rs
1//! Types for the [`m.forwarded_room_key`] event.
2//!
3//! [`m.forwarded_room_key`]: https://spec.matrix.org/v1.19/client-server-api/#mforwarded_room_key
4
5use ruma_common::{EventEncryptionAlgorithm, OwnedRoomId};
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
8
9/// The content of an `m.forwarded_room_key` event.
10///
11/// To create an instance of this type, first create a `ToDeviceForwardedRoomKeyEventContentInit`
12/// and convert it via `ToDeviceForwardedRoomKeyEventContent::from` / `.into()`.
13#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
14#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
15#[ruma_event(type = "m.forwarded_room_key", kind = ToDevice)]
16pub struct ToDeviceForwardedRoomKeyEventContent {
17 /// The encryption algorithm the key in this event is to be used with.
18 pub algorithm: EventEncryptionAlgorithm,
19
20 /// The room where the key is used.
21 pub room_id: OwnedRoomId,
22
23 /// The Curve25519 key of the device which initiated the session originally.
24 pub sender_key: String,
25
26 /// The ID of the session that the key is for.
27 pub session_id: String,
28
29 /// The key to be exchanged.
30 pub session_key: String,
31
32 /// The Ed25519 key of the device which initiated the session originally.
33 ///
34 /// It is "claimed" because the receiving device has no way to tell that the original
35 /// room_key actually came from a device which owns the private part of this key unless
36 /// they have done device verification.
37 pub sender_claimed_ed25519_key: String,
38
39 /// Chain of Curve25519 keys.
40 ///
41 /// It starts out empty, but each time the key is forwarded to another device, the
42 /// previous sender in the chain is added to the end of the list. For example, if the
43 /// key is forwarded from A to B to C, this field is empty between A and B, and contains
44 /// A's Curve25519 key between B and C.
45 pub forwarding_curve25519_key_chain: Vec<String>,
46
47 /// Used to mark key if allowed for shared history.
48 ///
49 /// Defaults to `false`.
50 #[serde(
51 default,
52 rename = "m.shared_history",
53 skip_serializing_if = "ruma_common::serde::is_default"
54 )]
55 pub shared_history: bool,
56}
57
58/// Initial set of fields of `ToDeviceForwardedRoomKeyEventContent`.
59///
60/// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in
61/// a new (non-breaking) release of the Matrix specification.
62#[derive(Debug)]
63#[allow(clippy::exhaustive_structs)]
64pub struct ToDeviceForwardedRoomKeyEventContentInit {
65 /// The encryption algorithm the key in this event is to be used with.
66 pub algorithm: EventEncryptionAlgorithm,
67
68 /// The room where the key is used.
69 pub room_id: OwnedRoomId,
70
71 /// The Curve25519 key of the device which initiated the session originally.
72 pub sender_key: String,
73
74 /// The ID of the session that the key is for.
75 pub session_id: String,
76
77 /// The key to be exchanged.
78 pub session_key: String,
79
80 /// The Ed25519 key of the device which initiated the session originally.
81 ///
82 /// It is "claimed" because the receiving device has no way to tell that the original
83 /// room_key actually came from a device which owns the private part of this key unless
84 /// they have done device verification.
85 pub sender_claimed_ed25519_key: String,
86
87 /// Chain of Curve25519 keys.
88 ///
89 /// It starts out empty, but each time the key is forwarded to another device, the
90 /// previous sender in the chain is added to the end of the list. For example, if the
91 /// key is forwarded from A to B to C, this field is empty between A and B, and contains
92 /// A's Curve25519 key between B and C.
93 pub forwarding_curve25519_key_chain: Vec<String>,
94}
95
96impl From<ToDeviceForwardedRoomKeyEventContentInit> for ToDeviceForwardedRoomKeyEventContent {
97 fn from(init: ToDeviceForwardedRoomKeyEventContentInit) -> Self {
98 Self {
99 algorithm: init.algorithm,
100 room_id: init.room_id,
101 sender_key: init.sender_key,
102 session_id: init.session_id,
103 session_key: init.session_key,
104 sender_claimed_ed25519_key: init.sender_claimed_ed25519_key,
105 forwarding_curve25519_key_chain: init.forwarding_curve25519_key_chain,
106 shared_history: false,
107 }
108 }
109}