ruma_federation_api/discovery/
get_remote_server_keys.rs

1//! `GET /_matrix/key/*/query/{serverName}`
2//!
3//! Query for another server's keys. The receiving (notary) server must sign the keys returned by
4//! the queried server.
5
6pub mod v2 {
7    //! `/v2/` ([spec])
8    //!
9    //! [spec]: https://spec.matrix.org/latest/server-server-api/#get_matrixkeyv2queryservername
10
11    use ruma_common::{
12        api::{request, response, Metadata},
13        metadata,
14        serde::Raw,
15        MilliSecondsSinceUnixEpoch, OwnedServerName,
16    };
17
18    use crate::discovery::ServerSigningKeys;
19
20    const METADATA: Metadata = metadata! {
21        method: GET,
22        rate_limited: false,
23        authentication: None,
24        history: {
25            1.0 => "/_matrix/key/v2/query/:server_name",
26        }
27    };
28
29    /// Request type for the `get_remote_server_keys` endpoint.
30    #[request]
31    pub struct Request {
32        /// The server's DNS name to query
33        #[ruma_api(path)]
34        pub server_name: OwnedServerName,
35
36        /// A millisecond POSIX timestamp in milliseconds indicating when the returned certificates
37        /// will need to be valid until to be useful to the requesting server.
38        ///
39        /// If not supplied, the current time as determined by the receiving server is used.
40        #[ruma_api(query)]
41        #[serde(default = "MilliSecondsSinceUnixEpoch::now")]
42        pub minimum_valid_until_ts: MilliSecondsSinceUnixEpoch,
43    }
44
45    /// Response type for the `get_remote_server_keys` endpoint.
46    #[response]
47    pub struct Response {
48        /// The queried server's keys, signed by the notary server.
49        pub server_keys: Vec<Raw<ServerSigningKeys>>,
50    }
51
52    impl Request {
53        /// Creates a new `Request` with the given server name and `minimum_valid_until` timestamp.
54        pub fn new(
55            server_name: OwnedServerName,
56            minimum_valid_until_ts: MilliSecondsSinceUnixEpoch,
57        ) -> Self {
58            Self { server_name, minimum_valid_until_ts }
59        }
60    }
61
62    impl Response {
63        /// Creates a new `Response` with the given keys.
64        pub fn new(server_keys: Vec<Raw<ServerSigningKeys>>) -> Self {
65            Self { server_keys }
66        }
67    }
68}