ruma_federation_api/discovery/
get_server_keys.rs

1//! `GET /_matrix/key/*/server`
2//!
3//! Get the homeserver's published signing keys.
4
5pub mod v2 {
6    //! `/v2/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixkeyv2server
9
10    use ruma_common::{
11        api::{request, response, Metadata},
12        metadata,
13        serde::Raw,
14    };
15
16    use crate::discovery::ServerSigningKeys;
17
18    const METADATA: Metadata = metadata! {
19        method: GET,
20        rate_limited: false,
21        authentication: None,
22        history: {
23            1.0 => "/_matrix/key/v2/server",
24        }
25    };
26
27    /// Request type for the `get_server_keys` endpoint.
28    #[request]
29    #[derive(Default)]
30    pub struct Request {}
31
32    /// Response type for the `get_server_keys` endpoint.
33    #[response]
34    pub struct Response {
35        /// Queried server key, signed by the notary server.
36        #[ruma_api(body)]
37        pub server_key: Raw<ServerSigningKeys>,
38    }
39
40    impl Request {
41        /// Creates an empty `Request`.
42        pub fn new() -> Self {
43            Self {}
44        }
45    }
46
47    impl Response {
48        /// Creates a new `Response` with the given server key.
49        pub fn new(server_key: Raw<ServerSigningKeys>) -> Self {
50            Self { server_key }
51        }
52    }
53
54    impl From<Raw<ServerSigningKeys>> for Response {
55        fn from(server_key: Raw<ServerSigningKeys>) -> Self {
56            Self::new(server_key)
57        }
58    }
59}