ruma_events/room/
encryption.rs1use js_int::{uint, UInt};
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
8
9use crate::{EmptyStateKey, EventEncryptionAlgorithm};
10
11#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
15#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
16#[ruma_event(type = "m.room.encryption", kind = State, state_key_type = EmptyStateKey)]
17pub struct RoomEncryptionEventContent {
18 pub algorithm: EventEncryptionAlgorithm,
22
23 #[cfg(feature = "unstable-msc3414")]
25 #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
26 #[serde(rename = "io.element.msc3414.encrypt_state_events")]
27 pub encrypt_state_events: bool,
28
29 #[serde(skip_serializing_if = "Option::is_none")]
33 pub rotation_period_ms: Option<UInt>,
34
35 #[serde(skip_serializing_if = "Option::is_none")]
39 pub rotation_period_msgs: Option<UInt>,
40}
41
42impl RoomEncryptionEventContent {
43 pub fn new(algorithm: EventEncryptionAlgorithm) -> Self {
45 Self {
46 algorithm,
47 #[cfg(feature = "unstable-msc3414")]
48 encrypt_state_events: false,
49 rotation_period_ms: None,
50 rotation_period_msgs: None,
51 }
52 }
53
54 pub fn with_recommended_defaults() -> Self {
60 Self {
62 algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
63 #[cfg(feature = "unstable-msc3414")]
64 encrypt_state_events: false,
65 rotation_period_ms: Some(uint!(604_800_000)),
66 rotation_period_msgs: Some(uint!(100)),
67 }
68 }
69
70 #[cfg(feature = "unstable-msc3414")]
74 pub fn with_encrypted_state(mut self) -> Self {
75 self.encrypt_state_events = true;
76 self
77 }
78}