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