diff --git a/crates/ruma-common/CHANGELOG.md b/crates/ruma-common/CHANGELOG.md index 06bbfb89..b018c1de 100644 --- a/crates/ruma-common/CHANGELOG.md +++ b/crates/ruma-common/CHANGELOG.md @@ -39,6 +39,10 @@ Breaking changes: - `(Owned)DeviceKeyId` is now a type alias of `(Owned)KeyId`. - Remove the `(owned_)device_key_id` macro, instead use `DeviceKeyId::from_parts`. +- Use `CrossSigningOrDeviceSignatures` for the `signatures` of `DeviceKeys`. +- Remove `SignedKeySignatures` and replace it with `DeviceSignatures`. +- Remove `CrossSigningKeySignatures` and replace it with + `CrossSigningOrDeviceSignatures`. Improvements: diff --git a/crates/ruma-common/src/encryption.rs b/crates/ruma-common/src/encryption.rs index 7f210a45..8878f8d6 100644 --- a/crates/ruma-common/src/encryption.rs +++ b/crates/ruma-common/src/encryption.rs @@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize}; use crate::{ serde::{Base64, StringEnum}, - EventEncryptionAlgorithm, OwnedCrossSigningKeyId, OwnedCrossSigningOrDeviceSigningKeyId, - OwnedDeviceId, OwnedDeviceKeyId, OwnedDeviceSigningKeyId, OwnedUserId, PrivOwnedStr, + CrossSigningOrDeviceSignatures, DeviceSignatures, EventEncryptionAlgorithm, + OwnedCrossSigningKeyId, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, PrivOwnedStr, }; /// Identity keys for a device. @@ -33,7 +33,7 @@ pub struct DeviceKeys { pub keys: BTreeMap, /// Signatures for the device key object. - pub signatures: BTreeMap>, + pub signatures: CrossSigningOrDeviceSignatures, /// Additional data added to the device key information by intermediate servers, and /// not covered by the signatures. @@ -49,7 +49,7 @@ impl DeviceKeys { device_id: OwnedDeviceId, algorithms: Vec, keys: BTreeMap, - signatures: BTreeMap>, + signatures: CrossSigningOrDeviceSignatures, ) -> Self { Self { user_id, device_id, algorithms, keys, signatures, unsigned: Default::default() } } @@ -76,9 +76,6 @@ impl UnsignedDeviceInfo { } } -/// Signatures for a `SignedKey` object. -pub type SignedKeySignatures = BTreeMap>; - /// A key for the SignedCurve25519 algorithm #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] @@ -87,7 +84,7 @@ pub struct SignedKey { pub key: Base64, /// Signatures for the key object. - pub signatures: SignedKeySignatures, + pub signatures: DeviceSignatures, /// Is this key considered to be a fallback key, defaults to false. #[serde(default, skip_serializing_if = "crate::serde::is_default")] @@ -96,12 +93,12 @@ pub struct SignedKey { impl SignedKey { /// Creates a new `SignedKey` with the given key and signatures. - pub fn new(key: Base64, signatures: SignedKeySignatures) -> Self { + pub fn new(key: Base64, signatures: DeviceSignatures) -> Self { Self { key, signatures, fallback: false } } /// Creates a new fallback `SignedKey` with the given key and signatures. - pub fn new_fallback(key: Base64, signatures: SignedKeySignatures) -> Self { + pub fn new_fallback(key: Base64, signatures: DeviceSignatures) -> Self { Self { key, signatures, fallback: true } } } @@ -118,10 +115,6 @@ pub enum OneTimeKey { Key(String), } -/// Signatures for a `CrossSigningKey` object. -pub type CrossSigningKeySignatures = - BTreeMap>; - /// A [cross-signing] key. /// /// [cross-signing]: https://spec.matrix.org/latest/client-server-api/#cross-signing @@ -147,7 +140,7 @@ pub struct CrossSigningKey { /// /// Only optional for the master key. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub signatures: CrossSigningKeySignatures, + pub signatures: CrossSigningOrDeviceSignatures, } impl CrossSigningKey { @@ -156,7 +149,7 @@ impl CrossSigningKey { user_id: OwnedUserId, usage: Vec, keys: BTreeMap, - signatures: CrossSigningKeySignatures, + signatures: CrossSigningOrDeviceSignatures, ) -> Self { Self { user_id, usage, keys, signatures } } diff --git a/crates/ruma-common/src/identifiers.rs b/crates/ruma-common/src/identifiers.rs index 28eabead..44e3d9f5 100644 --- a/crates/ruma-common/src/identifiers.rs +++ b/crates/ruma-common/src/identifiers.rs @@ -42,7 +42,10 @@ pub use self::{ server_name::{OwnedServerName, ServerName}, server_signing_key_version::{OwnedServerSigningKeyVersion, ServerSigningKeyVersion}, session_id::{OwnedSessionId, SessionId}, - signatures::{DeviceSignatures, EntitySignatures, ServerSignatures, Signatures}, + signatures::{ + CrossSigningOrDeviceSignatures, DeviceSignatures, EntitySignatures, ServerSignatures, + Signatures, + }, transaction_id::{OwnedTransactionId, TransactionId}, user_id::{OwnedUserId, UserId}, voip_id::{OwnedVoipId, VoipId}, diff --git a/crates/ruma-common/src/identifiers/signatures.rs b/crates/ruma-common/src/identifiers/signatures.rs index 0019445a..3aa81abc 100644 --- a/crates/ruma-common/src/identifiers/signatures.rs +++ b/crates/ruma-common/src/identifiers/signatures.rs @@ -6,7 +6,8 @@ use std::{ use serde::{Deserialize, Serialize}; use super::{ - DeviceId, KeyName, OwnedServerName, OwnedSigningKeyId, OwnedUserId, ServerSigningKeyVersion, + Base64PublicKeyOrDeviceId, DeviceId, KeyName, OwnedServerName, OwnedSigningKeyId, OwnedUserId, + ServerSigningKeyVersion, }; /// Map of key identifier to signature values. @@ -58,6 +59,9 @@ pub type ServerSignatures = Signatures /// Map of device signatures, grouped by user. pub type DeviceSignatures = Signatures; +/// Map of cross-signing or device signatures, grouped by user. +pub type CrossSigningOrDeviceSignatures = Signatures; + impl Clone for Signatures where E: Ord + Clone,