ruma_events/
room_key_request.rs1use ruma_common::{
6 serde::StringEnum, EventEncryptionAlgorithm, OwnedDeviceId, OwnedRoomId, OwnedTransactionId,
7};
8use ruma_macros::EventContent;
9use serde::{Deserialize, Serialize};
10
11use crate::PrivOwnedStr;
12
13#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
15#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
16#[ruma_event(type = "m.room_key_request", kind = ToDevice)]
17pub struct ToDeviceRoomKeyRequestEventContent {
18 pub action: Action,
20
21 pub body: Option<RequestedKeyInfo>,
25
26 pub requesting_device_id: OwnedDeviceId,
28
29 pub request_id: OwnedTransactionId,
34}
35
36impl ToDeviceRoomKeyRequestEventContent {
37 pub fn new(
40 action: Action,
41 body: Option<RequestedKeyInfo>,
42 requesting_device_id: OwnedDeviceId,
43 request_id: OwnedTransactionId,
44 ) -> Self {
45 Self { action, body, requesting_device_id, request_id }
46 }
47}
48
49#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
51#[derive(Clone, PartialEq, Eq, StringEnum)]
52#[ruma_enum(rename_all = "snake_case")]
53#[non_exhaustive]
54pub enum Action {
55 Request,
57
58 #[ruma_enum(rename = "request_cancellation")]
60 CancelRequest,
61
62 #[doc(hidden)]
63 _Custom(PrivOwnedStr),
64}
65
66#[derive(Clone, Debug, Deserialize, Serialize)]
68#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
69pub struct RequestedKeyInfo {
70 pub algorithm: EventEncryptionAlgorithm,
72
73 pub room_id: OwnedRoomId,
75
76 #[deprecated = "this field still needs to be sent but should not be used when received"]
78 pub sender_key: String,
79
80 pub session_id: String,
82}
83
84impl RequestedKeyInfo {
85 pub fn new(
88 algorithm: EventEncryptionAlgorithm,
89 room_id: OwnedRoomId,
90 sender_key: String,
91 session_id: String,
92 ) -> Self {
93 #[allow(deprecated)]
94 Self { algorithm, room_id, sender_key, session_id }
95 }
96}