client-api: Update upload_signatures endpoint
This commit is contained in:
parent
7782e4f648
commit
c4d2eacc38
@ -3,8 +3,13 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
use serde_json::Value as JsonValue;
|
||||
use ruma_common::encryption::{CrossSigningKey, DeviceKeys};
|
||||
use ruma_identifiers::{DeviceId, UserId};
|
||||
use ruma_serde::{Raw, StringEnum};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use crate::PrivOwnedStr;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -21,18 +26,21 @@ ruma_api! {
|
||||
request: {
|
||||
/// Signed keys.
|
||||
#[ruma_api(body)]
|
||||
pub signed_keys: BTreeMap<Box<UserId>, BTreeMap<String, JsonValue>>,
|
||||
pub signed_keys: BTreeMap<Box<UserId>, SignedKeys>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
response: {
|
||||
/// Signature processing failures.
|
||||
pub failures: BTreeMap<Box<UserId>, BTreeMap<String, Failure>>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given signed keys.
|
||||
pub fn new(signed_keys: BTreeMap<Box<UserId>, BTreeMap<String, JsonValue>>) -> Self {
|
||||
pub fn new(signed_keys: BTreeMap<Box<UserId>, SignedKeys>) -> Self {
|
||||
Self { signed_keys }
|
||||
}
|
||||
}
|
||||
@ -40,6 +48,54 @@ impl Request {
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// A map of key IDs to signed key objects.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct SignedKeys(BTreeMap<Box<str>, Box<RawJsonValue>>);
|
||||
|
||||
impl SignedKeys {
|
||||
/// Creates an empty `SignedKeys` map.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Add the given device keys.
|
||||
pub fn add_device_keys(&mut self, device_id: Box<DeviceId>, device_keys: Raw<DeviceKeys>) {
|
||||
self.0.insert(device_id.into(), device_keys.into_json());
|
||||
}
|
||||
|
||||
/// Add the given cross signing keys.
|
||||
pub fn add_cross_signing_keys(
|
||||
&mut self,
|
||||
cross_signing_key_id: Box<str>,
|
||||
cross_signing_keys: Raw<CrossSigningKey>,
|
||||
) {
|
||||
self.0.insert(cross_signing_key_id, cross_signing_keys.into_json());
|
||||
}
|
||||
}
|
||||
|
||||
/// A failure to process a signed key.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Failure {
|
||||
/// Machine-readable error code.
|
||||
errcode: FailureErrorCode,
|
||||
|
||||
/// Human-readable error message.
|
||||
error: String,
|
||||
}
|
||||
|
||||
/// Error code for signed key processing failures.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[non_exhaustive]
|
||||
#[ruma_enum(rename_all = "M_MATRIX_ERROR_CASE")]
|
||||
pub enum FailureErrorCode {
|
||||
/// The signature is invalid.
|
||||
InvalidSignature,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user