-
Notifications
You must be signed in to change notification settings - Fork 33
Unknown extension caching #249
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
Merged
Merged
+698
−10
Conversation
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
7ced41a to
fb89151
Compare
thomas-fossati
approved these changes
Dec 12, 2025
Contributor
thomas-fossati
left a comment
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
fb89151 to
49dec33
Compare
Allow caching of unknown fields during PopulateStructFrom(CBOR|JSON). The cache is then used during SerializeStructTo(CBOR|JSON). This ensures that any map entries in the source data that do not correspond to target struct fields are preserved across decode/encode cycle. This feature is enabled by adding a field to a struct tagged with `field-cache:""`. This field must be of type map[string]any. When PopulateStructFrom* functions encounter input entries that do not correspond to a field in the target struct, they will be added to the field-cache map instead. Analogously, when SerializeStructTo* functions see a field-cache map, they will add its entries to the output. This scheme has some (hopefully, obvious) limitations: - field-cache field's tag must also contain `cbor:"-" json:"-"` to make sure that the field itself will be ignored by serializers. - if a struct is unmarshaled from JSON, any unknown field names must be "stringified" integers, otherwise it is impossible to obtain the corresponding CBOR code point mapping for the name. Signed-off-by: Sergei Trofimov <[email protected]>
Up to this point, we only had deterministic encoding for structs. Fields
were encoded in the order they appeared.
This fix ensures that fields are encoded in lexicographic order as
required by CDE spec:
https://www.ietf.org/archive/id/draft-ietf-cbor-cde-13.html#name-the-lexicographic-map-sorti
(Note: we typically define fields in the order of their code points, so
in practice, we have been _mostly_ compliant with CDE; but this was not
guaranteed, and deviations were possible, especially when extensions are
involved.)
Signed-off-by: Sergei Trofimov <[email protected]>
d33a654 to
68e1c10
Compare
Extensions objects will now cache any extensions they don't recognize (that don't correspond to a field inside their registered IMapValue) when deserializing values. This means CORIMs with extensions remain stable when deserialized and then re-serialized using structs without registered extensions. Cached extensions are only used during marshalling, and will not be returned when calling the Get* methods. However they can be accessed directly via Extensions.Cached field. When an IMapValue struct is registered, cached values are scanned, and the new struct is populated with cached values, which are then removed form the cache. When registering a new struct when there is an existing IMapValue, the non-zero-value fields of the old IMapValue are stored in the cache. Signed-off-by: Sergei Trofimov <[email protected]>
7c276bf to
541f338
Compare
yogeshbdeshpande
approved these changes
Dec 12, 2025
Contributor
yogeshbdeshpande
left a comment
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!
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.
This pull implements the caching of unknown extension values when unmarshalling CoRIMs. Cached values are then incorporated when re-marshalling. This ensures that a CoRIM is preserved in its entirety across re-marshalling, even when containing extension values that do not correspond to fields in registered extension structs inside the unmarshal target.
This is necessary to support future migration of Veraison services to use corim-store, which will require lossless handling of CoRIMs without awareness of scheme-specific extensions.
Additionally, this ensures CDE compliance when marshalling to CBOR.