This section presents two enveloping methods. Both use CBOR tags in a way that results in a deterministic first 8 to 12 bytes. The Protocol designer determines which one to use; see
Appendix A for some guidance.
In both enveloping methods, CBOR Protocol designers need to obtain a CBOR tag for each kind of object that they might store in files. As there are more than 4 billion available 4-byte tags, there should be little issue in allocating a few to each available CBOR Protocol.
The IANA policy for 4-byte CBOR tags is First Come First Served [
RFC 8126] so only a simple interaction (e.g., via Web or email) with IANA is required. The interaction includes filling in the small template provided in
Section 9.2 of [
STD94]. In the template, a reference to this specification (RFC 9277) alongside the Description of semantics is suggested.
Allocation of the CBOR tag needs to be initiated by the designer of the CBOR Protocol, who can provide a proposed tag number. In order to be in the 4-byte range, and so that there are no leading zero bytes in the 4-byte encoding of the tag number, the value needs to be in the range 0x01000000 (decimal 16777216) to 0xFFFFFFFF (decimal 4294967295) inclusive. It is further suggested to avoid values that have an embedded zero byte in the 4 bytes of their binary representation (such as 0x12003456), as these may confuse implementations that treat the magic number as a C string.
The use of a sequence of four ASCII [
RFC20] codes which are mnemonic to the protocol is encouraged, but not required (there may be reasons to encode other information into the tag; see
Appendix B for an example). For instance,
Appendix C uses "OPSN", which translates to the tag number 1330664270 registered for it.
In [
IANA.CORE-PARAMETERS], the Constrained Application Protocol (CoAP) defines the "CoAP Content-Formats" registry to assign Content-Format Numbers (
Section 12.3 of
RFC 7252) to Content Types in a specific Content Coding. For CBOR data items that form a representation that is already described by such a Content-Format Number, a tag number has proactively been allocated in
Section 4.3 (see
Appendix B for details and examples).
The CBOR Tag Wrapped method is appropriate for use with CBOR Protocols that encode a single CBOR data item. This data item is enveloped into two nested tags:
The outer tag is a self-described CBOR tag, 55799, as described in
Section 3.4.6 of [
STD94].
The tag content of the outer tag is a second CBOR tag whose tag number has been allocated to describe the specific Protocol involved, as discussed in
Section 2.1. The tag content of this inner tag is the single CBOR data item.
This method wraps the CBOR data item as CBOR tags usually do. Applications that need to send the stored CBOR data item across a constrained network may wish to remove the two tags if the type is understood from the protocol context, e.g., from a CoAP Content-Format Option (
Section 5.10.3 of
RFC 7252). Therefore, a CBOR Protocol specification may pick the specific cases where the CBOR Tag Wrapped enveloping method is to be used. For instance, it might specify its use for storing the representation in a local file or for Web access, but not within protocol messages that already provide the necessary context.
To construct an example without registering a new tag, we use the Content-Format ID assigned for
application/senml+cbor (112) [
RFC 8428] of the "CoAP Content-Formats" registry [
IANA.CORE-PARAMETERS]).
Using the technique described in
Appendix B, this translates into the tag TN(112) = 1668546929.
With this tag, the SenML-CBOR pack
[{0: "current", 6: 3, 2: 1.5}] would be enveloped as follows (in diagnostic notation):
55799(1668546929([{0: "current", 6: 3, 2: 1.5}]))
Or in hex:
d9 d9f7 # tag(55799)
da 63740171 # tag(1668546929)
81 # array(1)
a3 # map(3)
00 # unsigned(0)
67 # text(7)
63757272656e74 # "current"
06 # unsigned(6)
03 # unsigned(3)
02 # unsigned(2)
f9 3e00 # primitive(15872)
At the representation level, the unique fingerprint for
application/senml+cbor is composed of the 8 bytes d9d9f7da63740171 hex, after which the unadorned CBOR data (81... for the SenML data) is appended.
The Labeled CBOR Sequence method is appropriate for use with CBOR Sequences as described in [
RFC 8742].
This method prepends a newly constructed, separate data item to the CBOR Sequence, the
label.
The label is a nesting of two tags, similar to but distinct from the CBOR Tag Wrapped methods, with an inner tag content of a constant byte string. The total length of the label is 12 bytes.
-
The outer tag is the self-described CBOR Sequence tag, 55800.
-
The inner tag is a CBOR tag from the First Come First Served space that uniquely identifies the CBOR Protocol. As with the CBOR Tag Wrapped method, the use of a 4-byte tag that encodes without zero bytes is encouraged.
-
The tag content is a 3-byte CBOR byte string containing 0x42_4f_52 ('BOR' in diagnostic notation).
The outer tag in the label identifies the file as being a CBOR Sequence and does so with all the desirable properties explained in
Section 3.4.6 of [
STD94]. Specifically, it does not appear to conflict with any known file types, and it is not valid Unicode in any Unicode encoding.
The inner tag in the label identifies which CBOR Protocol is used, as described above.
The inner tag content is a constant byte string that is represented as 0x43_42_4f_52, the ASCII characters "CBOR", which is the CBOR-encoded data item for the 3-byte string 0x42_4f_52 ('BOR' in diagnostic notation).
The actual CBOR Protocol data then follows as the next data item(s) in the CBOR Sequence, without a need for any further specific tag. The use of a CBOR Sequence allows the application to trivially remove the first item with the two tags.
Should this file be reviewed by a human (directly in an editor or in a hexdump display), it will include the ASCII characters "CBOR" prominently. This value is also included simply because the inner nested tag needs to tag something.
To construct an example without registering a new tag, we use ID 272 as assigned for
application/missing-blocks+cbor-seq of the "CoAP Content-Formats" registry [
RFC 9177].
Using the technique described in
Appendix B, this translates into the tag TN(272) = 1668547090.
This is a somewhat contrived example, as this is not a media type that is likely to be committed to storage. Nonetheless, with this tag, missing blocks list
0, 8, 15 would be enveloped as (in diagnostic notation):
55800(1668547090('BOR')),
0,
8,
15
Or in hex:
# CBOR sequence with 4 elements
d9 d9f8 # tag(55800)
da 63740212 # tag(1668547090)
43 # bytes(3)
424f52 # "BOR"
00 # unsigned(0)
08 # unsigned(8)
0f # unsigned(15)
At the representation level, the unique fingerprint for
application/missing-blocks+cbor-seq is composed of the 8 bytes d9d9f8da63740212 hex, after which the unadorned CBOR sequence (00... for the missing block list given) is appended.