Repository navigation
Stabilize serde variant indices for persisted enums - #2023
Closed
tylerhawkes wants to merge 1 commit into
Closed
tylerhawkes wants to merge 1 commit into
tylerhawkes wants to merge 1 commit into
Conversation
`ProposalType`, `Proposal`, `Extension`, `ExtensionType`, and `CredentialType` all gained variants since openmls-0.7.1 in positions that shifted the serde variant index. Self-describing formats (JSON, CBOR) deserialize enum variants by name and are unaffected, but non-self-describing formats like bincode and postcard decode the variant tag as a positional `u32`. A persisted `Proposal::Custom`, `Proposal::SelfRemove`, `Extension::Unknown`, `ExtensionType::Unknown`, or `CredentialType::Other` written by openmls-0.7.x deserializes as some other variant on the current main branch, silently corrupting state. Restore the 0.7.x variant order and append all new variants (`Grease`, `AppEphemeral`, `AppDataUpdate`, `AppDataDictionary`) at the end of each enum. For the removed `AppAck` variant on `Proposal` and `ProposalType`, introduce a hidden `_AppAck` placeholder at index 7 (with `#[serde(rename = "AppAck")]` to preserve the JSON variant name) so subsequent variant indices stay stable. `AppAck` was never produced by the library so no real persisted data round-trips through this variant. Also extends the variant-order comment on the four enums with feature-gated variants (`ProposalType`, `Proposal`, `Extension`, `ExtensionType`) with a note that new non-optional variants must not be added after a `#[cfg(feature = ...)]` variant — toggling the feature would otherwise shift every following index for non-self-describing formats. Match arms in `messages/codec.rs`, `messages/proposals_in.rs`, and `group/mls_group/proposal_store.rs` are updated to cover the new `_AppAck` variant (`unreachable!()`, since the placeholder is never produced at runtime).
This was referenced May 15, 2026
Contributor
|
Closing this PR in favor of the changes in #2034 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bincode and postcard encode enum variant tags as positional u32s, so when
variants get inserted mid-declaration the index of every following variant
shifts and persisted data silently decodes as the wrong variant.
Since 0.7.x,
ProposalType/Proposal,Extension/ExtensionType, andCredentialTypehave all had variants added (Grease,AppEphemeral,AppDataUpdate,AppDataDictionary) — andAppAckremoved fromProposal/ProposalType— in positions that shift the indices.This PR restores the 0.7.x order, appends every new variant to the end,
and replaces the removed
AppAckwith a hidden_AppAckunit placeholderat its original index 7. JSON/CBOR variant names, the TLS wire format,
and the public API are all unchanged.
The four enums with feature-gated variants also get a note in the
existing variant-order comment: new non-optional variants must not be
added after a
#[cfg(feature = ...)]variant, because toggling thefeature would otherwise shift every following index and silently corrupt
persisted data.
This means that for non human-readable serde implementations that after a
non-optional variant is added that enabling the feature would be a breaking
change for consumers of the library.
On the
_AppAckplaceholderOpen to discussion. The placeholder is doing two jobs: it occupies index 7
(which no real persisted data hits — openmls never produced
AppAck) and,more importantly, it keeps
SelfRemoveat index 8 andCustomat index 9,which 0.7.x bincode/postcard data does hit. Without the placeholder,
persisted
Custom(N: u16)silently decodes asGrease(N)onProposalType, and persistedSelfRemoveeither fails or silentlycorrupts on
Proposal.The cost is that exhaustive matches on
Proposal/ProposalTypeinexternal code need an
_AppAckarm. If a tidier alternative is preferred,marking these enums
#[non_exhaustive]as a one-time API change wouldlet the placeholder be dropped and the variant deleted cleanly — happy
to take that direction.
This can go away by using #2026 for the serde impls which wouldn't break 0.8 users.
Split from #2021.