Skip to content

Commit a6ec092

Browse files
committed
refactor(crypto): Don't require event_type to return a static string
1 parent 6950b14 commit a6ec092

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

crates/matrix-sdk-crypto/src/gossiping/machine.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,15 @@ impl GossipMachine {
539539
device: &Device,
540540
content: SecretSendContent,
541541
) -> OlmResult<Session> {
542-
let event_type = content.event_type();
543-
let (used_session, content) = device.encrypt(event_type, content).await?;
542+
let event_type = content.event_type().to_owned();
543+
let (used_session, content) = device.encrypt(&event_type, content).await?;
544+
545+
let encrypted_event_type = content.event_type().to_owned();
544546

545547
let request = ToDeviceRequest::new(
546548
device.user_id(),
547549
device.device_id().to_owned(),
548-
content.event_type(),
550+
&encrypted_event_type,
549551
content.cast(),
550552
);
551553

@@ -568,10 +570,12 @@ impl GossipMachine {
568570
let (used_session, content) =
569571
device.encrypt_room_key_for_forwarding(session.clone(), message_index).await?;
570572

573+
let event_type = content.event_type().to_owned();
574+
571575
let request = ToDeviceRequest::new(
572576
device.user_id(),
573577
device.device_id().to_owned(),
574-
content.event_type(),
578+
&event_type,
575579
content.cast(),
576580
);
577581

crates/matrix-sdk-crypto/src/identities/device.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,19 @@ impl Device {
425425
session: InboundGroupSession,
426426
message_index: Option<u32>,
427427
) -> OlmResult<(Session, Raw<ToDeviceEncryptedEventContent>)> {
428-
let (event_type, content) = {
428+
let content: ForwardedRoomKeyContent = {
429429
let export = if let Some(index) = message_index {
430430
session.export_at_index(index).await
431431
} else {
432432
session.export().await
433433
};
434-
let content: ForwardedRoomKeyContent = export.try_into()?;
435434

436-
(content.event_type(), content)
435+
export.try_into()?
437436
};
438437

439-
self.encrypt(event_type, content).await
438+
let event_type = content.event_type().to_owned();
439+
440+
self.encrypt(&event_type, content).await
440441
}
441442

442443
/// Encrypt an event for this device.
@@ -832,9 +833,9 @@ impl DeviceData {
832833
) -> OlmResult<MaybeEncryptedRoomKey> {
833834
let content = session.as_content().await;
834835
let message_index = session.message_index().await;
835-
let event_type = content.event_type();
836+
let event_type = content.event_type().to_owned();
836837

837-
match self.encrypt(store, event_type, content).await {
838+
match self.encrypt(store, &event_type, content).await {
838839
Ok((session, encrypted)) => Ok(MaybeEncryptedRoomKey::Encrypted {
839840
share_info: ShareInfo::new_shared(
840841
session.sender_key().to_owned(),

crates/matrix-sdk-crypto/src/session_manager/sessions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ impl SessionManager {
153153
let (_, content) =
154154
device.encrypt("m.dummy", ToDeviceDummyEventContent::new()).await?;
155155

156+
let event_type = content.event_type().to_owned();
157+
156158
let request = ToDeviceRequest::new(
157159
device.user_id(),
158160
device.device_id().to_owned(),
159-
content.event_type(),
161+
&event_type,
160162
content.cast(),
161163
);
162164

crates/matrix-sdk-crypto/src/types/events/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait EventType {
4242
///
4343
/// **Note**: This should never be implemented manually, this takes the
4444
/// event type from the constant.
45-
fn event_type(&self) -> &'static str {
45+
fn event_type(&self) -> &str {
4646
Self::EVENT_TYPE
4747
}
4848
}

0 commit comments

Comments
 (0)