Skip to content

serde serialization helpers for non-self-describing storage representations - #2034

Merged
wysiwys merged 33 commits into
mainfrom
wysiwys/serialization-helpers
Jun 9, 2026
Merged

wysiwys merged 33 commits into
mainfrom
wysiwys/serialization-helpers

Conversation

@wysiwys

@wysiwys wysiwys commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

This pull request proposes adding serialization helper macros for use with serde non-self-describing formats, which pin the storage tag index used for each enum variant. It uses these macros to pin storage tags for Proposal/ProposalType, Extension/ExtensionType, and CredentialType, and also adds an openmls_compat_tests crate which includes tests for storage tag stability across openmls versions. This PR was initially opened as a starting point for discussion.


As a basis for discussion, this draft pull request proposes a way to address some issues with non-self-describing serde serialization that were identified in #2021. Since non-self-describing serde formats serialize enum variants using a tag corresponding to the variant's position in the list of variants, when new versions of openmls added new variants to some serializable enums (e.g. CredentialType::Grease(_)) or removed some from others (e.g. Proposal::AppAck), the position of some existing variants was affected, leading to deserialization failures.

To prevent these kinds of deserialization issues in the future, this draft PR proposes pinning a fixed storage tag for each enum variant, so that it is not affected by future removals or additions of variants. The proposed solution is implemented using serialization helper macros that can be used to implement serde::Serialize and serde::Deserialize traits on these enums. These macros allow specifying a storage_tag attribute on each variant, to pin it to a specific index:

#[derive(
    openmls_serialization_helpers::Serialize,
    openmls_serialization_helpers::Deserialize,
)]
#[allow(missing_docs)]
pub enum Proposal {
    #[storage_tag = 0]
    Add(Box<AddProposal>),
    #[storage_tag = 1]
    Update(Box<UpdateProposal>),
    #[storage_tag = 2]
    Remove(Box<RemoveProposal>),
    #[storage_tag = 3]
    PreSharedKey(Box<PreSharedKeyProposal>),
    #[storage_tag = 4]
    ReInit(Box<ReInitProposal>),
    #[storage_tag = 5]
    ExternalInit(Box<ExternalInitProposal>),
    #[storage_tag = 6]
    GroupContextExtensions(Box<GroupContextExtensionProposal>),
    // AppAck = 7,
    #[storage_tag = 8]
    SelfRemove,
    #[storage_tag = 9]
    Custom(Box<CustomProposal>),
    // # Extensions
    #[cfg(feature = "extensions-draft-08")]
    #[storage_tag = 10]
    AppDataUpdate(Box<AppDataUpdateProposal>),
    #[cfg(feature = "extensions-draft-08")]
    #[storage_tag = 11]
    AppEphemeral(Box<AppEphemeralProposal>),
}

Using this approach, new variants can be added to these enums in a way that ensures that their serde non-self-describing serialization does not conflict with existing serializations, independent of feature flag annotations on the enum variants.

In the openmls library, in this PR, these openmls_serialization_helpers macros are used to implement the serde::Serialize and serde::Deserialize traits for each of Proposal/ProposalType, Extension/ExtensionType, and CredentialType. The serde trait implementations using the macros corresponds to the individual implementations of these serde traits for these enums proposed in #2021.

This PR also reorders some enum variants so that enum variants are in ascending order by their storage_tag attribute for readability, but this list position no longer affects the index used in non-self-describing serde serialization.

@wysiwys

wysiwys commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@tylerhawkes

@tylerhawkes

Copy link
Copy Markdown
Contributor

This is more maintainable and easier to reason about than what I had in #2023 and #2026. Thanks!

@franziskuskiefer franziskuskiefer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is the right approach. Let's clean it up and make it mergeable unless someone has a better idea.

Comment thread openmls/src/credentials/mod.rs Resolved
Comment thread serialization_helpers/src/serialize.rs Resolved
Comment thread openmls/tests/migration_example.rs Resolved
Comment thread serialization_helpers/src/serialize.rs Resolved
Comment thread openmls/tests/migration_example.rs Resolved
@github-actions github-actions Bot added size/xl and removed size/l labels May 28, 2026
@wysiwys
wysiwys marked this pull request as ready for review May 28, 2026 13:18
@wysiwys
wysiwys requested a review from a team as a code owner May 28, 2026 13:18
@wysiwys
wysiwys requested a review from franziskuskiefer June 2, 2026 07:22

@franziskuskiefer franziskuskiefer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a few more nits and there are a few open comments.

I think the most important one is on documentation. This is a breaking change for storage when upgrading from 0.8.1. Is there a way to help consumers with that? Is there something to test on that?

Comment thread serialization_helpers/src/serialize.rs Resolved
Comment thread compat_tests/Cargo.toml Resolved

@franziskuskiefer franziskuskiefer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's first get #2047 merged in here. Then this is good to go.

@wysiwys
wysiwys enabled auto-merge (squash) June 9, 2026 08:56

@franziskuskiefer franziskuskiefer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's get this in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants