You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 15, 2021. It is now read-only.
Support for CBOR tagged values is the most requested feature in serde_cbor (see #3, #56, #129, #151). Tags allow users to "give [a data item] additional semantics while retaining its structure". They enable the definition of common data types and they are needed to correctly implement some specifications that use CBOR (see for example COSE).
There is a hack (with a few variations) commonly suggested to implement tags: Create a struct with a special name and two fields, one for the tag and another for the value. Now use this type to represent tagged values and give it special treatment in the Serializer and Deserializer` to convert tags.
This has two downsides:
If the name of the special struct occurs (or is introduced by an attacker) in a CBOR document the deserialization breaks.
Serde decouples data formats and data types. The hack forces a coupling between the two.
If a CBOR deserializer emits a tag but the data type does not expect one the deserialization fails (or produces wrong results).
If a data type emits its tag to a serializer other than the CBOR serializer an artifact from the tag is found in the output.
Design criteria
The changes made in serde should be small and must be backwards-compatible (that is: not require changes to existing data formats).
Do not rely on features not yet available in stable rust (such as specialization).
Tagged values must be ignored by data formats and data types alike if they are not supported.
The solution should not be limited to CBOR but work for other data formats that use tags as well.
Support for CBOR tagged values is the most requested feature in serde_cbor (see #3, #56, #129, #151). Tags allow users to "give [a data item] additional semantics while retaining its structure". They enable the definition of common data types and they are needed to correctly implement some specifications that use CBOR (see for example COSE).
There is a hack (with a few variations) commonly suggested to implement tags: Create a struct with a special name and two fields, one for the tag and another for the value. Now use this type to represent tagged values and give it special treatment in the
Serializer andDeserializer` to convert tags.This has two downsides:
Design criteria
serde_cbor::Values with tags.Tasks
serde::ser::Serializertrait to allow the serialization of tagged values. (branch)serde::de::Visitorto visit a tagged value and make other necessary changes for deserialization.serde_cbor. (exprimental branch)serde_cbor.Taggedvariant toserde_cbor::Valueurl::Urlwith tag 32