-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the DecryptedOlmV1Event
when encrypting to-device events
#4690
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4690 +/- ##
==========================================
+ Coverage 85.82% 85.84% +0.01%
==========================================
Files 292 292
Lines 33761 33779 +18
==========================================
+ Hits 28974 28996 +22
+ Misses 4787 4783 -4 ☔ View full report in Codecov by Sentry. |
bfe7f6a
to
4195afa
Compare
…-device events This ensures that new fields that are added to the `m.olm.v1.curve25519-aes-sha` content need to be added in a single place.
4195afa
to
ffbf31c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
// So we just leave EVENT_TYPE out. This works because the serialization is | ||
// using `event_type()` and this type is contained to this function. | ||
const EVENT_TYPE: &'static str = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So EVENT_TYPE
is useless and never used in this context, is that alright? If yes, maybe it should be said explicitly in the doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in all the other types that implement EventType
. Only this one implementation is a special hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume Ivan means we should add this to the documentation of this implementation, to which, +1.
// So we just leave EVENT_TYPE out. This works because the serialization is | |
// using `event_type()` and this type is contained to this function. | |
const EVENT_TYPE: &'static str = ""; | |
// We have to provide `EVENT_TYPE` to conform to the `EventType` trait, but | |
// don't actually use it, so we just leave it empty. | |
// | |
// This works because the serialization uses `event_type()` and this type is contained | |
// to this function. | |
const EVENT_TYPE: &'static str = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this. Thanks for clarifying my words.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general, a few nits
/// **Note**: This should never be implemented manually, this takes the | ||
/// event type from the constant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer true? Or at least, the word "never" should be softened to "not usually" or something.
You could fix the comma splice while you're there.
let (event_type, content) = { | ||
let content = { | ||
let export = if let Some(index) = message_index { | ||
session.export_at_index(index).await | ||
} else { | ||
session.export().await | ||
}; | ||
let content: ForwardedRoomKeyContent = export.try_into()?; | ||
|
||
(content.event_type(), content) | ||
content | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let (event_type, content) = { | |
let content = { | |
let export = if let Some(index) = message_index { | |
session.export_at_index(index).await | |
} else { | |
session.export().await | |
}; | |
let content: ForwardedRoomKeyContent = export.try_into()?; | |
(content.event_type(), content) | |
content | |
}; | |
let content: ForwardedRoomKeyContent = { | |
let export = if let Some(index) = message_index { | |
session.export_at_index(index).await | |
} else { | |
session.export().await | |
}; | |
export.try_into()? | |
}; |
let event_type = content.event_type().to_owned(); | ||
let (used_session, content) = device.encrypt(&event_type, content).await?; | ||
|
||
let event_type = content.event_type().to_owned(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line looks redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance one would think so. But the first event_type
is for content
while the second event_type
is for content
after the device.encrypt()
step.
Perhaps renaming the second content
to encrypted_content
might make this clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, yes. Some different names might help.
@@ -162,7 +162,10 @@ impl AnyDecryptedOlmEvent { | |||
} | |||
|
|||
/// An `m.olm.v1.curve25519-aes-sha2` decrypted to-device event. | |||
#[derive(Clone, Debug, Deserialize, Serialize)] | |||
/// | |||
/// **Note**: This event will reserialize events lossy, unknown fields will be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// **Note**: This event will reserialize events lossy, unknown fields will be | |
/// **Note**: This event will reserialize events lossily; unknown fields will be |
@@ -182,6 +185,52 @@ where | |||
pub content: C, | |||
} | |||
|
|||
impl<C: EventType + Debug + Sized + Serialize> Serialize for DecryptedOlmV1Event<C> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment as to why this is needed/what it does differently from derive(Serialize)
might be helpful.
// This is a bit of a hack, usually we just define the `EVENT_TYPE` and use the | ||
// default implementation of `event_type()`, we can't do this here | ||
// because the event type isn't static. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multi-way comma splice!
// This is a bit of a hack, usually we just define the `EVENT_TYPE` and use the | |
// default implementation of `event_type()`, we can't do this here | |
// because the event type isn't static. | |
// This is a bit of a hack: usually we just define the `EVENT_TYPE` and use the | |
// default implementation of `event_type()`. We can't do this here | |
// because the event type isn't static. |
// So we just leave EVENT_TYPE out. This works because the serialization is | ||
// using `event_type()` and this type is contained to this function. | ||
const EVENT_TYPE: &'static str = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume Ivan means we should add this to the documentation of this implementation, to which, +1.
// So we just leave EVENT_TYPE out. This works because the serialization is | |
// using `event_type()` and this type is contained to this function. | |
const EVENT_TYPE: &'static str = ""; | |
// We have to provide `EVENT_TYPE` to conform to the `EventType` trait, but | |
// don't actually use it, so we just leave it empty. | |
// | |
// This works because the serialization uses `event_type()` and this type is contained | |
// to this function. | |
const EVENT_TYPE: &'static str = ""; |
This requires a bit of a hack, but I think the stronger typing and having the fields defined in a single place make this worth it.