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

feat(crypto): Add optional withheld reason to UnableToDecryptReason #4305

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

BillCarsonFr
Copy link
Member

Fixes #4270

  • Public API changes documented in changelogs (optional)

Signed-off-by:

@BillCarsonFr BillCarsonFr force-pushed the valere/support_for_withheld_reason branch from 9abe4ba to ea5fcdb Compare November 28, 2024 08:54
@BillCarsonFr BillCarsonFr marked this pull request as ready for review November 28, 2024 08:54
@BillCarsonFr BillCarsonFr requested review from a team as code owners November 28, 2024 08:54
@BillCarsonFr BillCarsonFr requested review from bnjbvr and richvdh and removed request for a team November 28, 2024 08:54
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.

Project coverage is 85.11%. Comparing base (a4434d7) to head (6801811).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...es/matrix-sdk-crypto/src/types/events/utd_cause.rs 20.00% 4 Missing ⚠️
...es/matrix-sdk-common/src/deserialized_responses.rs 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4305      +/-   ##
==========================================
- Coverage   85.15%   85.11%   -0.05%     
==========================================
  Files         280      280              
  Lines       30826    30837      +11     
==========================================
- Hits        26251    26248       -3     
- Misses       4575     4589      +14     

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

@poljar poljar requested review from poljar and removed request for bnjbvr November 28, 2024 09:12
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

Looks like a sensible direction to me; a few comments though

Mostly I'd like to know if we can avoid introducing yet another type

crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto/src/types/events/utd_cause.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto/src/types/events/utd_cause.rs Outdated Show resolved Hide resolved
@BillCarsonFr BillCarsonFr requested a review from richvdh December 2, 2024 09:29
richvdh
richvdh previously requested changes Dec 2, 2024
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
Comment on lines 804 to 805
// Wrapper around `Box<str>` that cannot be used in a meaningful way outside of
// this crate. Used for string enums because their `_Custom` variant can't be
Copy link
Member

Choose a reason for hiding this comment

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

cannot be used in a meaningful way outside of this crate

It's used in matrix-sdk-crypto, so that doesn't seem right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that seems like a copy-paste error.

Perhaps we should just remove that line.

Comment on lines 809 to 823
// XXX had to make the field public to make ruma `StringEnum` macro happy.
pub struct PrivOwnedStr(pub Box<str>);
Copy link
Member

Choose a reason for hiding this comment

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

It strikes me it's not really a PrivOwnedStr if it's pub.

I don't really understand what's going on here (why does it need to be pub now when it didn't before?), but I see you discussed this with @poljar, so I'm happy if he's happy. @poljar can you confirm this is what you were envisaging?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes nothing makes sense with the struct anymore (the name, the doc, ..)
Not sure how to properly document it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Ruma macro expects the type to have this name, it's not something that is in under our control...

The alternatives are to not use the Ruma macro or to have multiple copies of this struct.

Copy link
Member

Choose a reason for hiding this comment

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

ok, fair enough. It would be helpful if this could be explained in a comment.

Why does this need to be pub, when it didn't need to be pub when it lived in the crypto crate?

Copy link
Member Author

@BillCarsonFr BillCarsonFr Dec 3, 2024

Choose a reason for hiding this comment

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

1f50e4b

when it didn't need to be pub when it lived in the crypto crate

Because it is also used by other enums (still in crypto) that now uses the one that is in common.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually there was another copy left 2151fcd

I would be ok to revert that and have multiple copies if it makes it simpler

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be pub, when it didn't need to be pub when it lived in the crypto crate?

Because otherwise you can't construct the variant outside of the crate where the type lives unless it's pub. Now I don't exactly know where that is needed but if we remove the pub the compiler might tell us.

Copy link
Member Author

Choose a reason for hiding this comment

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

For EventEncryptionAlgorithm

error[E0616]: field `0` of struct `matrix_sdk_common::deserialized_responses::PrivOwnedStr` is private
   --> crates/matrix-sdk-crypto/src/types/mod.rs:430:49
    |
430 | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
    |                                                 ^^^^^^^^^^ private field
    |
    = note: this error originates in the derive macro `StringEnum` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0423]: cannot initialize a tuple struct which contains private fields

crates/matrix-sdk-crypto/src/types/events/utd_cause.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

LGTM now, with the exception of PrivOwnedStr, for which I defer to @poljar

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Left a small nit, I think the rest looks good.

crates/matrix-sdk-crypto/src/types/events/utd_cause.rs Outdated Show resolved Hide resolved
Comment on lines 809 to 823
// XXX had to make the field public to make ruma `StringEnum` macro happy.
pub struct PrivOwnedStr(pub Box<str>);
Copy link
Contributor

Choose a reason for hiding this comment

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

The Ruma macro expects the type to have this name, it's not something that is in under our control...

The alternatives are to not use the Ruma macro or to have multiple copies of this struct.

Comment on lines 804 to 805
// Wrapper around `Box<str>` that cannot be used in a meaningful way outside of
// this crate. Used for string enums because their `_Custom` variant can't be
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that seems like a copy-paste error.

Perhaps we should just remove that line.

@BillCarsonFr BillCarsonFr force-pushed the valere/support_for_withheld_reason branch from 2151fcd to 8f8cd17 Compare December 4, 2024 12:07
Adds new UtdCause variants for withheld keys, enabling applications to display customised messages when an Unable-To-Decrypt message is expected.

refactor(crypto): Move WithheldCode from crypto to common crate
@BillCarsonFr BillCarsonFr force-pushed the valere/support_for_withheld_reason branch from f09b3e4 to 6801811 Compare December 4, 2024 14:33
@BillCarsonFr BillCarsonFr merged commit 1009ea8 into main Dec 4, 2024
39 of 40 checks passed
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.

Message key "withheld" reasons are not shown in UI nor reported to Posthog
3 participants