diff --git a/ruma-federation-api/CHANGELOG.md b/ruma-federation-api/CHANGELOG.md index f3e49265..c8cbed3e 100644 --- a/ruma-federation-api/CHANGELOG.md +++ b/ruma-federation-api/CHANGELOG.md @@ -6,7 +6,10 @@ Improvements: ``` device::get_devices::v1, - keys::claim_keys::v1, + keys::{ + claim_keys::v1, + query_keys::v1, + }, ``` # 0.0.3 diff --git a/ruma-federation-api/src/keys.rs b/ruma-federation-api/src/keys.rs index 2346cffc..d1cdb755 100644 --- a/ruma-federation-api/src/keys.rs +++ b/ruma-federation-api/src/keys.rs @@ -1,3 +1,4 @@ //! Endpoints for handling keys for end-to-end encryption pub mod claim_keys; +pub mod get_keys; diff --git a/ruma-federation-api/src/keys/get_keys/mod.rs b/ruma-federation-api/src/keys/get_keys/mod.rs new file mode 100644 index 00000000..9d9eeffb --- /dev/null +++ b/ruma-federation-api/src/keys/get_keys/mod.rs @@ -0,0 +1,3 @@ +//! Module for getting information about the current devices and identity keys for the given users + +pub mod v1; diff --git a/ruma-federation-api/src/keys/get_keys/v1.rs b/ruma-federation-api/src/keys/get_keys/v1.rs new file mode 100644 index 00000000..374b2fa6 --- /dev/null +++ b/ruma-federation-api/src/keys/get_keys/v1.rs @@ -0,0 +1,43 @@ +//! [POST /_matrix/federation/v1/user/keys/query](https://matrix.org/docs/spec/server_server/r0.1.4#post-matrix-federation-v1-user-keys-claim) + +use std::collections::BTreeMap; + +use ruma_api::ruma_api; +use ruma_common::encryption::DeviceKeys; +use ruma_identifiers::{DeviceId, UserId}; + +ruma_api! { + metadata: { + description: "Returns the current devices and identity keys for the given users.", + method: POST, + name: "get_keys", + path: "/_matrix/federation/v1/user/keys/query", + rate_limited: false, + requires_authentication: true, + } + + request: { + /// The keys to be downloaded. Gives all keys for a given user if the list of device ids is + /// empty. + device_keys: BTreeMap>>, + } + + response: { + /// Keys from the queried devices. + device_keys: BTreeMap, DeviceKeys>>, + } +} + +impl Request { + /// Creates a new `Request` asking for the given device keys. + pub fn new(device_keys: BTreeMap>>) -> Self { + Self { device_keys } + } +} + +impl Response { + /// Creates a new `Response` with the given device keys. + pub fn new(device_keys: BTreeMap, DeviceKeys>>) -> Self { + Self { device_keys } + } +}