events: Use Signatures in more places
This commit is contained in:
parent
5ed3718310
commit
f87f388280
@ -48,6 +48,7 @@ Improvements:
|
|||||||
Breaking changes:
|
Breaking changes:
|
||||||
|
|
||||||
- `StickerEventContent::url` was replaced by `StickerEventContent::source` which is a `StickerMediaSource`
|
- `StickerEventContent::url` was replaced by `StickerEventContent::source` which is a `StickerMediaSource`
|
||||||
|
- Use `ServerSignatures` for the `signatures` of `RoomV1Pdu`, `RoomV3Pdu` and `SignedContent`.
|
||||||
|
|
||||||
# 0.28.1
|
# 0.28.1
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName,
|
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, ServerSignatures,
|
||||||
OwnedServerSigningKeyId, OwnedUserId,
|
|
||||||
};
|
};
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{Error as _, IgnoredAny},
|
de::{Error as _, IgnoredAny},
|
||||||
@ -87,7 +86,7 @@ pub struct RoomV1Pdu {
|
|||||||
pub hashes: EventHash,
|
pub hashes: EventHash,
|
||||||
|
|
||||||
/// Signatures for the PDU.
|
/// 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.
|
/// A 'persistent data unit' (event) for room versions 3 and beyond.
|
||||||
@ -140,7 +139,7 @@ pub struct RoomV3Pdu {
|
|||||||
pub hashes: EventHash,
|
pub hashes: EventHash,
|
||||||
|
|
||||||
/// Signatures for the PDU.
|
/// Signatures for the PDU.
|
||||||
pub signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
|
pub signatures: ServerSignatures,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Content hashes of a PDU.
|
/// Content hashes of a PDU.
|
||||||
|
@ -2,13 +2,10 @@
|
|||||||
//!
|
//!
|
||||||
//! [`m.room.member`]: https://spec.matrix.org/latest/client-server-api/#mroommember
|
//! [`m.room.member`]: https://spec.matrix.org/latest/client-server-api/#mroommember
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
|
|
||||||
use js_int::Int;
|
use js_int::Int;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
serde::{CanBeEmpty, Raw, StringEnum},
|
serde::{CanBeEmpty, Raw, StringEnum},
|
||||||
OwnedMxcUri, OwnedServerName, OwnedServerSigningKeyId, OwnedTransactionId, OwnedUserId,
|
OwnedMxcUri, OwnedTransactionId, OwnedUserId, RoomVersionId, ServerSignatures, UserId,
|
||||||
RoomVersionId, UserId,
|
|
||||||
};
|
};
|
||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
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
|
/// A single signature from the verifying server, in the format specified by the Signing Events
|
||||||
/// section of the server-server API.
|
/// 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.
|
/// The token property of the containing `third_party_invite` object.
|
||||||
pub token: String,
|
pub token: String,
|
||||||
@ -377,11 +374,7 @@ pub struct SignedContent {
|
|||||||
|
|
||||||
impl SignedContent {
|
impl SignedContent {
|
||||||
/// Creates a new `SignedContent` with the given mxid, signature and token.
|
/// Creates a new `SignedContent` with the given mxid, signature and token.
|
||||||
pub fn new(
|
pub fn new(signatures: ServerSignatures, mxid: OwnedUserId, token: String) -> Self {
|
||||||
signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
|
|
||||||
mxid: OwnedUserId,
|
|
||||||
token: String,
|
|
||||||
) -> Self {
|
|
||||||
Self { mxid, signatures, token }
|
Self { mxid, signatures, token }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -706,15 +699,16 @@ mod tests {
|
|||||||
let third_party_invite = ev.content.third_party_invite.unwrap();
|
let third_party_invite = ev.content.third_party_invite.unwrap();
|
||||||
assert_eq!(third_party_invite.display_name, "alice");
|
assert_eq!(third_party_invite.display_name, "alice");
|
||||||
assert_eq!(third_party_invite.signed.mxid, "@alice:example.org");
|
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!(
|
assert_eq!(
|
||||||
third_party_invite.signed.signatures,
|
*server_signatures,
|
||||||
btreemap! {
|
btreemap! {
|
||||||
server_name!("magic.forest").to_owned() => btreemap! {
|
ServerSigningKeyId::from_parts(
|
||||||
ServerSigningKeyId::from_parts(
|
SigningKeyAlgorithm::Ed25519,
|
||||||
SigningKeyAlgorithm::Ed25519,
|
server_signing_key_version!("3")
|
||||||
server_signing_key_version!("3")
|
) => "foobar".to_owned()
|
||||||
) => "foobar".to_owned()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert_eq!(third_party_invite.signed.token, "abc123");
|
assert_eq!(third_party_invite.signed.token, "abc123");
|
||||||
@ -779,15 +773,16 @@ mod tests {
|
|||||||
let third_party_invite = prev_content.third_party_invite.unwrap();
|
let third_party_invite = prev_content.third_party_invite.unwrap();
|
||||||
assert_eq!(third_party_invite.display_name, "alice");
|
assert_eq!(third_party_invite.display_name, "alice");
|
||||||
assert_eq!(third_party_invite.signed.mxid, "@alice:example.org");
|
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!(
|
assert_eq!(
|
||||||
third_party_invite.signed.signatures,
|
*server_signatures,
|
||||||
btreemap! {
|
btreemap! {
|
||||||
server_name!("magic.forest").to_owned() => btreemap! {
|
ServerSigningKeyId::from_parts(
|
||||||
ServerSigningKeyId::from_parts(
|
SigningKeyAlgorithm::Ed25519,
|
||||||
SigningKeyAlgorithm::Ed25519,
|
server_signing_key_version!("3")
|
||||||
server_signing_key_version!("3")
|
) => "foobar".to_owned()
|
||||||
) => "foobar".to_owned()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert_eq!(third_party_invite.signed.token, "abc123");
|
assert_eq!(third_party_invite.signed.token, "abc123");
|
||||||
|
@ -4,8 +4,8 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id, owned_event_id, owned_room_id, owned_user_id, server_name,
|
event_id, owned_event_id, owned_room_id, owned_server_name, owned_user_id,
|
||||||
server_signing_key_version, MilliSecondsSinceUnixEpoch, ServerSigningKeyId,
|
server_signing_key_version, MilliSecondsSinceUnixEpoch, ServerSignatures, ServerSigningKeyId,
|
||||||
SigningKeyAlgorithm,
|
SigningKeyAlgorithm,
|
||||||
};
|
};
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
@ -19,16 +19,16 @@ use serde_json::{
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_pdu_as_v1() {
|
fn serialize_pdu_as_v1() {
|
||||||
let mut signatures = BTreeMap::new();
|
let mut signatures = ServerSignatures::new();
|
||||||
let mut inner_signature = BTreeMap::new();
|
let key_id = ServerSigningKeyId::from_parts(
|
||||||
inner_signature.insert(
|
SigningKeyAlgorithm::Ed25519,
|
||||||
ServerSigningKeyId::from_parts(
|
server_signing_key_version!("key_version"),
|
||||||
SigningKeyAlgorithm::Ed25519,
|
);
|
||||||
server_signing_key_version!("key_version"),
|
signatures.insert_signature(
|
||||||
),
|
owned_server_name!("example.com"),
|
||||||
"86BytesOfSignatureOfTheRedactedEvent".into(),
|
key_id,
|
||||||
|
"86BytesOfSignatureOfTheRedactedEvent".to_owned(),
|
||||||
);
|
);
|
||||||
signatures.insert(server_name!("example.com").to_owned(), inner_signature);
|
|
||||||
|
|
||||||
let mut unsigned = BTreeMap::new();
|
let mut unsigned = BTreeMap::new();
|
||||||
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());
|
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());
|
||||||
@ -87,16 +87,16 @@ fn serialize_pdu_as_v1() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_pdu_as_v3() {
|
fn serialize_pdu_as_v3() {
|
||||||
let mut signatures = BTreeMap::new();
|
let mut signatures = ServerSignatures::new();
|
||||||
let mut inner_signature = BTreeMap::new();
|
let key_id = ServerSigningKeyId::from_parts(
|
||||||
inner_signature.insert(
|
SigningKeyAlgorithm::Ed25519,
|
||||||
ServerSigningKeyId::from_parts(
|
server_signing_key_version!("key_version"),
|
||||||
SigningKeyAlgorithm::Ed25519,
|
);
|
||||||
server_signing_key_version!("key_version"),
|
signatures.insert_signature(
|
||||||
),
|
owned_server_name!("example.com"),
|
||||||
"86BytesOfSignatureOfTheRedactedEvent".into(),
|
key_id,
|
||||||
|
"86BytesOfSignatureOfTheRedactedEvent".to_owned(),
|
||||||
);
|
);
|
||||||
signatures.insert(server_name!("example.com").to_owned(), inner_signature);
|
|
||||||
|
|
||||||
let mut unsigned = BTreeMap::new();
|
let mut unsigned = BTreeMap::new();
|
||||||
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());
|
unsigned.insert("somekey".into(), to_raw_json_value(&json!({ "a": 456 })).unwrap());
|
||||||
|
@ -11,7 +11,7 @@ use futures_util::future::ready;
|
|||||||
use js_int::{int, uint};
|
use js_int::{int, uint};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id, room_id, user_id, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId,
|
event_id, room_id, user_id, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId,
|
||||||
RoomVersionId, UserId,
|
RoomVersionId, ServerSignatures, UserId,
|
||||||
};
|
};
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
pdu::{EventHash, Pdu, RoomV3Pdu},
|
pdu::{EventHash, Pdu, RoomV3Pdu},
|
||||||
@ -401,7 +401,7 @@ pub(crate) fn to_init_pdu_event(
|
|||||||
prev_events: vec![],
|
prev_events: vec![],
|
||||||
depth: uint!(0),
|
depth: uint!(0),
|
||||||
hashes: EventHash::new("".to_owned()),
|
hashes: EventHash::new("".to_owned()),
|
||||||
signatures: BTreeMap::new(),
|
signatures: ServerSignatures::default(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ where
|
|||||||
prev_events,
|
prev_events,
|
||||||
depth: uint!(0),
|
depth: uint!(0),
|
||||||
hashes: EventHash::new("".to_owned()),
|
hashes: EventHash::new("".to_owned()),
|
||||||
signatures: BTreeMap::new(),
|
signatures: ServerSignatures::default(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user