diff --git a/crates/ruma-events/src/enums.rs b/crates/ruma-events/src/enums.rs index aa4fee98..87f6ce64 100644 --- a/crates/ruma-events/src/enums.rs +++ b/crates/ruma-events/src/enums.rs @@ -107,6 +107,9 @@ event_enum! { "m.room_key_request", "m.forwarded_room_key", "m.key.verification.request", + #[cfg(feature = "unstable-pre-spec")] + #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] + "m.key.verification.ready", "m.key.verification.start", "m.key.verification.cancel", "m.key.verification.accept", diff --git a/crates/ruma-events/src/event_type.rs b/crates/ruma-events/src/event_type.rs index a32c9d8a..53138dc5 100644 --- a/crates/ruma-events/src/event_type.rs +++ b/crates/ruma-events/src/event_type.rs @@ -56,6 +56,10 @@ pub enum EventType { #[ruma_enum(rename = "m.key.verification.mac")] KeyVerificationMac, + /// m.key.verification.ready + #[ruma_enum(rename = "m.key.verification.ready")] + KeyVerificationReady, + /// m.key.verification.request #[ruma_enum(rename = "m.key.verification.request")] KeyVerificationRequest, @@ -229,6 +233,7 @@ mod tests { serde_json_eq(EventType::KeyVerificationCancel, json!("m.key.verification.cancel")); serde_json_eq(EventType::KeyVerificationKey, json!("m.key.verification.key")); serde_json_eq(EventType::KeyVerificationMac, json!("m.key.verification.mac")); + serde_json_eq(EventType::KeyVerificationReady, json!("m.key.verification.ready")); serde_json_eq(EventType::KeyVerificationRequest, json!("m.key.verification.request")); serde_json_eq(EventType::KeyVerificationStart, json!("m.key.verification.start")); serde_json_eq(EventType::IgnoredUserList, json!("m.ignored_user_list")); diff --git a/crates/ruma-events/src/key/verification/ready.rs b/crates/ruma-events/src/key/verification/ready.rs index a23674e9..3767ec45 100644 --- a/crates/ruma-events/src/key/verification/ready.rs +++ b/crates/ruma-events/src/key/verification/ready.rs @@ -1,6 +1,6 @@ //! Types for the *m.key.verification.ready* event. -use ruma_events_macros::MessageEventContent; +use ruma_events_macros::{EventContent, MessageEventContent}; use ruma_identifiers::DeviceIdBox; use serde::{Deserialize, Serialize}; @@ -10,7 +10,25 @@ use crate::MessageEvent; /// Response to a previously sent *m.key.verification.request* message. pub type ReadyEvent = MessageEvent; -/// The payload for `ReadyEvent`. +/// The payload for a to-device `m.key.verification.ready` event. +#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] +#[ruma_event(type = "m.key.verification.ready")] +pub struct ReadyToDeviceEventContent { + /// The device ID which is initiating the request. + pub from_device: DeviceIdBox, + + /// The verification methods supported by the sender. + pub methods: Vec, + + /// An opaque identifier for the verification process. + /// + /// Must be unique with respect to the devices involved. Must be the same as the + /// `transaction_id` given in the *m.key.verification.request* from a + /// request. + pub transaction_id: String, +} + +/// The payload for an in-room `m.key.verification.ready` event. #[derive(Clone, Debug, Deserialize, Serialize, MessageEventContent)] #[ruma_event(type = "m.key.verification.ready")] pub struct ReadyEventContent { @@ -33,7 +51,7 @@ mod tests { use ruma_serde::Raw; use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; - use super::{ReadyEventContent, Relation, VerificationMethod}; + use super::{ReadyEventContent, ReadyToDeviceEventContent, Relation, VerificationMethod}; #[test] fn serialization() { @@ -50,12 +68,26 @@ mod tests { }); let content = ReadyEventContent { - from_device: device, + from_device: device.clone(), relation: Relation { event_id }, methods: vec![VerificationMethod::MSasV1], }; assert_eq!(to_json_value(&content).unwrap(), json_data); + + let json_data = json!({ + "from_device": device, + "methods": ["m.sas.v1"], + "transaction_id": "456", + }); + + let content = ReadyToDeviceEventContent { + from_device: device, + transaction_id: "456".to_owned(), + methods: vec![VerificationMethod::MSasV1], + }; + + assert_eq!(to_json_value(&content).unwrap(), json_data); } #[test] @@ -87,5 +119,25 @@ mod tests { && methods == vec![VerificationMethod::MSasV1] && event_id == id ); + + let json_data = json!({ + "from_device": device, + "methods": ["m.sas.v1"], + "transaction_id": "456", + }); + + assert_matches!( + from_json_value::>(json_data) + .unwrap() + .deserialize() + .unwrap(), + ReadyToDeviceEventContent { + from_device, + transaction_id, + methods, + } if from_device == device + && methods == vec![VerificationMethod::MSasV1] + && transaction_id == "456" + ); } }