diff --git a/crates/ruma-events-macros/src/event.rs b/crates/ruma-events-macros/src/event.rs index 0bf7f97c..b2b1946b 100644 --- a/crates/ruma-events-macros/src/event.rs +++ b/crates/ruma-events-macros/src/event.rs @@ -17,7 +17,7 @@ pub fn expand_event(input: DeriveInput) -> syn::Result { let ident = &input.ident; let (kind, var) = to_kind_variation(ident).ok_or_else(|| { - syn::Error::new(Span::call_site(), "not a valid ruma event struct identifier") + syn::Error::new_spanned(ident, "not a valid ruma event struct identifier") })?; let fields: Vec<_> = if let Data::Struct(DataStruct { fields, .. }) = input.data.clone() { diff --git a/crates/ruma-events-macros/src/event_content.rs b/crates/ruma-events-macros/src/event_content.rs index 88f3e6e7..7df3258b 100644 --- a/crates/ruma-events-macros/src/event_content.rs +++ b/crates/ruma-events-macros/src/event_content.rs @@ -313,8 +313,9 @@ fn generate_event_content_derives( EventKind::Message => Ok(quote! { MessageEventContent }), EventKind::State => Ok(quote! { StateEventContent }), EventKind::ToDevice => Ok(quote! { ToDeviceEventContent }), - EventKind::Redaction => Err(syn::Error::new_spanned(ident, msg)), - EventKind::Presence => Err(syn::Error::new_spanned(ident, msg)), + EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => { + Err(syn::Error::new_spanned(ident, msg)) + } }) .collect::>()?; diff --git a/crates/ruma-events-macros/src/event_parse.rs b/crates/ruma-events-macros/src/event_parse.rs index 97343450..1ffe806c 100644 --- a/crates/ruma-events-macros/src/event_parse.rs +++ b/crates/ruma-events-macros/src/event_parse.rs @@ -71,6 +71,7 @@ pub enum EventKind { ToDevice, Redaction, Presence, + Decrypted, } impl fmt::Display for EventKind { @@ -84,6 +85,7 @@ impl fmt::Display for EventKind { EventKind::ToDevice => write!(f, "ToDeviceEvent"), EventKind::Redaction => write!(f, "RedactionEvent"), EventKind::Presence => write!(f, "PresenceEvent"), + EventKind::Decrypted => unreachable!(), } } } @@ -203,6 +205,9 @@ pub fn to_kind_variation(ident: &Ident) -> Option<(EventKind, EventKindVariation "PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)), "RedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Full)), "SyncRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Sync)), + "DecryptedOlmV1Event" | "DecryptedMegolmV1Event" => { + Some((EventKind::Decrypted, EventKindVariation::Full)) + } _ => None, } } diff --git a/crates/ruma-events-macros/src/event_type.rs b/crates/ruma-events-macros/src/event_type.rs index 028de31c..d98d36f2 100644 --- a/crates/ruma-events-macros/src/event_type.rs +++ b/crates/ruma-events-macros/src/event_type.rs @@ -31,8 +31,7 @@ pub fn expand_event_type_enum( room.push(&event.events); } EventKind::ToDevice => to_device.push(&event.events), - EventKind::Redaction => {} - EventKind::Presence => {} + EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => {} } } let presence = vec![EventEnumEntry { diff --git a/crates/ruma-events/CHANGELOG.md b/crates/ruma-events/CHANGELOG.md index 292c1f69..a75dbca3 100644 --- a/crates/ruma-events/CHANGELOG.md +++ b/crates/ruma-events/CHANGELOG.md @@ -11,6 +11,14 @@ Breaking changes: * Remove `Custom` variant from `key::verification::accept::AcceptMethod` and `key::verification::start::StartMethod`. +Improvements: + +* Add types for decrypted `m.room.encryption` event payloads (`DecryptedOlmV1Event`, + `DecryptedMegolmV1Event`) + * Currently, these don't have corresponding enums (and they might never get ones), instead to + represent a decrypted event payload with an unknown event type use `AnyMessageEventContent` for + the generic parameter + # 0.22.2 Improvements: diff --git a/crates/ruma-events/src/event_kinds.rs b/crates/ruma-events/src/event_kinds.rs index 20cf1284..40ec726c 100644 --- a/crates/ruma-events/src/event_kinds.rs +++ b/crates/ruma-events/src/event_kinds.rs @@ -3,6 +3,7 @@ use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_events_macros::Event; use ruma_identifiers::{EventId, RoomId, UserId}; +use serde::{Deserialize, Serialize}; use crate::{ EphemeralRoomEventContent, GlobalAccountDataEventContent, MessageEventContent, @@ -327,3 +328,39 @@ pub struct ToDeviceEvent { /// The fully-qualified ID of the user who sent this event. pub sender: UserId, } + +/// The decrypted payload of an `m.olm.v1.curve25519-aes-sha2` event. +#[derive(Clone, Debug, Event)] +pub struct DecryptedOlmV1Event { + /// Data specific to the event type. + pub content: C, + + /// The fully-qualified ID of the user who sent this event. + pub sender: UserId, + + /// The fully-qualified ID of the intended recipient this event. + pub recipient: UserId, + + /// The recipient's ed25519 key. + pub recipient_keys: OlmV1Keys, + + /// The sender's ed25519 key. + pub keys: OlmV1Keys, +} + +/// Public keys used for an `m.olm.v1.curve25519-aes-sha2` event. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct OlmV1Keys { + /// An ed25519 key. + ed25519: String, +} + +/// The decrypted payload of an `m.megolm.v1.aes-sha2` event. +#[derive(Clone, Debug, Event)] +pub struct DecryptedMegolmV1Event { + /// Data specific to the event type. + pub content: C, + + /// The ID of the room associated with the event. + pub room_id: RoomId, +}