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

CBOR: Basic Support for Tags #2359

Closed
wants to merge 6 commits into from

Conversation

JesusMcCloud
Copy link
Contributor

@JesusMcCloud JesusMcCloud commented Jul 10, 2023

Introduces basic support for CBOR tags.

Basic means that no semantic checks are performed yet, so you freely use reserved tags (e.g. serialize a cornucopia of fruit and other produce using tags reserved for dates, URIs, MIME messages, negative bignums and so forth) and no error will be thrown.

  • New annotations ValueTags and KeyTags to specify tags for keys and values, respectively
    • Tags can be nested freely as specified in the annotations
    • By default, tags will be validated upon deserialization. If no annotations are present on a property, validation is omitted. Behaviour can be customized (see below).
    • By default, tags will be written as annotated. Behaviour can be customized (see below).
  • Introduces the following configuration parameters to the Cbor class (names are self-explanatory):
    • writeKeyTags
    • writeValueTags
    • verifyKeyTags
    • verifyValueTags

This is the first PR in a series of planned enhancements, but we still consider it valuable on its own (as it also affects #1560).

In the long run, we plan to support semantically correct serialization for all reserved CBOR tags. This includes separate contributions to koltinx.datetime and the native support for self-describing CBOR. The latter of which is planned to enable the deserialization of CBOR structures, while also enabling access to the original underlying raw byte-string. This is a crucial features for conveniently working with (i.e. verifying) signed data. (Which, in turn, is a requirement for a 100% pure Kotlin multiplatform COSE implementation.)
Hence, we want to use this opportunity to also collect early feedback from those who are more familiar with kotlinx.serialization than we are.

(ofc, this should be squashed prior to merging/rebasing)

@JesusMcCloud
Copy link
Contributor Author

Superseded by #2412. closing this one…

sandwwraith added a commit that referenced this pull request Jul 22, 2024
This PR contains all features required to serialize and parse COSE-compliant CBOR (thanks to @nodh). While some canonicalization steps (such as sorting keys) still need to be performed manually. It does get the job done quite well. Namely, we have successfully used the features introduced here to create and validate ISO/IEC 18013-5:2021-compliant mobile driving license data.

This PR introduces the following features to the CBOR format:

- Serial Labels
- Tagging of keys and values
- Definite length encoding (this is the largest change, as it effectively makes the cbor encoder two-pass)
- Option to globally prefer major type 2 for byte array encoding
- Various QoL changes, such as public CborEncoder/CborDecoder interfaces and separate CborConfiguration class.

This PR obsoletes #2371 and #2359 as it contains the features of both PRs and many more.

Fixes #1955
Fixes #1560

Co-authored-by: Christian Kollmann <[email protected]>
Co-authored-by: Leonid Startsev <[email protected]>
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.

1 participant