ruma_events/room/policy.rs
1//! Types for the [`m.room.policy`] event.
2//!
3//! [`m.room.policy`]: https://spec.matrix.org/v1.18/client-server-api/#mroompolicy
4
5use std::collections::BTreeMap;
6
7use ruma_common::{OwnedServerName, SigningKeyAlgorithm, serde::Base64};
8use ruma_macros::EventContent;
9use serde::{Deserialize, Serialize};
10
11use crate::EmptyStateKey;
12
13/// The signing key ID that must be used by a Policy Server for its ed25519 signature.
14pub const POLICY_SERVER_ED25519_SIGNING_KEY_ID: &str = "ed25519:policy_server";
15
16/// The content of an [`m.room.policy`] event.
17///
18/// A [Policy Server] configuration.
19///
20/// If invalid or not set, the room does not use a Policy Server.
21///
22/// [`m.room.policy`]: https://spec.matrix.org/v1.18/client-server-api/#mroompolicy
23/// [Policy Server]: https://spec.matrix.org/v1.18/client-server-api/#policy-servers
24#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
25#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
26#[ruma_event(type = "m.room.policy", kind = State, state_key_type = EmptyStateKey)]
27pub struct RoomPolicyEventContent {
28 /// The server name to use as a Policy Server.
29 ///
30 /// MUST have a joined user in the room.
31 pub via: OwnedServerName,
32
33 /// The public keys for the Policy Server.
34 ///
35 /// MUST contain at least `ed25519`.
36 pub public_keys: BTreeMap<SigningKeyAlgorithm, Base64>,
37}
38
39impl RoomPolicyEventContent {
40 /// Creates a new `RoomPolicyEventContent` with the given server name and ed25519 public key.
41 pub fn new(via: OwnedServerName, ed25519_public_key: Base64) -> Self {
42 Self { via, public_keys: [(SigningKeyAlgorithm::Ed25519, ed25519_public_key)].into() }
43 }
44}