ruma_client_api/discovery/discover_policy_server.rs
1//! `GET /.well-known/matrix/policy_server` ([spec])
2//!
3//! Gets public key information for a [Policy Server].
4//!
5//! Note that this endpoint is not necessarily handled by the homeserver or Policy Server. It may be
6//! served by another webserver.
7//!
8//! [spec]: https://spec.matrix.org/v1.18/client-server-api/#getwell-knownmatrixpolicy_server
9//! [Policy Server]: https://spec.matrix.org/v1.18/client-server-api/#policy-servers
10
11use std::collections::BTreeMap;
12
13use ruma_common::{
14 SigningKeyAlgorithm,
15 api::{auth_scheme::NoAccessToken, request, response},
16 metadata,
17 serde::Base64,
18};
19
20metadata! {
21 method: GET,
22 rate_limited: false,
23 authentication: NoAccessToken,
24 path: "/.well-known/matrix/policy_server",
25}
26
27/// Request type for the `discover_policy_server` endpoint.
28#[request]
29#[derive(Default)]
30pub struct Request {}
31
32/// Response type for the `discover_policy_server` endpoint.
33#[response]
34pub struct Response {
35 /// The public keys for the Policy Server.
36 ///
37 /// MUST contain at least `ed25519`.
38 pub public_keys: BTreeMap<SigningKeyAlgorithm, Base64>,
39}
40
41impl Request {
42 /// Creates an empty `Request`.
43 pub fn new() -> Self {
44 Self {}
45 }
46}
47
48impl Response {
49 /// Creates a new `Response` with the given ed25519 public key.
50 pub fn new(ed25519_public_key: Base64) -> Self {
51 Self { public_keys: [(SigningKeyAlgorithm::Ed25519, ed25519_public_key)].into() }
52 }
53}