Skip to content
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

crypto: New return type for decrypt_room_event #4064

Merged
merged 1 commit into from
Oct 3, 2024
Merged

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Oct 3, 2024

I need to do a bit of a refactoring on TimelineEvent, so let's start by giving decrypt_room_event its own return type.

(some groundwork for #4048)

  • Public API changes documented in changelogs (optional)

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.56%. Comparing base (6de676f) to head (95a2d1f).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4064      +/-   ##
==========================================
- Coverage   84.57%   84.56%   -0.01%     
==========================================
  Files         267      267              
  Lines       28456    28461       +5     
==========================================
+ Hits        24067    24069       +2     
- Misses       4389     4392       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -423,6 +444,35 @@ impl fmt::Debug for TimelineEvent {
}
}

#[derive(Clone, Serialize, Deserialize)]
/// A successfully-decrypted encrypted event.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The casual reader might wonder why this is here, rather than in the crypto crate. The answer is that, in the fullness of time, I want to make TimelineEvent and SyncTimelineEvent wrap a DecryptedRoomEvent rather than duplicating the fields.

@richvdh richvdh marked this pull request as ready for review October 3, 2024 09:32
@richvdh richvdh requested review from a team as code owners October 3, 2024 09:32
@richvdh richvdh requested review from jmartinesp and BillCarsonFr and removed request for a team October 3, 2024 09:32
Copy link
Contributor

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question - looks good.

@@ -1818,14 +1818,9 @@ impl OlmMachine {
.await;
}

let event = serde_json::from_value::<Raw<AnyTimelineEvent>>(decrypted_event.into())?;
let event = serde_json::from_value::<Raw<AnyMessageLikeEvent>>(decrypted_event.into())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know state events aren't currently encrypted, but does the change from AnyTimelineEvent to AnyMessageLikeEvent here mean that we are assuming this is not a state event? Are we OK with that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.

Yes I am assuming this is not a state event, and that our lack of encryption for state events is not going to change any time soon. It felt like using the more specific type might be more useful for callers. It's also worth noting that situation can't change without changes elsewhere in the crypto crate (specifically we construct the JSON for the decrypted event in InboundGroupSession::decrypt).

On the other hand: maybe it's better we encourage callers to be ready for state events by continuing to return Raw<AnyTimelineEvent>.

I'd be interested in @poljar's thoughts here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't expect state events to be able to use the same mechanisms for encryption as we use for non-state events, perhaps I'm mistaken here but I would expect that they would be different enough to warrant a separate method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that they would be different enough to warrant a separate method.

I guess the point is that it's not just about a separate method: the intention is to embed DecryptedRoomEvent inside TimelineEvent and SyncTimelineEvent -- so we'll be hardcoding this knowledge there too.

That said: on the grand scale of changes that will be needed to support encrypted state events, I don't think changing this later is going to be that significant.

I want to do a bit of a refactoring on `TimelineEvent`, so let's start by
giving `decrypt_room_event` its own return type.
@richvdh richvdh merged commit 1d1863d into main Oct 3, 2024
40 checks passed
@richvdh richvdh deleted the rav/decryption_result branch October 3, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants