Skip to main content

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
48/// Initial set of fields of `ToDeviceForwardedRoomKeyEventContent`.
49///
50/// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in
51/// a new (non-breaking) release of the Matrix specification.
52#[derive(Debug)]
53#[allow(clippy::exhaustive_structs)]
54pub struct ToDeviceForwardedRoomKeyEventContentInit {
55    /// The encryption algorithm the key in this event is to be used with.
56    pub algorithm: EventEncryptionAlgorithm,
57
58    /// The room where the key is used.
59    pub room_id: OwnedRoomId,
60
61    /// The Curve25519 key of the device which initiated the session originally.
62    pub sender_key: String,
63
64    /// The ID of the session that the key is for.
65    pub session_id: String,
66
67    /// The key to be exchanged.
68    pub session_key: String,
69
70    /// The Ed25519 key of the device which initiated the session originally.
71    ///
72    /// It is "claimed" because the receiving device has no way to tell that the original
73    /// room_key actually came from a device which owns the private part of this key unless
74    /// they have done device verification.
75    pub sender_claimed_ed25519_key: String,
76
77    /// Chain of Curve25519 keys.
78    ///
79    /// It starts out empty, but each time the key is forwarded to another device, the
80    /// previous sender in the chain is added to the end of the list. For example, if the
81    /// key is forwarded from A to B to C, this field is empty between A and B, and contains
82    /// A's Curve25519 key between B and C.
83    pub forwarding_curve25519_key_chain: Vec<String>,
84}
85
86impl From<ToDeviceForwardedRoomKeyEventContentInit> for ToDeviceForwardedRoomKeyEventContent {
87    fn from(init: ToDeviceForwardedRoomKeyEventContentInit) -> Self {
88        Self {
89            algorithm: init.algorithm,
90            room_id: init.room_id,
91            sender_key: init.sender_key,
92            session_id: init.session_id,
93            session_key: init.session_key,
94            sender_claimed_ed25519_key: init.sender_claimed_ed25519_key,
95            forwarding_curve25519_key_chain: init.forwarding_curve25519_key_chain,
96        }
97    }
98}