ruma_federation_api/keys/
get_keys.rs

1//! `POST /_matrix/federation/*/user/keys/query`
2//!
3//! Get the current devices and identity keys for the given users.
4
5pub mod v1 {
6    //! `/v1/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/server-server-api/#post_matrixfederationv1userkeysquery
9
10    use std::collections::BTreeMap;
11
12    use ruma_common::{
13        api::{request, response, Metadata},
14        encryption::{CrossSigningKey, DeviceKeys},
15        metadata,
16        serde::Raw,
17        OwnedDeviceId, OwnedUserId,
18    };
19
20    const METADATA: Metadata = metadata! {
21        method: POST,
22        rate_limited: false,
23        authentication: ServerSignatures,
24        history: {
25            1.0 => "/_matrix/federation/v1/user/keys/query",
26        }
27    };
28
29    /// Request type for the `get_keys` endpoint.
30    #[request]
31    pub struct Request {
32        /// The keys to be downloaded.
33        ///
34        /// Gives all keys for a given user if the list of device ids is empty.
35        pub device_keys: BTreeMap<OwnedUserId, Vec<OwnedDeviceId>>,
36    }
37
38    /// Response type for the `get_keys` endpoint.
39    #[response]
40    #[derive(Default)]
41    pub struct Response {
42        /// Keys from the queried devices.
43        pub device_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, Raw<DeviceKeys>>>,
44
45        /// Information on the master cross-signing keys of the queried users.
46        #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
47        pub master_keys: BTreeMap<OwnedUserId, Raw<CrossSigningKey>>,
48
49        /// Information on the self-signing keys of the queried users.
50        #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
51        pub self_signing_keys: BTreeMap<OwnedUserId, Raw<CrossSigningKey>>,
52    }
53
54    impl Request {
55        /// Creates a new `Request` asking for the given device keys.
56        pub fn new(device_keys: BTreeMap<OwnedUserId, Vec<OwnedDeviceId>>) -> Self {
57            Self { device_keys }
58        }
59    }
60
61    impl Response {
62        /// Creates a new `Response` with the given device keys.
63        pub fn new(
64            device_keys: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, Raw<DeviceKeys>>>,
65        ) -> Self {
66            Self { device_keys, ..Default::default() }
67        }
68    }
69}