events: Use Signatures in more places

This commit is contained in:
Kévin Commaille 2024-10-26 16:27:32 +02:00 committed by strawberry
parent 5ed3718310
commit f87f388280
5 changed files with 46 additions and 51 deletions

View File

@ -48,6 +48,7 @@ Improvements:
Breaking changes:
- `StickerEventContent::url` was replaced by `StickerEventContent::source` which is a `StickerMediaSource`
- Use `ServerSignatures` for the `signatures` of `RoomV1Pdu`, `RoomV3Pdu` and `SignedContent`.
# 0.28.1

View File

@ -9,8 +9,7 @@ use std::collections::BTreeMap;
use js_int::UInt;
use ruma_common::{
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName,
OwnedServerSigningKeyId, OwnedUserId,
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, ServerSignatures,
};
use serde::{
de::{Error as _, IgnoredAny},
@ -87,7 +86,7 @@ pub struct RoomV1Pdu {
pub hashes: EventHash,
/// Signatures for the PDU.
pub signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
pub signatures: ServerSignatures,
}
/// A 'persistent data unit' (event) for room versions 3 and beyond.
@ -140,7 +139,7 @@ pub struct RoomV3Pdu {
pub hashes: EventHash,
/// Signatures for the PDU.
pub signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
pub signatures: ServerSignatures,
}
/// Content hashes of a PDU.

View File

@ -2,13 +2,10 @@
//!
//! [`m.room.member`]: https://spec.matrix.org/latest/client-server-api/#mroommember
use std::collections::BTreeMap;
use js_int::Int;
use ruma_common::{
serde::{CanBeEmpty, Raw, StringEnum},
OwnedMxcUri, OwnedServerName, OwnedServerSigningKeyId, OwnedTransactionId, OwnedUserId,
RoomVersionId, UserId,
OwnedMxcUri, OwnedTransactionId, OwnedUserId, RoomVersionId, ServerSignatures, UserId,
};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
@ -369,7 +366,7 @@ pub struct SignedContent {
/// A single signature from the verifying server, in the format specified by the Signing Events
/// section of the server-server API.
pub signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
pub signatures: ServerSignatures,
/// The token property of the containing `third_party_invite` object.
pub token: String,
@ -377,11 +374,7 @@ pub struct SignedContent {
impl SignedContent {
/// Creates a new `SignedContent` with the given mxid, signature and token.
pub fn new(
signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
mxid: OwnedUserId,
token: String,
) -> Self {
pub fn new(signatures: ServerSignatures, mxid: OwnedUserId, token: String) -> Self {
Self { mxid, signatures, token }
}
}
@ -706,16 +699,17 @@ mod tests {
let third_party_invite = ev.content.third_party_invite.unwrap();
assert_eq!(third_party_invite.display_name, "alice");
assert_eq!(third_party_invite.signed.mxid, "@alice:example.org");
assert_eq!(third_party_invite.signed.signatures.len(), 1);
let server_signatures =
third_party_invite.signed.signatures.get(server_name!("magic.forest")).unwrap();
assert_eq!(
third_party_invite.signed.signatures,
*server_signatures,
btreemap! {
server_name!("magic.forest").to_owned() => btreemap! {
ServerSigningKeyId::from_parts(
SigningKeyAlgorithm::Ed25519,
server_signing_key_version!("3")
) => "foobar".to_owned()
}
}
);
assert_eq!(third_party_invite.signed.token, "abc123");
}
@ -779,16 +773,17 @@ mod tests {
let third_party_invite = prev_content.third_party_invite.unwrap();
assert_eq!(third_party_invite.display_name, "alice");
assert_eq!(third_party_invite.signed.mxid, "@alice:example.org");
assert_eq!(third_party_invite.signed.signatures.len(), 1);
let server_signatures =
third_party_invite.signed.signatures.get(server_name!("magic.forest")).unwrap();
assert_eq!(
third_party_invite.signed.signatures,
*server_signatures,
btreemap! {
server_name!("magic.forest").to_owned() => btreemap! {
ServerSigningKeyId::from_parts(
SigningKeyAlgorithm::Ed25519,
server_signing_key_version!("3")
) => "foobar".to_owned()
}
}
);
assert_eq!(third_party_invite.signed.token, "abc123");
}

View File

@ -4,8 +4,8 @@ use std::collections::BTreeMap;
use js_int::uint;
use ruma_common::{
event_id, owned_event_id, owned_room_id, owned_user_id, server_name,
server_signing_key_version, MilliSecondsSinceUnixEpoch, ServerSigningKeyId,
event_id, owned_event_id, owned_room_id, owned_server_name, owned_user_id,
server_signing_key_version, MilliSecondsSinceUnixEpoch, ServerSignatures, ServerSigningKeyId,
SigningKeyAlgorithm,
};
use ruma_events::{
@ -19,16 +19,16 @@ use serde_json::{
#[test]
fn serialize_pdu_as_v1() {
let mut signatures = BTreeMap::new();
let mut inner_signature = BTreeMap::new();
inner_signature.insert(
ServerSigningKeyId::from_parts(
let mut signatures = ServerSignatures::new();
let key_id = ServerSigningKeyId::from_parts(
SigningKeyAlgorithm::Ed25519,
server_signing_key_version!("key_version"),
),
"86BytesOfSignatureOfTheRedactedEvent".into(),
);
signatures.insert(server_name!("example.com").to_owned(), inner_signature);
signatures.insert_signature(
owned_server_name!("example.com"),
key_id,
"86BytesOfSignatureOfTheRedactedEvent".to_owned(),
);
let mut unsigned = BTreeMap::new();
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());
@ -87,16 +87,16 @@ fn serialize_pdu_as_v1() {
#[test]
fn serialize_pdu_as_v3() {
let mut signatures = BTreeMap::new();
let mut inner_signature = BTreeMap::new();
inner_signature.insert(
ServerSigningKeyId::from_parts(
let mut signatures = ServerSignatures::new();
let key_id = ServerSigningKeyId::from_parts(
SigningKeyAlgorithm::Ed25519,
server_signing_key_version!("key_version"),
),
"86BytesOfSignatureOfTheRedactedEvent".into(),
);
signatures.insert(server_name!("example.com").to_owned(), inner_signature);
signatures.insert_signature(
owned_server_name!("example.com"),
key_id,
"86BytesOfSignatureOfTheRedactedEvent".to_owned(),
);
let mut unsigned = BTreeMap::new();
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());

View File

@ -11,7 +11,7 @@ use futures_util::future::ready;
use js_int::{int, uint};
use ruma_common::{
event_id, room_id, user_id, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId,
RoomVersionId, UserId,
RoomVersionId, ServerSignatures, UserId,
};
use ruma_events::{
pdu::{EventHash, Pdu, RoomV3Pdu},
@ -401,7 +401,7 @@ pub(crate) fn to_init_pdu_event(
prev_events: vec![],
depth: uint!(0),
hashes: EventHash::new("".to_owned()),
signatures: BTreeMap::new(),
signatures: ServerSignatures::default(),
}),
})
}
@ -439,7 +439,7 @@ where
prev_events,
depth: uint!(0),
hashes: EventHash::new("".to_owned()),
signatures: BTreeMap::new(),
signatures: ServerSignatures::default(),
}),
})
}