ruma_identity_service_api/keys/
check_public_key_validity.rs

1//! `GET /_matrix/identity/*/pubkey/isvalid`
2//!
3//! Check whether a long-term public key is valid. The response should always be the same, provided
4//! the key exists.
5
6pub mod v2 {
7    //! `/v2/` ([spec])
8    //!
9    //! [spec]: https://spec.matrix.org/latest/identity-service-api/#get_matrixidentityv2pubkeyisvalid
10
11    use ruma_common::{
12        api::{request, response, Metadata},
13        metadata,
14        third_party_invite::IdentityServerBase64PublicKey,
15    };
16
17    const METADATA: Metadata = metadata! {
18        method: GET,
19        rate_limited: false,
20        authentication: None,
21        history: {
22            1.0 => "/_matrix/identity/v2/pubkey/isvalid",
23        }
24    };
25
26    /// Request type for the `check_public_key_validity` endpoint.
27    #[request]
28    pub struct Request {
29        /// Base64-encoded (no padding) public key to check for validity.
30        #[ruma_api(query)]
31        pub public_key: IdentityServerBase64PublicKey,
32    }
33
34    /// Response type for the `check_public_key_validity` endpoint.
35    #[response]
36    pub struct Response {
37        /// Whether the public key is recognised and is currently valid.
38        pub valid: bool,
39    }
40
41    impl Request {
42        /// Create a `Request` with the given base64-encoded (unpadded) public key.
43        pub fn new(public_key: IdentityServerBase64PublicKey) -> Self {
44            Self { public_key }
45        }
46    }
47
48    impl Response {
49        /// Create a `Response` with the given bool indicating the validity of the public key.
50        pub fn new(valid: bool) -> Self {
51            Self { valid }
52        }
53    }
54}