From 887e8247f75b7e89aab0eae63533e54549ae83f1 Mon Sep 17 00:00:00 2001 From: Nym Seddon <64070857+unseddd@users.noreply.github.com> Date: Mon, 15 Feb 2021 20:18:54 +0000 Subject: [PATCH] identity-service-api: Add public key validity endpoint --- ruma-identity-service-api/src/keys.rs | 3 ++ .../src/keys/check_public_key_validity.rs | 3 ++ .../src/keys/check_public_key_validity/v2.rs | 39 +++++++++++++++++++ ruma-identity-service-api/src/lib.rs | 1 + 4 files changed, 46 insertions(+) create mode 100644 ruma-identity-service-api/src/keys.rs create mode 100644 ruma-identity-service-api/src/keys/check_public_key_validity.rs create mode 100644 ruma-identity-service-api/src/keys/check_public_key_validity/v2.rs diff --git a/ruma-identity-service-api/src/keys.rs b/ruma-identity-service-api/src/keys.rs new file mode 100644 index 00000000..50c6751c --- /dev/null +++ b/ruma-identity-service-api/src/keys.rs @@ -0,0 +1,3 @@ +//! Endpoints to retrieve, update, and validate keys with an identity server. + +pub mod check_public_key_validity; diff --git a/ruma-identity-service-api/src/keys/check_public_key_validity.rs b/ruma-identity-service-api/src/keys/check_public_key_validity.rs new file mode 100644 index 00000000..b4d737c5 --- /dev/null +++ b/ruma-identity-service-api/src/keys/check_public_key_validity.rs @@ -0,0 +1,3 @@ +//! Endpoint to check for valid public key with an identity server. + +pub mod v2; diff --git a/ruma-identity-service-api/src/keys/check_public_key_validity/v2.rs b/ruma-identity-service-api/src/keys/check_public_key_validity/v2.rs new file mode 100644 index 00000000..1dbe4ef1 --- /dev/null +++ b/ruma-identity-service-api/src/keys/check_public_key_validity/v2.rs @@ -0,0 +1,39 @@ +//! [GET /_matrix/identity/v2/pubkey/isvalid](https://matrix.org/docs/spec/identity_service/0.3.0#get-matrix-identity-v2-pubkey-isvalid) + +use ruma_api::ruma_api; + +ruma_api! { + metadata: { + description: "Check whether a long-term public key is valid. The response should always be the same, provided the key exists.", + method: GET, + name: "check_public_key_validity", + path: "/_matrix/identity/v2/pubkey/isvalid", + authentication: None, + rate_limited: false, + } + + request: { + /// Base64-encoded (no padding) public key to check for validity. + #[ruma_api(query)] + pub public_key: &'a str, + } + + response: { + /// Whether the public key is recognised and is currently valid. + pub valid: bool, + } +} + +impl<'a> Request<'a> { + /// Create a `Request` with the given base64-encoded (unpadded) public key. + pub fn new(public_key: &'a str) -> Self { + Self { public_key } + } +} + +impl Response { + /// Create a `Response` with the given bool indicating the validity of the public key. + pub fn new(valid: bool) -> Self { + Self { valid } + } +} diff --git a/ruma-identity-service-api/src/lib.rs b/ruma-identity-service-api/src/lib.rs index 1030cb55..2f36fbb1 100644 --- a/ruma-identity-service-api/src/lib.rs +++ b/ruma-identity-service-api/src/lib.rs @@ -1,2 +1,3 @@ pub mod authentication; +pub mod keys; pub mod status;