draft-ietf-cbor-7049bis-01.txt   draft-ietf-cbor-7049bis-02.txt 
Network Working Group C. Bormann Network Working Group C. Bormann
Internet-Draft Universitaet Bremen TZI Internet-Draft Universitaet Bremen TZI
Intended status: Standards Track P. Hoffman Intended status: Standards Track P. Hoffman
Expires: April 17, 2018 ICANN Expires: September 3, 2018 ICANN
October 14, 2017 March 02, 2018
Concise Binary Object Representation (CBOR) Concise Binary Object Representation (CBOR)
draft-ietf-cbor-7049bis-01 draft-ietf-cbor-7049bis-02
Abstract Abstract
The Concise Binary Object Representation (CBOR) is a data format The Concise Binary Object Representation (CBOR) is a data format
whose design goals include the possibility of extremely small code whose design goals include the possibility of extremely small code
size, fairly small message size, and extensibility without the need size, fairly small message size, and extensibility without the need
for version negotiation. These design goals make it different from for version negotiation. These design goals make it different from
earlier binary serializations such as ASN.1 and MessagePack. earlier binary serializations such as ASN.1 and MessagePack.
Contributing Contributing
skipping to change at page 1, line 40 skipping to change at page 1, line 40
targeted at becoming an Internet Standard. targeted at becoming an Internet Standard.
Status of This Memo Status of This Memo
This Internet-Draft is submitted in full conformance with the This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79. provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet- working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/. Drafts is at https://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress." material or to cite them other than as "work in progress."
This Internet-Draft will expire on April 17, 2018. This Internet-Draft will expire on September 3, 2018.
Copyright Notice Copyright Notice
Copyright (c) 2017 IETF Trust and the persons identified as the Copyright (c) 2018 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of (https://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1. Objectives . . . . . . . . . . . . . . . . . . . . . . . 4 1.1. Objectives . . . . . . . . . . . . . . . . . . . . . . . 4
1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 5 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 5
2. Specification of the CBOR Encoding . . . . . . . . . . . . . 6 2. CBOR Data Models . . . . . . . . . . . . . . . . . . . . . . 7
2.1. Major Types . . . . . . . . . . . . . . . . . . . . . . . 7 2.1. Extended Generic Data Models . . . . . . . . . . . . . . 7
2.2. Indefinite Lengths for Some Major Types . . . . . . . . . 9 2.2. Specific Data Models . . . . . . . . . . . . . . . . . . 8
2.2.1. Indefinite-Length Arrays and Maps . . . . . . . . . . 9 3. Specification of the CBOR Encoding . . . . . . . . . . . . . 9
2.2.2. Indefinite-Length Byte Strings and Text Strings . . . 11 3.1. Major Types . . . . . . . . . . . . . . . . . . . . . . . 9
2.3. Floating-Point Numbers and Values with No Content . . . . 12 3.2. Indefinite Lengths for Some Major Types . . . . . . . . . 11
2.4. Optional Tagging of Items . . . . . . . . . . . . . . . . 14 3.2.1. Indefinite-Length Arrays and Maps . . . . . . . . . . 11
2.4.1. Date and Time . . . . . . . . . . . . . . . . . . . . 16 3.2.2. Indefinite-Length Byte Strings and Text Strings . . . 14
2.4.2. Bignums . . . . . . . . . . . . . . . . . . . . . . . 16 3.3. Floating-Point Numbers and Values with No Content . . . . 14
2.4.3. Decimal Fractions and Bigfloats . . . . . . . . . . . 16 3.4. Optional Tagging of Items . . . . . . . . . . . . . . . . 16
2.4.4. Content Hints . . . . . . . . . . . . . . . . . . . . 18 3.4.1. Date and Time . . . . . . . . . . . . . . . . . . . . 18
2.4.4.1. Encoded CBOR Data Item . . . . . . . . . . . . . 18 3.4.2. Bignums . . . . . . . . . . . . . . . . . . . . . . . 19
2.4.4.2. Expected Later Encoding for CBOR-to-JSON 3.4.3. Decimal Fractions and Bigfloats . . . . . . . . . . . 19
Converters . . . . . . . . . . . . . . . . . . . 18 3.4.4. Content Hints . . . . . . . . . . . . . . . . . . . . 21
2.4.4.3. Encoded Text . . . . . . . . . . . . . . . . . . 19 3.4.4.1. Encoded CBOR Data Item . . . . . . . . . . . . . 21
2.4.5. Self-Describe CBOR . . . . . . . . . . . . . . . . . 19 3.4.4.2. Expected Later Encoding for CBOR-to-JSON
2.5. CBOR Data Models . . . . . . . . . . . . . . . . . . . . 20 Converters . . . . . . . . . . . . . . . . . . . 21
3. Creating CBOR-Based Protocols . . . . . . . . . . . . . . . . 21 3.4.4.3. Encoded Text . . . . . . . . . . . . . . . . . . 21
3.1. CBOR in Streaming Applications . . . . . . . . . . . . . 22 3.4.5. Self-Describe CBOR . . . . . . . . . . . . . . . . . 22
3.2. Generic Encoders and Decoders . . . . . . . . . . . . . . 22 3.5. CBOR Data Models . . . . . . . . . . . . . . . . . . . . 22
3.3. Syntax Errors . . . . . . . . . . . . . . . . . . . . . . 23 4. Creating CBOR-Based Protocols . . . . . . . . . . . . . . . . 24
3.3.1. Incomplete CBOR Data Items . . . . . . . . . . . . . 23 4.1. CBOR in Streaming Applications . . . . . . . . . . . . . 25
3.3.2. Malformed Indefinite-Length Items . . . . . . . . . . 24 4.2. Generic Encoders and Decoders . . . . . . . . . . . . . . 25
3.3.3. Unknown Additional Information Values . . . . . . . . 24 4.3. Syntax Errors . . . . . . . . . . . . . . . . . . . . . . 26
3.4. Other Decoding Errors . . . . . . . . . . . . . . . . . . 24 4.3.1. Incomplete CBOR Data Items . . . . . . . . . . . . . 26
3.5. Handling Unknown Simple Values and Tags . . . . . . . . . 25 4.3.2. Malformed Indefinite-Length Items . . . . . . . . . . 27
3.6. Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.3.3. Unknown Additional Information Values . . . . . . . . 27
3.7. Specifying Keys for Maps . . . . . . . . . . . . . . . . 26 4.4. Other Decoding Errors . . . . . . . . . . . . . . . . . . 27
3.8. Undefined Values . . . . . . . . . . . . . . . . . . . . 27 4.5. Handling Unknown Simple Values and Tags . . . . . . . . . 28
3.9. Canonical CBOR . . . . . . . . . . . . . . . . . . . . . 28 4.6. Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.10. Strict Mode . . . . . . . . . . . . . . . . . . . . . . . 29 4.7. Specifying Keys for Maps . . . . . . . . . . . . . . . . 29
4. Converting Data between CBOR and JSON . . . . . . . . . . . . 30 4.7.1. Equivalence of Keys . . . . . . . . . . . . . . . . . 30
4.1. Converting from CBOR to JSON . . . . . . . . . . . . . . 31 4.8. Undefined Values . . . . . . . . . . . . . . . . . . . . 31
4.2. Converting from JSON to CBOR . . . . . . . . . . . . . . 32 4.9. Canonical CBOR . . . . . . . . . . . . . . . . . . . . . 31
5. Future Evolution of CBOR . . . . . . . . . . . . . . . . . . 33 4.9.1. Length-first map key ordering . . . . . . . . . . . . 33
5.1. Extension Points . . . . . . . . . . . . . . . . . . . . 33 4.10. Strict Mode . . . . . . . . . . . . . . . . . . . . . . . 34
5.2. Curating the Additional Information Space . . . . . . . . 34 5. Converting Data between CBOR and JSON . . . . . . . . . . . . 36
6. Diagnostic Notation . . . . . . . . . . . . . . . . . . . . . 34 5.1. Converting from CBOR to JSON . . . . . . . . . . . . . . 36
6.1. Encoding Indicators . . . . . . . . . . . . . . . . . . . 35 5.2. Converting from JSON to CBOR . . . . . . . . . . . . . . 37
7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 36 6. Future Evolution of CBOR . . . . . . . . . . . . . . . . . . 38
7.1. Simple Values Registry . . . . . . . . . . . . . . . . . 36 6.1. Extension Points . . . . . . . . . . . . . . . . . . . . 38
7.2. Tags Registry . . . . . . . . . . . . . . . . . . . . . . 36 6.2. Curating the Additional Information Space . . . . . . . . 39
7.3. Media Type ("MIME Type") . . . . . . . . . . . . . . . . 37 7. Diagnostic Notation . . . . . . . . . . . . . . . . . . . . . 40
7.4. CoAP Content-Format . . . . . . . . . . . . . . . . . . . 38 7.1. Encoding Indicators . . . . . . . . . . . . . . . . . . . 41
7.5. The +cbor Structured Syntax Suffix Registration . . . . . 38 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 41
8. Security Considerations . . . . . . . . . . . . . . . . . . . 39 8.1. Simple Values Registry . . . . . . . . . . . . . . . . . 41
9. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 40 8.2. Tags Registry . . . . . . . . . . . . . . . . . . . . . . 42
10. References . . . . . . . . . . . . . . . . . . . . . . . . . 40 8.3. Media Type ("MIME Type") . . . . . . . . . . . . . . . . 42
10.1. Normative References . . . . . . . . . . . . . . . . . . 40 8.4. CoAP Content-Format . . . . . . . . . . . . . . . . . . . 43
10.2. Informative References . . . . . . . . . . . . . . . . . 41 8.5. The +cbor Structured Syntax Suffix Registration . . . . . 43
Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 43 9. Security Considerations . . . . . . . . . . . . . . . . . . . 44
Appendix B. Jump Table . . . . . . . . . . . . . . . . . . . . . 47 10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 45
Appendix C. Pseudocode . . . . . . . . . . . . . . . . . . . . . 50 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 45
Appendix D. Half-Precision . . . . . . . . . . . . . . . . . . . 52 11.1. Normative References . . . . . . . . . . . . . . . . . . 45
11.2. Informative References . . . . . . . . . . . . . . . . . 46
Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 48
Appendix B. Jump Table . . . . . . . . . . . . . . . . . . . . . 52
Appendix C. Pseudocode . . . . . . . . . . . . . . . . . . . . . 55
Appendix D. Half-Precision . . . . . . . . . . . . . . . . . . . 57
Appendix E. Comparison of Other Binary Formats to CBOR's Design Appendix E. Comparison of Other Binary Formats to CBOR's Design
Objectives . . . . . . . . . . . . . . . . . . . . . 53 Objectives . . . . . . . . . . . . . . . . . . . . . 58
E.1. ASN.1 DER, BER, and PER . . . . . . . . . . . . . . . . . 54 E.1. ASN.1 DER, BER, and PER . . . . . . . . . . . . . . . . . 59
E.2. MessagePack . . . . . . . . . . . . . . . . . . . . . . . 54 E.2. MessagePack . . . . . . . . . . . . . . . . . . . . . . . 59
E.3. BSON . . . . . . . . . . . . . . . . . . . . . . . . . . 55 E.3. BSON . . . . . . . . . . . . . . . . . . . . . . . . . . 60
E.4. UBJSON . . . . . . . . . . . . . . . . . . . . . . . . . 55 E.4. UBJSON . . . . . . . . . . . . . . . . . . . . . . . . . 60
E.5. MSDTP: RFC 713 . . . . . . . . . . . . . . . . . . . . . 55 E.5. MSDTP: RFC 713 . . . . . . . . . . . . . . . . . . . . . 60
E.6. Conciseness on the Wire . . . . . . . . . . . . . . . . . 55 E.6. Conciseness on the Wire . . . . . . . . . . . . . . . . . 60
Appendix F. Changes from RFC 7049 . . . . . . . . . . . . . . . 56 Appendix F. Changes from RFC 7049 . . . . . . . . . . . . . . . 61
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 56 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 61
1. Introduction 1. Introduction
There are hundreds of standardized formats for binary representation There are hundreds of standardized formats for binary representation
of structured data (also known as binary serialization formats). Of of structured data (also known as binary serialization formats). Of
those, some are for specific domains of information, while others are those, some are for specific domains of information, while others are
generalized for arbitrary data. In the IETF, probably the best-known generalized for arbitrary data. In the IETF, probably the best-known
formats in the latter category are ASN.1's BER and DER [ASN.1]. formats in the latter category are ASN.1's BER and DER [ASN.1].
The format defined here follows some specific design goals that are The format defined here follows some specific design goals that are
skipping to change at page 6, line 47 skipping to change at page 7, line 5
Where bit arithmetic or data types are explained, this document uses Where bit arithmetic or data types are explained, this document uses
the notation familiar from the programming language C, except that the notation familiar from the programming language C, except that
"**" denotes exponentiation. Similar to the "0x" notation for "**" denotes exponentiation. Similar to the "0x" notation for
hexadecimal numbers, numbers in binary notation are prefixed with hexadecimal numbers, numbers in binary notation are prefixed with
"0b". Underscores can be added to such a number solely for "0b". Underscores can be added to such a number solely for
readability, so 0b00100001 (0x21) might be written 0b001_00001 to readability, so 0b00100001 (0x21) might be written 0b001_00001 to
emphasize the desired interpretation of the bits in the byte; in this emphasize the desired interpretation of the bits in the byte; in this
case, it is split into three bits and five bits. case, it is split into three bits and five bits.
2. Specification of the CBOR Encoding 2. CBOR Data Models
A CBOR-encoded data item is structured and encoded as described in CBOR is explicit about its generic data model, which defines the set
this section. The encoding is summarized in Table 5. of all data items that can be represented in CBOR. Its basic generic
data model is extensible by the registration of simple type values
and tags. Applications can then subset the resulting extended
generic data model to build their specific data models.
Within environments that can represent the data items in the generic
data model, generic CBOR encoders and decoders can be implemented
(which usually involves defining additional implementation data types
for those data items that do not already have a natural
representation in the environment). The ability to provide generic
encoders and decoders is an explicit design goal of CBOR; however
many applications will provide their own application-specific
encoders and/or decoders.
In the basic (un-extended) generic data model, a data item is one of:
o an integer in the range -2**64..2**64-1 inclusive
o a simple value, identified by a number between 0 and 255, but
distinct from that number
o a floating point value, distinct from an integer, out of the set
representable by IEEE 754 binary64 (including non-finites)
o a sequence of zero or more bytes ("byte string")
o a sequence of zero or more Unicode code points ("text string")
o a sequence of zero or more data items ("array")
o a mapping (mathematical function) from zero or more data items
("keys") each to a data item ("values"), ("map")
o a tagged data item, comprising a tag (an integer in the range
0..2**64-1) and a value (a data item)
Note that integer and floating-point values are distinct in this
model, even if they have the same numeric value.
2.1. Extended Generic Data Models
This basic generic data model comes pre-extended by the registration
of a number of simple values and tags right in this document, such
as:
o "false", "true", "null", and "undefined" (simple values identified
by 20..23)
o integer and floating point values with a larger range and
precision than the above (tags 2 to 5)
o application data types such as a point in time (tags 1, 0)
Further elements of the extended generic data model can be (and have
been) defined via the IANA registries created for CBOR. Even if such
an extension is unknown to a generic encoder or decoder, data items
using that extension can be passed to or from the application by
representing them at the interface to the application within the
basic generic data model, i.e., as generic values of a simple type or
generic tagged items.
In other words, the basic generic data model is stable as defined in
this document, while the extended generic data model expands by the
registration of new simple values or tags, but never shrinks.
While there is a strong expectation that generic encoders and
decoders can represent "false", "true", and "null" in the form
appropriate for their programming environment, implementation of the
data model extensions created by tags is truly optional and a matter
of implementation quality.
2.2. Specific Data Models
The specific data model for a CBOR-based protocol usually subsets the
extended generic data model and assigns application semantics to the
data items within this subset and its components. When documenting
such specific data models, where it is desired to specify the types
of data items, it is preferred to identify the types by their names
in the generic data model ("negative integer", "array") instead of by
referring to aspects of their CBOR representation ("major type 1",
"major type 4").
Specific data models can also specify that values of different types
are equivalent for the purposes of map keys and encoder freedom. For
example, in the generic data model, a valid map MAY have both "0" and
"0.0" as keys, and an encoder MUST NOT encode "0.0" as an integer
(major type 0, Section 3.1). However, if a specific data model
declares that floating point and integer representations of integral
values are equivalent, map keys "0" and "0.0" would be considered
duplicates and so invalid, and an encoder could encode integral-
valued floats as integers or vice versa, perhaps to save encoded
bytes.
3. Specification of the CBOR Encoding
A CBOR data item (Section 2) is encoded to or decoded from a byte
string as described in this section. The encoding is summarized in
Table 5.
The initial byte of each data item contains both information about The initial byte of each data item contains both information about
the major type (the high-order 3 bits, described in Section 2.1) and the major type (the high-order 3 bits, described in Section 3.1) and
additional information (the low-order 5 bits). When the value of the additional information (the low-order 5 bits). When the value of the
additional information is less than 24, it is directly used as a additional information is less than 24, it is directly used as a
small unsigned integer. When it is 24 to 27, the additional bytes small unsigned integer. When it is 24 to 27, the additional bytes
for a variable-length integer immediately follow; the values 24 to 27 for a variable-length integer immediately follow; the values 24 to 27
of the additional information specify that its length is a 1-, 2-, of the additional information specify that its length is a 1-, 2-,
4-, or 8-byte unsigned integer, respectively. Additional information 4-, or 8-byte unsigned integer, respectively. Additional information
value 31 is used for indefinite-length items, described in value 31 is used for indefinite-length items, described in
Section 2.2. Additional information values 28 to 30 are reserved for Section 3.2. Additional information values 28 to 30 are reserved for
future expansion. future expansion.
In all additional information values, the resulting integer is In all additional information values, the resulting integer is
interpreted depending on the major type. It may represent the actual interpreted depending on the major type. It may represent the actual
data: for example, in integer types, the resulting integer is used data: for example, in integer types, the resulting integer is used
for the value itself. It may instead supply length information: for for the value itself. It may instead supply length information: for
example, in byte strings it gives the length of the byte string data example, in byte strings it gives the length of the byte string data
that follows. that follows.
A CBOR decoder implementation can be based on a jump table with all A CBOR decoder implementation can be based on a jump table with all
256 defined values for the initial byte (Table 5). A decoder in a 256 defined values for the initial byte (Table 5). A decoder in a
constrained implementation can instead use the structure of the constrained implementation can instead use the structure of the
initial byte and following bytes for more compact code (see initial byte and following bytes for more compact code (see
Appendix C for a rough impression of how this could look). Appendix C for a rough impression of how this could look).
2.1. Major Types 3.1. Major Types
The following lists the major types and the additional information The following lists the major types and the additional information
and other bytes associated with the type. and other bytes associated with the type.
Major type 0: an unsigned integer. The 5-bit additional information Major type 0: an unsigned integer. The 5-bit additional information
is either the integer itself (for additional information values 0 is either the integer itself (for additional information values 0
through 23) or the length of additional data. Additional through 23) or the length of additional data. Additional
information 24 means the value is represented in an additional information 24 means the value is represented in an additional
uint8_t, 25 means a uint16_t, 26 means a uint32_t, and 27 means a uint8_t, 25 means a uint16_t, 26 means a uint32_t, and 27 means a
uint64_t. For example, the integer 10 is denoted as the one byte uint64_t. For example, the integer 10 is denoted as the one byte
skipping to change at page 8, line 52 skipping to change at page 11, line 10
that is immediately followed by a value. The map's length follows that is immediately followed by a value. The map's length follows
the rules for byte strings (major type 2), except that the length the rules for byte strings (major type 2), except that the length
denotes the number of pairs, not the length in bytes that the map denotes the number of pairs, not the length in bytes that the map
takes up. For example, a map that contains 9 pairs would have an takes up. For example, a map that contains 9 pairs would have an
initial byte of 0b101_01001 (major type of 5, additional initial byte of 0b101_01001 (major type of 5, additional
information of 9 for the number of pairs) followed by the 18 information of 9 for the number of pairs) followed by the 18
remaining items. The first item is the first key, the second item remaining items. The first item is the first key, the second item
is the first value, the third item is the second key, and so on. is the first value, the third item is the second key, and so on.
A map that has duplicate keys may be well-formed, but it is not A map that has duplicate keys may be well-formed, but it is not
valid, and thus it causes indeterminate decoding; see also valid, and thus it causes indeterminate decoding; see also
Section 3.7. Section 4.7.
Major type 6: optional semantic tagging of other major types. See Major type 6: optional semantic tagging of other major types. See
Section 2.4. Section 3.4.
Major type 7: floating-point numbers and simple data types that need Major type 7: floating-point numbers and simple data types that need
no content, as well as the "break" stop code. See Section 2.3. no content, as well as the "break" stop code. See Section 3.3.
These eight major types lead to a simple table showing which of the These eight major types lead to a simple table showing which of the
256 possible values for the initial byte of a data item are used 256 possible values for the initial byte of a data item are used
(Table 5). (Table 5).
In major types 6 and 7, many of the possible values are reserved for In major types 6 and 7, many of the possible values are reserved for
future specification. See Section 7 for more information on these future specification. See Section 8 for more information on these
values. values.
2.2. Indefinite Lengths for Some Major Types 3.2. Indefinite Lengths for Some Major Types
Four CBOR items (arrays, maps, byte strings, and text strings) can be Four CBOR items (arrays, maps, byte strings, and text strings) can be
encoded with an indefinite length using additional information value encoded with an indefinite length using additional information value
31. This is useful if the encoding of the item needs to begin before 31. This is useful if the encoding of the item needs to begin before
the number of items inside the array or map, or the total length of the number of items inside the array or map, or the total length of
the string, is known. (The application of this is often referred to the string, is known. (The application of this is often referred to
as "streaming" within a data item.) as "streaming" within a data item.)
Indefinite-length arrays and maps are dealt with differently than Indefinite-length arrays and maps are dealt with differently than
indefinite-length byte strings and text strings. indefinite-length byte strings and text strings.
2.2.1. Indefinite-Length Arrays and Maps 3.2.1. Indefinite-Length Arrays and Maps
Indefinite-length arrays and maps are simply opened without Indefinite-length arrays and maps are simply opened without
indicating the number of data items that will be included in the indicating the number of data items that will be included in the
array or map, using the additional information value of 31. The array or map, using the additional information value of 31. The
initial major type and additional information byte is followed by the initial major type and additional information byte is followed by the
elements of the array or map, just as they would be in other arrays elements of the array or map, just as they would be in other arrays
or maps. The end of the array or map is indicated by encoding a or maps. The end of the array or map is indicated by encoding a
"break" stop code in a place where the next data item would normally "break" stop code in a place where the next data item would normally
have been included. The "break" is encoded with major type 7 and have been included. The "break" is encoded with major type 7 and
additional information value 31 (0b111_11111) but is not itself a additional information value 31 (0b111_11111) but is not itself a
skipping to change at page 11, line 40 skipping to change at page 14, line 5
0xbf6346756ef563416d7421ff 0xbf6346756ef563416d7421ff
BF -- Start indefinite-length map BF -- Start indefinite-length map
63 -- First key, UTF-8 string length 3 63 -- First key, UTF-8 string length 3
46756e -- "Fun" 46756e -- "Fun"
F5 -- First value, true F5 -- First value, true
63 -- Second key, UTF-8 string length 3 63 -- Second key, UTF-8 string length 3
416d74 -- "Amt" 416d74 -- "Amt"
21 -- Second value, -2 21 -- Second value, -2
FF -- "break" FF -- "break"
2.2.2. Indefinite-Length Byte Strings and Text Strings 3.2.2. Indefinite-Length Byte Strings and Text Strings
Indefinite-length byte strings and text strings are actually a Indefinite-length byte strings and text strings are actually a
concatenation of zero or more definite-length byte or text strings concatenation of zero or more definite-length byte or text strings
("chunks") that are together treated as one contiguous string. ("chunks") that are together treated as one contiguous string.
Indefinite-length strings are opened with the major type and Indefinite-length strings are opened with the major type and
additional information value of 31, but what follows are a series of additional information value of 31, but what follows are a series of
byte or text strings that have definite lengths (the chunks). The byte or text strings that have definite lengths (the chunks). The
end of the series of chunks is indicated by encoding the "break" stop end of the series of chunks is indicated by encoding the "break" stop
code (0b111_11111) in a place where the next chunk in the series code (0b111_11111) in a place where the next chunk in the series
would occur. The contents of the chunks are concatenated together, would occur. The contents of the chunks are concatenated together,
skipping to change at page 12, line 34 skipping to change at page 14, line 48
After decoding, this results in a single byte string with seven After decoding, this results in a single byte string with seven
bytes: 0xaabbccddeeff99. bytes: 0xaabbccddeeff99.
Text strings with indefinite lengths act the same as byte strings Text strings with indefinite lengths act the same as byte strings
with indefinite lengths, except that all their chunks MUST be with indefinite lengths, except that all their chunks MUST be
definite-length text strings. Note that this implies that the bytes definite-length text strings. Note that this implies that the bytes
of a single UTF-8 character cannot be spread between chunks: a new of a single UTF-8 character cannot be spread between chunks: a new
chunk can only be started at a character boundary. chunk can only be started at a character boundary.
2.3. Floating-Point Numbers and Values with No Content 3.3. Floating-Point Numbers and Values with No Content
Major type 7 is for two types of data: floating-point numbers and Major type 7 is for two types of data: floating-point numbers and
"simple values" that do not need any content. Each value of the "simple values" that do not need any content. Each value of the
5-bit additional information in the initial byte has its own separate 5-bit additional information in the initial byte has its own separate
meaning, as defined in Table 1. Like the major types for integers, meaning, as defined in Table 1. Like the major types for integers,
items of this major type do not carry content data; all the items of this major type do not carry content data; all the
information is in the initial bytes. information is in the initial bytes.
+-------------+--------------------------------------------------+ +-------------+--------------------------------------------------+
| 5-Bit Value | Semantics | | 5-Bit Value | Semantics |
skipping to change at page 14, line 17 skipping to change at page 16, line 37
are encoded in the additional bytes of the appropriate size. (See are encoded in the additional bytes of the appropriate size. (See
Appendix D for some information about 16-bit floating point.) Appendix D for some information about 16-bit floating point.)
An encoder MUST NOT encode False as the two-byte sequence of 0xf814, An encoder MUST NOT encode False as the two-byte sequence of 0xf814,
MUST NOT encode True as the two-byte sequence of 0xf815, MUST NOT MUST NOT encode True as the two-byte sequence of 0xf815, MUST NOT
encode Null as the two-byte sequence of 0xf816, and MUST NOT encode encode Null as the two-byte sequence of 0xf816, and MUST NOT encode
Undefined value as the two-byte sequence of 0xf817. A decoder MUST Undefined value as the two-byte sequence of 0xf817. A decoder MUST
treat these two-byte sequences as an error. Similar prohibitions treat these two-byte sequences as an error. Similar prohibitions
apply to the unassigned simple values as well. apply to the unassigned simple values as well.
2.4. Optional Tagging of Items 3.4. Optional Tagging of Items
In CBOR, a data item can optionally be preceded by a tag to give it In CBOR, a data item can optionally be preceded by a tag to give it
additional semantics while retaining its structure. The tag is major additional semantics while retaining its structure. The tag is major
type 6, and represents an integer number as indicated by the tag's type 6, and represents an integer number as indicated by the tag's
integer value; the (sole) data item is carried as content data. If a integer value; the (sole) data item is carried as content data. If a
tag requires structured data, this structure is encoded into the tag requires structured data, this structure is encoded into the
nested data item. The definition of a tag usually restricts what nested data item. The definition of a tag usually restricts what
kinds of nested data item or items can be carried by a tag. kinds of nested data item or items can be carried by a tag.
The initial bytes of the tag follow the rules for positive integers The initial bytes of the tag follow the rules for positive integers
(major type 0). The tag is followed by a single data item of any (major type 0). The tag is followed by a single data item of any
type. For example, assume that a byte string of length 12 is marked type. For example, assume that a byte string of length 12 is marked
with a tag to indicate it is a positive bignum (Section 2.4.2). This with a tag to indicate it is a positive bignum (Section 3.4.2). This
would be marked as 0b110_00010 (major type 6, additional information would be marked as 0b110_00010 (major type 6, additional information
2 for the tag) followed by 0b010_01100 (major type 2, additional 2 for the tag) followed by 0b010_01100 (major type 2, additional
information of 12 for the length) followed by the 12 bytes of the information of 12 for the length) followed by the 12 bytes of the
bignum. bignum.
Decoders do not need to understand tags, and thus tags may be of Decoders do not need to understand tags, and thus tags may be of
little value in applications where the implementation creating a little value in applications where the implementation creating a
particular CBOR data item and the implementation decoding that stream particular CBOR data item and the implementation decoding that stream
know the semantic meaning of each item in the data flow. Their know the semantic meaning of each item in the data flow. Their
primary purpose in this specification is to define common data types primary purpose in this specification is to define common data types
skipping to change at page 15, line 5 skipping to change at page 17, line 25
tags is optional for a decoder; it can just jump over the initial tags is optional for a decoder; it can just jump over the initial
bytes of the tag and interpret the tagged data item itself. bytes of the tag and interpret the tagged data item itself.
A tag always applies to the item that is directly followed by it. A tag always applies to the item that is directly followed by it.
Thus, if tag A is followed by tag B, which is followed by data item Thus, if tag A is followed by tag B, which is followed by data item
C, tag A applies to the result of applying tag B on data item C. C, tag A applies to the result of applying tag B on data item C.
That is, a tagged item is a data item consisting of a tag and a That is, a tagged item is a data item consisting of a tag and a
value. The content of the tagged item is the data item (the value) value. The content of the tagged item is the data item (the value)
that is being tagged. that is being tagged.
IANA maintains a registry of tag values as described in Section 7.2. IANA maintains a registry of tag values as described in Section 8.2.
Table 3 provides a list of initial values, with definitions in the Table 3 provides a list of initial values, with definitions in the
rest of this section. rest of this section.
+-----------+--------------+----------------------------------------+ +-----------+--------------+----------------------------------------+
| Tag | Data Item | Semantics | | Tag | Data Item | Semantics |
+-----------+--------------+----------------------------------------+ +-----------+--------------+----------------------------------------+
| 0 | UTF-8 string | Standard date/time string; see | | 0 | UTF-8 string | Standard date/time string; see |
| | | Section 2.4.1 | | | | Section 3.4.1 |
| | | | | | | |
| 1 | multiple | Epoch-based date/time; see | | 1 | multiple | Epoch-based date/time; see |
| | | Section 2.4.1 | | | | Section 3.4.1 |
| | | | | | | |
| 2 | byte string | Positive bignum; see Section 2.4.2 | | 2 | byte string | Positive bignum; see Section 3.4.2 |
| | | | | | | |
| 3 | byte string | Negative bignum; see Section 2.4.2 | | 3 | byte string | Negative bignum; see Section 3.4.2 |
| | | | | | | |
| 4 | array | Decimal fraction; see Section 2.4.3 | | 4 | array | Decimal fraction; see Section 3.4.3 |
| | | | | | | |
| 5 | array | Bigfloat; see Section 2.4.3 | | 5 | array | Bigfloat; see Section 3.4.3 |
| | | | | | | |
| 6..20 | (Unassigned) | (Unassigned) | | 6..20 | (Unassigned) | (Unassigned) |
| | | | | | | |
| 21 | multiple | Expected conversion to base64url | | 21 | multiple | Expected conversion to base64url |
| | | encoding; see Section 2.4.4.2 | | | | encoding; see Section 3.4.4.2 |
| | | | | | | |
| 22 | multiple | Expected conversion to base64 | | 22 | multiple | Expected conversion to base64 |
| | | encoding; see Section 2.4.4.2 | | | | encoding; see Section 3.4.4.2 |
| | | | | | | |
| 23 | multiple | Expected conversion to base16 | | 23 | multiple | Expected conversion to base16 |
| | | encoding; see Section 2.4.4.2 | | | | encoding; see Section 3.4.4.2 |
| | | | | | | |
| 24 | byte string | Encoded CBOR data item; see | | 24 | byte string | Encoded CBOR data item; see |
| | | Section 2.4.4.1 | | | | Section 3.4.4.1 |
| | | | | | | |
| 25..31 | (Unassigned) | (Unassigned) | | 25..31 | (Unassigned) | (Unassigned) |
| | | | | | | |
| 32 | UTF-8 string | URI; see Section 2.4.4.3 | | 32 | UTF-8 string | URI; see Section 3.4.4.3 |
| | | | | | | |
| 33 | UTF-8 string | base64url; see Section 2.4.4.3 | | 33 | UTF-8 string | base64url; see Section 3.4.4.3 |
| | | | | | | |
| 34 | UTF-8 string | base64; see Section 2.4.4.3 | | 34 | UTF-8 string | base64; see Section 3.4.4.3 |
| | | | | | | |
| 35 | UTF-8 string | Regular expression; see | | 35 | UTF-8 string | Regular expression; see |
| | | Section 2.4.4.3 | | | | Section 3.4.4.3 |
| | | | | | | |
| 36 | UTF-8 string | MIME message; see Section 2.4.4.3 | | 36 | UTF-8 string | MIME message; see Section 3.4.4.3 |
| | | | | | | |
| 37..55798 | (Unassigned) | (Unassigned) | | 37..55798 | (Unassigned) | (Unassigned) |
| | | | | | | |
| 55799 | multiple | Self-describe CBOR; see Section 2.4.5 | | 55799 | multiple | Self-describe CBOR; see Section 3.4.5 |
| | | | | | | |
| 55800+ | (Unassigned) | (Unassigned) | | 55800+ | (Unassigned) | (Unassigned) |
+-----------+--------------+----------------------------------------+ +-----------+--------------+----------------------------------------+
Table 3: Values for Tags Table 3: Values for Tags
2.4.1. Date and Time 3.4.1. Date and Time
Protocols using tag values 0 and 1 extend the generic data model
(Section 2) with data items representing points in time.
Tag value 0 is for date/time strings that follow the standard format Tag value 0 is for date/time strings that follow the standard format
described in [RFC3339], as refined by Section 3.3 of [RFC4287]. described in [RFC3339], as refined by Section 3.3 of [RFC4287].
Tag value 1 is for numerical representation of seconds relative to Tag value 1 is for numerical representation of seconds relative to
1970-01-01T00:00Z in UTC time. (For the non-negative values that the 1970-01-01T00:00Z in UTC time. (For the non-negative values that the
Portable Operating System Interface (POSIX) defines, the number of Portable Operating System Interface (POSIX) defines, the number of
seconds is counted in the same way as for POSIX "seconds since the seconds is counted in the same way as for POSIX "seconds since the
epoch" [TIME_T].) The tagged item can be a positive or negative epoch" [TIME_T].) The tagged item can be a positive or negative
integer (major types 0 and 1), or a floating-point number (major type integer (major types 0 and 1), or a floating-point number (major type
7 with additional information 25, 26, or 27). Note that the number 7 with additional information 25, 26, or 27). Note that the number
can be negative (time before 1970-01-01T00:00Z) and, if a floating- can be negative (time before 1970-01-01T00:00Z) and, if a floating-
point number, indicate fractional seconds. point number, indicate fractional seconds.
2.4.2. Bignums 3.4.2. Bignums
Bignums are integers that do not fit into the basic integer Protocols using tag values 2 and 3 extend the generic data model
representations provided by major types 0 and 1. They are encoded as (Section 2) with "bignums" representing arbitrary integers. In the
a byte string data item, which is interpreted as an unsigned integer generic data model, bignum values are not equal to integers from the
n in network byte order. For tag value 2, the value of the bignum is basic data model, but specific data models can define that
n. For tag value 3, the value of the bignum is -1 - n. Decoders equivalence.
that understand these tags MUST be able to decode bignums that have
leading zeroes. Bignums are encoded as a byte string data item, which is interpreted
as an unsigned integer n in network byte order. For tag value 2, the
value of the bignum is n. For tag value 3, the value of the bignum
is -1 - n. Decoders that understand these tags MUST be able to
decode bignums that have leading zeroes.
For example, the number 18446744073709551616 (2**64) is represented For example, the number 18446744073709551616 (2**64) is represented
as 0b110_00010 (major type 6, tag 2), followed by 0b010_01001 (major as 0b110_00010 (major type 6, tag 2), followed by 0b010_01001 (major
type 2, length 9), followed by 0x010000000000000000 (one byte 0x01 type 2, length 9), followed by 0x010000000000000000 (one byte 0x01
and eight bytes 0x00). In hexadecimal: and eight bytes 0x00). In hexadecimal:
C2 -- Tag 2 C2 -- Tag 2
49 -- Byte string of length 9 49 -- Byte string of length 9
010000000000000000 -- Bytes content 010000000000000000 -- Bytes content
2.4.3. Decimal Fractions and Bigfloats 3.4.3. Decimal Fractions and Bigfloats
Protocols using tag value 4 extend the generic data model with data
items representing arbitrary-length decimal fractions m*(10*e).
Protocols using tag value 5 extend the generic data model with data
items representing arbitrary-length binary fractions m*(2*e). As
with bignums, values of different types are not equal in the generic
data model.
Decimal fractions combine an integer mantissa with a base-10 scaling Decimal fractions combine an integer mantissa with a base-10 scaling
factor. They are most useful if an application needs the exact factor. They are most useful if an application needs the exact
representation of a decimal fraction such as 1.1 because there is no representation of a decimal fraction such as 1.1 because there is no
exact representation for many decimal fractions in binary floating exact representation for many decimal fractions in binary floating
point. point.
Bigfloats combine an integer mantissa with a base-2 scaling factor. Bigfloats combine an integer mantissa with a base-2 scaling factor.
They are binary floating-point values that can exceed the range or They are binary floating-point values that can exceed the range or
the precision of the three IEEE 754 formats supported by CBOR the precision of the three IEEE 754 formats supported by CBOR
(Section 2.3). Bigfloats may also be used by constrained (Section 3.3). Bigfloats may also be used by constrained
applications that need some basic binary floating-point capability applications that need some basic binary floating-point capability
without the need for supporting IEEE 754. without the need for supporting IEEE 754.
A decimal fraction or a bigfloat is represented as a tagged array A decimal fraction or a bigfloat is represented as a tagged array
that contains exactly two integer numbers: an exponent e and a that contains exactly two integer numbers: an exponent e and a
mantissa m. Decimal fractions (tag 4) use base-10 exponents; the mantissa m. Decimal fractions (tag 4) use base-10 exponents; the
value of a decimal fraction data item is m*(10**e). Bigfloats (tag value of a decimal fraction data item is m*(10**e). Bigfloats (tag
5) use base-2 exponents; the value of a bigfloat data item is 5) use base-2 exponents; the value of a bigfloat data item is
m*(2**e). The exponent e MUST be represented in an integer of major m*(2**e). The exponent e MUST be represented in an integer of major
type 0 or 1, while the mantissa also can be a bignum (Section 2.4.2). type 0 or 1, while the mantissa also can be a bignum (Section 3.4.2).
An example of a decimal fraction is that the number 273.15 could be An example of a decimal fraction is that the number 273.15 could be
represented as 0b110_00100 (major type of 6 for the tag, additional represented as 0b110_00100 (major type of 6 for the tag, additional
information of 4 for the type of tag), followed by 0b100_00010 (major information of 4 for the type of tag), followed by 0b100_00010 (major
type of 4 for the array, additional information of 2 for the length type of 4 for the array, additional information of 2 for the length
of the array), followed by 0b001_00001 (major type of 1 for the first of the array), followed by 0b001_00001 (major type of 1 for the first
integer, additional information of 1 for the value of -2), followed integer, additional information of 1 for the value of -2), followed
by 0b000_11001 (major type of 0 for the second integer, additional by 0b000_11001 (major type of 0 for the second integer, additional
information of 25 for a two-byte value), followed by information of 25 for a two-byte value), followed by
0b0110101010110011 (27315 in two bytes). In hexadecimal: 0b0110101010110011 (27315 in two bytes). In hexadecimal:
skipping to change at page 18, line 8 skipping to change at page 20, line 41
information of 3 for the value of 3). In hexadecimal: information of 3 for the value of 3). In hexadecimal:
C5 -- Tag 5 C5 -- Tag 5
82 -- Array of length 2 82 -- Array of length 2
20 -- -1 20 -- -1
03 -- 3 03 -- 3
Decimal fractions and bigfloats provide no representation of Decimal fractions and bigfloats provide no representation of
Infinity, -Infinity, or NaN; if these are needed in place of a Infinity, -Infinity, or NaN; if these are needed in place of a
decimal fraction or bigfloat, the IEEE 754 half-precision decimal fraction or bigfloat, the IEEE 754 half-precision
representations from Section 2.3 can be used. For constrained representations from Section 3.3 can be used. For constrained
applications, where there is a choice between representing a specific applications, where there is a choice between representing a specific
number as an integer and as a decimal fraction or bigfloat (such as number as an integer and as a decimal fraction or bigfloat (such as
when the exponent is small and non-negative), there is a quality-of- when the exponent is small and non-negative), there is a quality-of-
implementation expectation that the integer representation is used implementation expectation that the integer representation is used
directly. directly.
2.4.4. Content Hints 3.4.4. Content Hints
The tags in this section are for content hints that might be used by The tags in this section are for content hints that might be used by
generic CBOR processors. generic CBOR processors. These content hints do not extend the
generic data model.
2.4.4.1. Encoded CBOR Data Item 3.4.4.1. Encoded CBOR Data Item
Sometimes it is beneficial to carry an embedded CBOR data item that Sometimes it is beneficial to carry an embedded CBOR data item that
is not meant to be decoded immediately at the time the enclosing data is not meant to be decoded immediately at the time the enclosing data
item is being parsed. Tag 24 (CBOR data item) can be used to tag the item is being parsed. Tag 24 (CBOR data item) can be used to tag the
embedded byte string as a data item encoded in CBOR format. embedded byte string as a data item encoded in CBOR format.
2.4.4.2. Expected Later Encoding for CBOR-to-JSON Converters 3.4.4.2. Expected Later Encoding for CBOR-to-JSON Converters
Tags 21 to 23 indicate that a byte string might require a specific Tags 21 to 23 indicate that a byte string might require a specific
encoding when interoperating with a text-based representation. These encoding when interoperating with a text-based representation. These
tags are useful when an encoder knows that the byte string data it is tags are useful when an encoder knows that the byte string data it is
writing is likely to be later converted to a particular JSON-based writing is likely to be later converted to a particular JSON-based
usage. That usage specifies that some strings are encoded as base64, usage. That usage specifies that some strings are encoded as base64,
base64url, and so on. The encoder uses byte strings instead of doing base64url, and so on. The encoder uses byte strings instead of doing
the encoding itself to reduce the message size, to reduce the code the encoding itself to reduce the message size, to reduce the code
size of the encoder, or both. The encoder does not know whether or size of the encoder, or both. The encoder does not know whether or
not the converter will be generic, and therefore wants to say what it not the converter will be generic, and therefore wants to say what it
skipping to change at page 19, line 5 skipping to change at page 21, line 43
contained in the data item, except for those contained in a nested contained in the data item, except for those contained in a nested
data item tagged with an expected conversion. data item tagged with an expected conversion.
These three tag types suggest conversions to three of the base data These three tag types suggest conversions to three of the base data
encodings defined in [RFC4648]. For base64url encoding, padding is encodings defined in [RFC4648]. For base64url encoding, padding is
not used (see Section 3.2 of RFC 4648); that is, all trailing equals not used (see Section 3.2 of RFC 4648); that is, all trailing equals
signs ("=") are removed from the base64url-encoded string. Later signs ("=") are removed from the base64url-encoded string. Later
tags might be defined for other data encodings of RFC 4648 or for tags might be defined for other data encodings of RFC 4648 or for
other ways to encode binary data in strings. other ways to encode binary data in strings.
2.4.4.3. Encoded Text 3.4.4.3. Encoded Text
Some text strings hold data that have formats widely used on the Some text strings hold data that have formats widely used on the
Internet, and sometimes those formats can be validated and presented Internet, and sometimes those formats can be validated and presented
to the application in appropriate form by the decoder. There are to the application in appropriate form by the decoder. There are
tags for some of these formats. tags for some of these formats.
o Tag 32 is for URIs, as defined in [RFC3986]; o Tag 32 is for URIs, as defined in [RFC3986];
o Tags 33 and 34 are for base64url- and base64-encoded text strings, o Tags 33 and 34 are for base64url- and base64-encoded text strings,
as defined in [RFC4648]; as defined in [RFC4648];
o Tag 35 is for regular expressions in Perl Compatible Regular o Tag 35 is for regular expressions in Perl Compatible Regular
Expressions (PCRE) / JavaScript syntax [ECMA262]. Expressions (PCRE) / JavaScript syntax [ECMA262].
o Tag 36 is for MIME messages (including all headers), as defined in o Tag 36 is for MIME messages (including all headers), as defined in
[RFC2045]; [RFC2045];
Note that tags 33 and 34 differ from 21 and 22 in that the data is Note that tags 33 and 34 differ from 21 and 22 in that the data is
skipping to change at page 19, line 27 skipping to change at page 22, line 17
o Tag 35 is for regular expressions in Perl Compatible Regular o Tag 35 is for regular expressions in Perl Compatible Regular
Expressions (PCRE) / JavaScript syntax [ECMA262]. Expressions (PCRE) / JavaScript syntax [ECMA262].
o Tag 36 is for MIME messages (including all headers), as defined in o Tag 36 is for MIME messages (including all headers), as defined in
[RFC2045]; [RFC2045];
Note that tags 33 and 34 differ from 21 and 22 in that the data is Note that tags 33 and 34 differ from 21 and 22 in that the data is
transported in base-encoded form for the former and in raw byte transported in base-encoded form for the former and in raw byte
string form for the latter. string form for the latter.
2.4.5. Self-Describe CBOR 3.4.5. Self-Describe CBOR
In many applications, it will be clear from the context that CBOR is In many applications, it will be clear from the context that CBOR is
being employed for encoding a data item. For instance, a specific being employed for encoding a data item. For instance, a specific
protocol might specify the use of CBOR, or a media type is indicated protocol might specify the use of CBOR, or a media type is indicated
that specifies its use. However, there may be applications where that specifies its use. However, there may be applications where
such context information is not available, such as when CBOR data is such context information is not available, such as when CBOR data is
stored in a file and disambiguating metadata is not in use. Here, it stored in a file and disambiguating metadata is not in use. Here, it
may help to have some distinguishing characteristics for the data may help to have some distinguishing characteristics for the data
itself. itself.
skipping to change at page 20, line 5 skipping to change at page 22, line 44
use as a distinguishing mark for frequently used file types. In use as a distinguishing mark for frequently used file types. In
particular, it is not a valid start of a Unicode text in any Unicode particular, it is not a valid start of a Unicode text in any Unicode
encoding if followed by a valid CBOR data item. encoding if followed by a valid CBOR data item.
For instance, a decoder might be able to parse both CBOR and JSON. For instance, a decoder might be able to parse both CBOR and JSON.
Such a decoder would need to mechanically distinguish the two Such a decoder would need to mechanically distinguish the two
formats. An easy way for an encoder to help the decoder would be to formats. An easy way for an encoder to help the decoder would be to
tag the entire CBOR item with tag 55799, the serialization of which tag the entire CBOR item with tag 55799, the serialization of which
will never be found at the beginning of a JSON text. will never be found at the beginning of a JSON text.
2.5. CBOR Data Models 3.5. CBOR Data Models
CBOR is explicit about its generic data model, which defines the set CBOR is explicit about its generic data model, which defines the set
of all data items that can be represented in CBOR. Its basic generic of all data items that can be represented in CBOR. Its basic generic
data model is extensible by the registration of simple type values data model is extensible by the registration of simple type values
and tags. Applications can then subset the resulting extended and tags. Applications can then subset the resulting extended
generic data model to build their specific data models. generic data model to build their specific data models.
Within environments that can represent the data items in the generic Within environments that can represent the data items in the generic
data model, generic CBOR encoders and decoders can be implemented data model, generic CBOR encoders and decoders can be implemented
(which usually involves defining additional implementation data types (which usually involves defining additional implementation data types
skipping to change at page 21, line 24 skipping to change at page 24, line 18
using that extension can be passed to or from the application by using that extension can be passed to or from the application by
representing them at the interface to the application within the representing them at the interface to the application within the
basic generic data model, i.e., as generic values of a simple type or basic generic data model, i.e., as generic values of a simple type or
generic tagged items. generic tagged items.
In other words, the basic generic data model is stable as defined in In other words, the basic generic data model is stable as defined in
this document, while the extended generic data model expands by the this document, while the extended generic data model expands by the
registration of new simple values or tags, but never shrinks. registration of new simple values or tags, but never shrinks.
While there is a strong expectation that generic encoders and While there is a strong expectation that generic encoders and
decoders can represent "false", "true", and "null" in the form decoders can represent "false", "true", and "null" ("undefined" is
appropriate for their programming environment, implementation of the intentionally omitted) in the form appropriate for their programming
data model extensions created by tags is truly optional and a matter environment, implementation of the data model extensions created by
of implementation quality. tags is truly optional and a matter of implementation quality.
A specific data model usually subsets the extended generic data model A specific data model usually subsets the extended generic data model
and assigns application semantics to the data items within this and assigns application semantics to the data items within this
subset and its components. When documenting such specific data subset and its components. When documenting such specific data
models, where it is desired to specify the types of data items, it is models, where it is desired to specify the types of data items, it is
preferred to identify the types by their names in the generic data preferred to identify the types by their names in the generic data
model ("negative integer", "array") instead of by referring to model ("negative integer", "array") instead of by referring to
aspects of their CBOR representation ("major type 1", "major type aspects of their CBOR representation ("major type 1", "major type
4"). 4").
3. Creating CBOR-Based Protocols 4. Creating CBOR-Based Protocols
Data formats such as CBOR are often used in environments where there Data formats such as CBOR are often used in environments where there
is no format negotiation. A specific design goal of CBOR is to not is no format negotiation. A specific design goal of CBOR is to not
need any included or assumed schema: a decoder can take a CBOR item need any included or assumed schema: a decoder can take a CBOR item
and decode it with no other knowledge. and decode it with no other knowledge.
Of course, in real-world implementations, the encoder and the decoder Of course, in real-world implementations, the encoder and the decoder
will have a shared view of what should be in a CBOR data item. For will have a shared view of what should be in a CBOR data item. For
example, an agreed-to format might be "the item is an array whose example, an agreed-to format might be "the item is an array whose
first value is a UTF-8 string, second value is an integer, and first value is a UTF-8 string, second value is an integer, and
skipping to change at page 22, line 18 skipping to change at page 25, line 12
capable of understanding as many or as few types of values as is capable of understanding as many or as few types of values as is
required by the protocols in which it is used. This lack of required by the protocols in which it is used. This lack of
restrictions allows CBOR to be used in extremely constrained restrictions allows CBOR to be used in extremely constrained
environments. environments.
This section discusses some considerations in creating CBOR-based This section discusses some considerations in creating CBOR-based
protocols. It is advisory only and explicitly excludes any language protocols. It is advisory only and explicitly excludes any language
from RFC 2119 other than words that could be interpreted as "MAY" in from RFC 2119 other than words that could be interpreted as "MAY" in
the sense of RFC 2119. the sense of RFC 2119.
3.1. CBOR in Streaming Applications 4.1. CBOR in Streaming Applications
In a streaming application, a data stream may be composed of a In a streaming application, a data stream may be composed of a
sequence of CBOR data items concatenated back-to-back. In such an sequence of CBOR data items concatenated back-to-back. In such an
environment, the decoder immediately begins decoding a new data item environment, the decoder immediately begins decoding a new data item
if data is found after the end of a previous data item. if data is found after the end of a previous data item.
Not all of the bytes making up a data item may be immediately Not all of the bytes making up a data item may be immediately
available to the decoder; some decoders will buffer additional data available to the decoder; some decoders will buffer additional data
until a complete data item can be presented to the application. until a complete data item can be presented to the application.
Other decoders can present partial information about a top-level data Other decoders can present partial information about a top-level data
skipping to change at page 22, line 40 skipping to change at page 25, line 34
already be decoded, or even parts of a byte string that hasn't already be decoded, or even parts of a byte string that hasn't
completely arrived yet. completely arrived yet.
Note that some applications and protocols will not want to use Note that some applications and protocols will not want to use
indefinite-length encoding. Using indefinite-length encoding allows indefinite-length encoding. Using indefinite-length encoding allows
an encoder to not need to marshal all the data for counting, but it an encoder to not need to marshal all the data for counting, but it
requires a decoder to allocate increasing amounts of memory while requires a decoder to allocate increasing amounts of memory while
waiting for the end of the item. This might be fine for some waiting for the end of the item. This might be fine for some
applications but not others. applications but not others.
3.2. Generic Encoders and Decoders 4.2. Generic Encoders and Decoders
A generic CBOR decoder can decode all well-formed CBOR data and A generic CBOR decoder can decode all well-formed CBOR data and
present them to an application. CBOR data is well-formed if it uses present them to an application. CBOR data is well-formed if it uses
the initial bytes, as well as the byte strings and/or data items that the initial bytes, as well as the byte strings and/or data items that
are implied by their values, in the manner defined by CBOR, and no are implied by their values, in the manner defined by CBOR, and no
extraneous data follows (Appendix C). extraneous data follows (Appendix C).
Even though CBOR attempts to minimize these cases, not all well- Even though CBOR attempts to minimize these cases, not all well-
formed CBOR data is valid: for example, the format excludes simple formed CBOR data is valid: for example, the format excludes simple
values below 32 that are encoded with an extension byte. Also, values below 32 that are encoded with an extension byte. Also,
specific tags may make semantic constraints that may be violated, specific tags may make semantic constraints that may be violated,
such as by including a tag in a bignum tag or by following a byte such as by including a tag in a bignum tag or by following a byte
string within a date tag. Finally, the data may be invalid, such as string within a date tag. Finally, the data may be invalid, such as
invalid UTF-8 strings or date strings that do not conform to invalid UTF-8 strings or date strings that do not conform to
[RFC3339]. There is no requirement that generic encoders and [RFC3339]. There is no requirement that generic encoders and
decoders make unnatural choices for their application interface to decoders make unnatural choices for their application interface to
enable the processing of invalid data. Generic encoders and decoders enable the processing of invalid data. Generic encoders and decoders
are expected to forward simple values and tags even if their specific are expected to forward simple values and tags even if their specific
codepoints are not registered at the time the encoder/decoder is codepoints are not registered at the time the encoder/decoder is
written (Section 3.5). written (Section 4.5).
Generic decoders provide ways to present well-formed CBOR values, Generic decoders provide ways to present well-formed CBOR values,
both valid and invalid, to an application. The diagnostic notation both valid and invalid, to an application. The diagnostic notation
(Section 6) may be used to present well-formed CBOR values to humans. (Section 7) may be used to present well-formed CBOR values to humans.
Generic encoders provide an application interface that allows the Generic encoders provide an application interface that allows the
application to specify any well-formed value, including simple values application to specify any well-formed value, including simple values
and tags unknown to the encoder. and tags unknown to the encoder.
3.3. Syntax Errors 4.3. Syntax Errors
A decoder encountering a CBOR data item that is not well-formed A decoder encountering a CBOR data item that is not well-formed
generally can choose to completely fail the decoding (issue an error generally can choose to completely fail the decoding (issue an error
and/or stop processing altogether), substitute the problematic data and/or stop processing altogether), substitute the problematic data
and data items using a decoder-specific convention that clearly and data items using a decoder-specific convention that clearly
indicates there has been a problem, or take some other action. indicates there has been a problem, or take some other action.
3.3.1. Incomplete CBOR Data Items 4.3.1. Incomplete CBOR Data Items
The representation of a CBOR data item has a specific length, The representation of a CBOR data item has a specific length,
determined by its initial bytes and by the structure of any data determined by its initial bytes and by the structure of any data
items enclosed in the data items. If less data is available, this items enclosed in the data items. If less data is available, this
can be treated as a syntax error. A decoder may also implement can be treated as a syntax error. A decoder may also implement
incremental parsing, that is, decode the data item as far as it is incremental parsing, that is, decode the data item as far as it is
available and present the data found so far (such as in an event- available and present the data found so far (such as in an event-
based interface), with the option of continuing the decoding once based interface), with the option of continuing the decoding once
further data is available. further data is available.
skipping to change at page 24, line 9 skipping to change at page 27, line 5
o A decoder processes what it expects to be the last pair in a map o A decoder processes what it expects to be the last pair in a map
and comes to the end of the data. and comes to the end of the data.
o A decoder has just seen a tag and then encounters the end of the o A decoder has just seen a tag and then encounters the end of the
data. data.
o A decoder has seen the beginning of an indefinite-length item but o A decoder has seen the beginning of an indefinite-length item but
encounters the end of the data before it sees the "break" stop encounters the end of the data before it sees the "break" stop
code. code.
3.3.2. Malformed Indefinite-Length Items 4.3.2. Malformed Indefinite-Length Items
Examples of malformed indefinite-length data items include: Examples of malformed indefinite-length data items include:
o Within an indefinite-length byte string or text, a decoder finds o Within an indefinite-length byte string or text, a decoder finds
an item that is not of the appropriate major type before it finds an item that is not of the appropriate major type before it finds
the "break" stop code. the "break" stop code.
o Within an indefinite-length map, a decoder encounters the "break" o Within an indefinite-length map, a decoder encounters the "break"
stop code immediately after reading a key (the value is missing). stop code immediately after reading a key (the value is missing).
Another error is finding a "break" stop code at a point in the data Another error is finding a "break" stop code at a point in the data
where there is no immediately enclosing (unclosed) indefinite-length where there is no immediately enclosing (unclosed) indefinite-length
item. item.
3.3.3. Unknown Additional Information Values 4.3.3. Unknown Additional Information Values
At the time of writing, some additional information values are At the time of writing, some additional information values are
unassigned and reserved for future versions of this document (see unassigned and reserved for future versions of this document (see
Section 5.2). Since the overall syntax for these additional Section 6.2). Since the overall syntax for these additional
information values is not yet defined, a decoder that sees an information values is not yet defined, a decoder that sees an
additional information value that it does not understand cannot additional information value that it does not understand cannot
continue parsing. continue parsing.
3.4. Other Decoding Errors 4.4. Other Decoding Errors
A CBOR data item may be syntactically well-formed but present a A CBOR data item may be syntactically well-formed but present a
problem with interpreting the data encoded in it in the CBOR data problem with interpreting the data encoded in it in the CBOR data
model. Generally speaking, a decoder that finds a data item with model. Generally speaking, a decoder that finds a data item with
such a problem might issue a warning, might stop processing such a problem might issue a warning, might stop processing
altogether, might handle the error and make the problematic value altogether, might handle the error and make the problematic value
available to the application as such, or take some other type of available to the application as such, or take some other type of
action. action.
Such problems might include: Such problems might include:
Duplicate keys in a map: Generic decoders (Section 3.2) make data Duplicate keys in a map: Generic decoders (Section 4.2) make data
available to applications using the native CBOR data model. That available to applications using the native CBOR data model. That
data model includes maps (key-value mappings with unique keys), data model includes maps (key-value mappings with unique keys),
not multimaps (key-value mappings where multiple entries can have not multimaps (key-value mappings where multiple entries can have
the same key). Thus, a generic decoder that gets a CBOR map item the same key). Thus, a generic decoder that gets a CBOR map item
that has duplicate keys will decode to a map with only one that has duplicate keys will decode to a map with only one
instance of that key, or it might stop processing altogether. On instance of that key, or it might stop processing altogether. On
the other hand, a "streaming decoder" may not even be able to the other hand, a "streaming decoder" may not even be able to
notice (Section 3.7). notice (Section 4.7).
Inadmissible type on the value following a tag: Tags (Section 2.4) Inadmissible type on the value following a tag: Tags (Section 3.4)
specify what type of data item is supposed to follow the tag; for specify what type of data item is supposed to follow the tag; for
example, the tags for positive or negative bignums are supposed to example, the tags for positive or negative bignums are supposed to
be put on byte strings. A decoder that decodes the tagged data be put on byte strings. A decoder that decodes the tagged data
item into a native representation (a native big integer in this item into a native representation (a native big integer in this
example) is expected to check the type of the data item being example) is expected to check the type of the data item being
tagged. Even decoders that don't have such native representations tagged. Even decoders that don't have such native representations
available in their environment may perform the check on those tags available in their environment may perform the check on those tags
known to them and react appropriately. known to them and react appropriately.
Invalid UTF-8 string: A decoder might or might not want to verify Invalid UTF-8 string: A decoder might or might not want to verify
that the sequence of bytes in a UTF-8 string (major type 3) is that the sequence of bytes in a UTF-8 string (major type 3) is
actually valid UTF-8 and react appropriately. actually valid UTF-8 and react appropriately.
3.5. Handling Unknown Simple Values and Tags 4.5. Handling Unknown Simple Values and Tags
A decoder that comes across a simple value (Section 2.3) that it does A decoder that comes across a simple value (Section 3.3) that it does
not recognize, such as a value that was added to the IANA registry not recognize, such as a value that was added to the IANA registry
after the decoder was deployed or a value that the decoder chose not after the decoder was deployed or a value that the decoder chose not
to implement, might issue a warning, might stop processing to implement, might issue a warning, might stop processing
altogether, might handle the error by making the unknown value altogether, might handle the error by making the unknown value
available to the application as such (as is expected of generic available to the application as such (as is expected of generic
decoders), or take some other type of action. decoders), or take some other type of action.
A decoder that comes across a tag (Section 2.4) that it does not A decoder that comes across a tag (Section 3.4) that it does not
recognize, such as a tag that was added to the IANA registry after recognize, such as a tag that was added to the IANA registry after
the decoder was deployed or a tag that the decoder chose not to the decoder was deployed or a tag that the decoder chose not to
implement, might issue a warning, might stop processing altogether, implement, might issue a warning, might stop processing altogether,
might handle the error and present the unknown tag value together might handle the error and present the unknown tag value together
with the contained data item to the application (as is expected of with the contained data item to the application (as is expected of
generic decoders), might ignore the tag and simply present the generic decoders), might ignore the tag and simply present the
contained data item only to the application, or take some other type contained data item only to the application, or take some other type
of action. of action.
3.6. Numbers 4.6. Numbers
For the purposes of this specification, all number representations
for the same numeric value are equivalent. This means that an
encoder can encode a floating-point value of 0.0 as the integer 0.
It, however, also means that an application that expects to find
integer values only might find floating-point values if the encoder
decides these are desirable, such as when the floating-point value is
more compact than a 64-bit integer.
An application or protocol that uses CBOR might restrict the An application or protocol that uses CBOR might restrict the
representations of numbers. For instance, a protocol that only deals representations of numbers. For instance, a protocol that only deals
with integers might say that floating-point numbers may not be used with integers might say that floating-point numbers may not be used
and that decoders of that protocol do not need to be able to handle and that decoders of that protocol do not need to be able to handle
floating-point numbers. Similarly, a protocol or application that floating-point numbers. Similarly, a protocol or application that
uses CBOR might say that decoders need to be able to handle either uses CBOR might say that decoders need to be able to handle either
type of number. type of number.
CBOR-based protocols should take into account that different language CBOR-based protocols should take into account that different language
skipping to change at page 26, line 38 skipping to change at page 29, line 23
A CBOR-based protocol designed for compactness may want to exclude A CBOR-based protocol designed for compactness may want to exclude
specific integer encodings that are longer than necessary for the specific integer encodings that are longer than necessary for the
application, such as to save the need to implement 64-bit integers. application, such as to save the need to implement 64-bit integers.
There is an expectation that encoders will use the most compact There is an expectation that encoders will use the most compact
integer representation that can represent a given value. However, a integer representation that can represent a given value. However, a
compact application should accept values that use a longer-than- compact application should accept values that use a longer-than-
needed encoding (such as encoding "0" as 0b000_11001 followed by two needed encoding (such as encoding "0" as 0b000_11001 followed by two
bytes of 0x00) as long as the application can decode an integer of bytes of 0x00) as long as the application can decode an integer of
the given size. the given size.
3.7. Specifying Keys for Maps 4.7. Specifying Keys for Maps
The encoding and decoding applications need to agree on what types of The encoding and decoding applications need to agree on what types of
keys are going to be used in maps. In applications that need to keys are going to be used in maps. In applications that need to
interwork with JSON-based applications, keys probably should be interwork with JSON-based applications, keys probably should be
limited to UTF-8 strings only; otherwise, there has to be a specified limited to UTF-8 strings only; otherwise, there has to be a specified
mapping from the other CBOR types to Unicode characters, and this mapping from the other CBOR types to Unicode characters, and this
often leads to implementation errors. In applications where keys are often leads to implementation errors. In applications where keys are
numeric in nature and numeric ordering of keys is important to the numeric in nature and numeric ordering of keys is important to the
application, directly using the numbers for the keys is useful. application, directly using the numbers for the keys is useful.
skipping to change at page 27, line 25 skipping to change at page 30, line 13
source to maintain uniqueness. source to maintain uniqueness.
A CBOR-based protocol should make an intentional decision about what A CBOR-based protocol should make an intentional decision about what
to do when a receiving application does see multiple identical keys to do when a receiving application does see multiple identical keys
in a map. The resulting rule in the protocol should respect the CBOR in a map. The resulting rule in the protocol should respect the CBOR
data model: it cannot prescribe a specific handling of the entries data model: it cannot prescribe a specific handling of the entries
with the identical keys, except that it might have a rule that having with the identical keys, except that it might have a rule that having
identical keys in a map indicates a malformed map and that the identical keys in a map indicates a malformed map and that the
decoder has to stop with an error. Duplicate keys are also decoder has to stop with an error. Duplicate keys are also
prohibited by CBOR decoders that are using strict mode prohibited by CBOR decoders that are using strict mode
(Section 3.10). (Section 4.10).
The CBOR data model for maps does not allow ascribing semantics to The CBOR data model for maps does not allow ascribing semantics to
the order of the key/value pairs in the map representation. the order of the key/value pairs in the map representation. Thus, it
Thus, it would be a very bad practice to define a CBOR-based protocol would be a very bad practice to define a CBOR-based protocol in such
in such a way that changing the key/value pair order in a map would a way that changing the key/value pair order in a map would change
change the semantics, apart from trivial aspects (cache usage, etc.). the semantics, apart from trivial aspects (cache usage, etc.). (A
(A CBOR-based protocol can prescribe a specific order of CBOR-based protocol can prescribe a specific order of serialization,
serialization, such as for canonicalization.) such as for canonicalization.)
Applications for constrained devices that have maps with 24 or fewer Applications for constrained devices that have maps with 24 or fewer
frequently used keys should consider using small integers (and those frequently used keys should consider using small integers (and those
with up to 48 frequently used keys should consider also using small with up to 48 frequently used keys should consider also using small
negative integers) because the keys can then be encoded in a single negative integers) because the keys can then be encoded in a single
byte. byte.
3.8. Undefined Values 4.7.1. Equivalence of Keys
In some CBOR-based protocols, the simple value (Section 2.3) of This notion of equivalence must be used to determine whether keys in
maps are duplicates or distinct.
o All numbers are compared by their numeric value.
* Integer data items with the same value are equal regardless of
how many bytes are used to encode them.
* Floating point data items with the same value are equal
regardless of how many bytes are used to encode them.
* An integer value encoded as a floating point data item is
equivalent to the same value encoded as an integer
o Byte strings and text strings are compared by their binary
content.
* A different length encoding has no effect on equivalence.
* A byte string is equal to a text string if they have the same
binary content.
o Two arrays are equal if all their items are in the same order and
equal.
o Two maps are equal if they have the same set of pairs regardless
of their order; pairs are equal if both the key and value are
equal.
o Tags have no effect in determining equality of a data item, if two
items are equal then they are equal irrespective of any tags that
either or both may have.
o Simple values are equal if they simply have the same value.
Nothing else is equal, a simple value 2 is not equivalent to an
integer 2 and an array cannot be equivalent to a map with the same
values and sequential integer keys.
4.8. Undefined Values
In some CBOR-based protocols, the simple value (Section 3.3) of
Undefined might be used by an encoder as a substitute for a data item Undefined might be used by an encoder as a substitute for a data item
with an encoding problem, in order to allow the rest of the enclosing with an encoding problem, in order to allow the rest of the enclosing
data items to be encoded without harm. data items to be encoded without harm.
3.9. Canonical CBOR 4.9. Canonical CBOR
Some protocols may want encoders to only emit CBOR in a particular Some protocols may want encoders to only emit CBOR in a particular
canonical format; those protocols might also have the decoders check canonical format; those protocols might also have the decoders check
that their input is canonical. Those protocols are free to define that their input is canonical. Those protocols are free to define
what they mean by a canonical format and what encoders and decoders what they mean by a canonical format and what encoders and decoders
are expected to do. This section lists some suggestions for such are expected to do. This section defines a set of restrictions that
protocols. can serve as the base of such a canonical format.
If a protocol considers "canonical" to mean that two encoder A CBOR encoding satisfies the "core canonicalization requirements" if
implementations starting with the same input data will produce the it satisfies the following restrictions:
same CBOR output, the following four rules would suffice:
o Integers must be as small as possible. o Integers MUST be as short as possible. In particular:
* 0 to 23 and -1 to -24 must be expressed in the same byte as the * 0 to 23 and -1 to -24 MUST be expressed in the same byte as the
major type; major type;
* 24 to 255 and -25 to -256 must be expressed only with an * 24 to 255 and -25 to -256 MUST be expressed only with an
additional uint8_t; additional uint8_t;
* 256 to 65535 and -257 to -65536 must be expressed only with an * 256 to 65535 and -257 to -65536 MUST be expressed only with an
additional uint16_t; additional uint16_t;
* 65536 to 4294967295 and -65537 to -4294967296 must be expressed * 65536 to 4294967295 and -65537 to -4294967296 MUST be expressed
only with an additional uint32_t. only with an additional uint32_t.
o The expression of lengths in major types 2 through 5 must be as o The expression of lengths in major types 2 through 5 MUST be as
short as possible. The rules for these lengths follow the above short as possible. The rules for these lengths follow the above
rule for integers. rule for integers.
o The keys in every map must be sorted lowest value to highest. o The keys in every map MUST be sorted in the bytewise lexicographic
Sorting is performed on the bytes of the representation of the key order of their canonical encodings. For example, the following
data items without paying attention to the 3/5 bit splitting for keys are sorted correctly:
major types. (Note that this rule allows maps that have keys of
different types, even though that is probably a bad practice that
could lead to errors in some canonicalization implementations.)
The sorting rules are:
* If two keys have different lengths, the shorter one sorts 1. 10, encoded as 0x0a.
earlier;
* If two keys have the same length, the one with the lower value 2. 100, encoded as 0x1864.
in (byte-wise) lexical order sorts earlier.
o Indefinite-length items must be made into definite-length items. 3. -1, encoded as 0x20.
4. "z", encoded as 0x617a.
5. "aa", encoded as 0x626161.
6. [100], encoded as 0x811864.
7. [-1], encoded as 0x8120.
8. false, encoded as 0xf4.
o Indefinite-length items MUST not appear. They can be encoded as
definite-length items instead.
If a protocol allows for IEEE floats, then additional If a protocol allows for IEEE floats, then additional
canonicalization rules might need to be added. One example rule canonicalization rules might need to be added. One example rule
might be to have all floats start as a 64-bit float, then do a test might be to have all floats start as a 64-bit float, then do a test
conversion to a 32-bit float; if the result is the same numeric conversion to a 32-bit float; if the result is the same numeric
value, use the shorter value and repeat the process with a test value, use the shorter value and repeat the process with a test
conversion to a 16-bit float. (This rule selects 16-bit float for conversion to a 16-bit float. (This rule selects 16-bit float for
positive and negative Infinity as well.) Also, there are many positive and negative Infinity as well.) Also, there are many
representations for NaN. If NaN is an allowed value, it must always representations for NaN. If NaN is an allowed value, it must always
be represented as 0xf97e00. be represented as 0xf97e00.
skipping to change at page 29, line 25 skipping to change at page 33, line 7
CBOR tags present additional considerations for canonicalization. CBOR tags present additional considerations for canonicalization.
The absence or presence of tags in a canonical format is determined The absence or presence of tags in a canonical format is determined
by the optionality of the tags in the protocol. In a CBOR-based by the optionality of the tags in the protocol. In a CBOR-based
protocol that allows optional tagging anywhere, the canonical format protocol that allows optional tagging anywhere, the canonical format
must not allow them. In a protocol that requires tags in certain must not allow them. In a protocol that requires tags in certain
places, the tag needs to appear in the canonical format. A CBOR- places, the tag needs to appear in the canonical format. A CBOR-
based protocol that uses canonicalization might instead say that all based protocol that uses canonicalization might instead say that all
tags that appear in a message must be retained regardless of whether tags that appear in a message must be retained regardless of whether
they are optional. they are optional.
3.10. Strict Mode Protocols that include floating, big integer, or other complex values
need to define extra requirements on their canonical encodings. For
example:
o If a protocol includes a field that can express floating values
(Section 3.3), the protocol's canonicalization needs to specify
whether the integer 1.0 is encoded as 0x01, 0xf93c00,
0xfa3f800000, or 0xfb3ff0000000000000. Three sensible rules for
this are:
1. Encode integral values that fit in 64 bits as values from
major types 0 and 1, and other values as the smallest of 16-,
32-, or 64-bit floating point that accurately represents the
value,
2. Encode all values as the smallest of 16-, 32-, or 64-bit
floating point that accurately represents the value, even for
integral values, or
3. Encode all values as 64-bit floating point.
If NaN is an allowed value, the protocol needs to pick a single
representation, for example 0xf97e00.
o If a protocol includes a field that can express integers larger
than 2^64 using tag 2 (Section 3.4.2), the protocol's
canonicalization needs to specify whether small integers are
expressed using the tag or major types 0 and 1.
o A protocol might give encoders the choice of representing a URL as
either a text string or, using Section 3.4.4.3, tag 32 containing
a text string. This protocol's canonicalization needs to either
require that the tag is present or require that it's absent, not
allow either one.
4.9.1. Length-first map key ordering
The core canonicalization requirements sort map keys in a different
order from the one suggested by [RFC7049]. Protocols that need to be
compatible with [RFC7049]'s order can instead be specified in terms
of this specification's "length-first core canonicalization
requirements":
A CBOR encoding satisfies the "length-first core canonicalization
requirements" if it satisfies the core canonicalization requirements
except that the keys in every map MUST be sorted such that:
1. If two keys have different lengths, the shorter one sorts
earlier;
2. If two keys have the same length, the one with the lower value in
(byte-wise) lexical order sorts earlier.
For example, under the length-first core canonicalization
requirements, the following keys are sorted correctly:
1. 10, encoded as 0x0a.
2. -1, encoded as 0x20.
3. false, encoded as 0xf4.
4. 100, encoded as 0x1864.
5. "z", encoded as 0x617a.
6. [-1], encoded as 0x8120.
7. "aa", encoded as 0x626161.
8. [100], encoded as 0x811864.
4.10. Strict Mode
Some areas of application of CBOR do not require canonicalization Some areas of application of CBOR do not require canonicalization
(Section 3.9) but may require that different decoders reach the same (Section 4.9) but may require that different decoders reach the same
(semantically equivalent) results, even in the presence of (semantically equivalent) results, even in the presence of
potentially malicious data. This can be required if one application potentially malicious data. This can be required if one application
(such as a firewall or other protecting entity) makes a decision (such as a firewall or other protecting entity) makes a decision
based on the data that another application, which independently based on the data that another application, which independently
decodes the data, relies on. decodes the data, relies on.
Normally, it is the responsibility of the sender to avoid ambiguously Normally, it is the responsibility of the sender to avoid ambiguously
decodable data. However, the sender might be an attacker specially decodable data. However, the sender might be an attacker specially
making up CBOR data such that it will be interpreted differently by making up CBOR data such that it will be interpreted differently by
different decoders in an attempt to exploit that as a vulnerability. different decoders in an attempt to exploit that as a vulnerability.
Generic decoders used in applications where this might be a problem Generic decoders used in applications where this might be a problem
need to support a strict mode in which it is also the responsibility need to support a strict mode in which it is also the responsibility
of the receiver to reject ambiguously decodable data. It is expected of the receiver to reject ambiguously decodable data. It is expected
that firewalls and other security systems that decode CBOR will only that firewalls and other security systems that decode CBOR will only
decode in strict mode. decode in strict mode.
A decoder in strict mode will reliably reject any data that could be A decoder in strict mode will reliably reject any data that could be
interpreted by other decoders in different ways. It will reliably interpreted by other decoders in different ways. It will reliably
reject data items with syntax errors (Section 3.3). It will also reject data items with syntax errors (Section 4.3). It will also
expend the effort to reliably detect other decoding errors expend the effort to reliably detect other decoding errors
(Section 3.4). In particular, a strict decoder needs to have an API (Section 4.4). In particular, a strict decoder needs to have an API
that reports an error (and does not return data) for a CBOR data item that reports an error (and does not return data) for a CBOR data item
that contains any of the following: that contains any of the following:
o a map (major type 5) that has more than one entry with the same o a map (major type 5) that has more than one entry with the same
key key
o a tag that is used on a data item of the incorrect type o a tag that is used on a data item of the incorrect type
o a data item that is incorrectly formatted for the type given to o a data item that is incorrectly formatted for the type given to
it, such as invalid UTF-8 or data that cannot be interpreted with it, such as invalid UTF-8 or data that cannot be interpreted with
skipping to change at page 30, line 41 skipping to change at page 36, line 5
Since some of this processing may have an appreciable cost (in Since some of this processing may have an appreciable cost (in
particular with duplicate detection for maps), support of strict mode particular with duplicate detection for maps), support of strict mode
is not a requirement placed on all CBOR decoders. is not a requirement placed on all CBOR decoders.
Some encoders will rely on their applications to provide input data Some encoders will rely on their applications to provide input data
in such a way that unambiguously decodable CBOR results. A generic in such a way that unambiguously decodable CBOR results. A generic
encoder also may want to provide a strict mode where it reliably encoder also may want to provide a strict mode where it reliably
limits its output to unambiguously decodable CBOR, independent of limits its output to unambiguously decodable CBOR, independent of
whether or not its application is providing API-conformant data. whether or not its application is providing API-conformant data.
4. Converting Data between CBOR and JSON 5. Converting Data between CBOR and JSON
This section gives non-normative advice about converting between CBOR This section gives non-normative advice about converting between CBOR
and JSON. Implementations of converters are free to use whichever and JSON. Implementations of converters are free to use whichever
advice here they want. advice here they want.
It is worth noting that a JSON text is a sequence of characters, not It is worth noting that a JSON text is a sequence of characters, not
an encoded sequence of bytes, while a CBOR data item consists of an encoded sequence of bytes, while a CBOR data item consists of
bytes, not characters. bytes, not characters.
4.1. Converting from CBOR to JSON 5.1. Converting from CBOR to JSON
Most of the types in CBOR have direct analogs in JSON. However, some Most of the types in CBOR have direct analogs in JSON. However, some
do not, and someone implementing a CBOR-to-JSON converter has to do not, and someone implementing a CBOR-to-JSON converter has to
consider what to do in those cases. The following non-normative consider what to do in those cases. The following non-normative
advice deals with these by converting them to a single substitute advice deals with these by converting them to a single substitute
value, such as a JSON null. value, such as a JSON null.
o An integer (major type 0 or 1) becomes a JSON number. o An integer (major type 0 or 1) becomes a JSON number.
o A byte string (major type 2) that is not embedded in a tag that o A byte string (major type 2) that is not embedded in a tag that
skipping to change at page 32, line 18 skipping to change at page 37, line 30
o A byte string with an encoding hint (major type 6, tag value 21 o A byte string with an encoding hint (major type 6, tag value 21
through 23) is encoded as described and becomes a JSON string. through 23) is encoded as described and becomes a JSON string.
o For all other tags (major type 6, any other tag value), the o For all other tags (major type 6, any other tag value), the
embedded CBOR item is represented as a JSON value; the tag value embedded CBOR item is represented as a JSON value; the tag value
is ignored. is ignored.
o Indefinite-length items are made definite before conversion. o Indefinite-length items are made definite before conversion.
4.2. Converting from JSON to CBOR 5.2. Converting from JSON to CBOR
All JSON values, once decoded, directly map into one or more CBOR All JSON values, once decoded, directly map into one or more CBOR
values. As with any kind of CBOR generation, decisions have to be values. As with any kind of CBOR generation, decisions have to be
made with respect to number representation. In a suggested made with respect to number representation. In a suggested
conversion: conversion:
o JSON numbers without fractional parts (integer numbers) are o JSON numbers without fractional parts (integer numbers) are
represented as integers (major types 0 and 1, possibly major type represented as integers (major types 0 and 1, possibly major type
6 tag value 2 and 3), choosing the shortest form; integers longer 6 tag value 2 and 3), choosing the shortest form; integers longer
than an implementation-defined threshold (which is usually either than an implementation-defined threshold (which is usually either
skipping to change at page 33, line 8 skipping to change at page 38, line 19
perform a JSON-to-CBOR encoding in place in a single buffer. This perform a JSON-to-CBOR encoding in place in a single buffer. This
strategy would need to carefully consider a number of pathological strategy would need to carefully consider a number of pathological
cases, such as that some strings represented with no or very few cases, such as that some strings represented with no or very few
escapes and longer (or much longer) than 255 bytes may expand when escapes and longer (or much longer) than 255 bytes may expand when
encoded as UTF-8 strings in CBOR. Similarly, a few of the binary encoded as UTF-8 strings in CBOR. Similarly, a few of the binary
floating-point representations might cause expansion from some short floating-point representations might cause expansion from some short
decimal representations (1.1, 1e9) in JSON. This may be hard to get decimal representations (1.1, 1e9) in JSON. This may be hard to get
right, and any ensuing vulnerabilities may be exploited by an right, and any ensuing vulnerabilities may be exploited by an
attacker. attacker.
5. Future Evolution of CBOR 6. Future Evolution of CBOR
Successful protocols evolve over time. New ideas appear, Successful protocols evolve over time. New ideas appear,
implementation platforms improve, related protocols are developed and implementation platforms improve, related protocols are developed and
evolve, and new requirements from applications and protocols are evolve, and new requirements from applications and protocols are
added. Facilitating protocol evolution is therefore an important added. Facilitating protocol evolution is therefore an important
design consideration for any protocol development. design consideration for any protocol development.
For protocols that will use CBOR, CBOR provides some useful For protocols that will use CBOR, CBOR provides some useful
mechanisms to facilitate their evolution. Best practices for this mechanisms to facilitate their evolution. Best practices for this
are well known, particularly from JSON format development of JSON- are well known, particularly from JSON format development of JSON-
skipping to change at page 33, line 31 skipping to change at page 38, line 42
However, facilitating the evolution of CBOR itself is very well However, facilitating the evolution of CBOR itself is very well
within its scope. CBOR is designed to both provide a stable basis within its scope. CBOR is designed to both provide a stable basis
for development of CBOR-based protocols and to be able to evolve. for development of CBOR-based protocols and to be able to evolve.
Since a successful protocol may live for decades, CBOR needs to be Since a successful protocol may live for decades, CBOR needs to be
designed for decades of use and evolution. This section provides designed for decades of use and evolution. This section provides
some guidance for the evolution of CBOR. It is necessarily more some guidance for the evolution of CBOR. It is necessarily more
subjective than other parts of this document. It is also necessarily subjective than other parts of this document. It is also necessarily
incomplete, lest it turn into a textbook on protocol development. incomplete, lest it turn into a textbook on protocol development.
5.1. Extension Points 6.1. Extension Points
In a protocol design, opportunities for evolution are often included In a protocol design, opportunities for evolution are often included
in the form of extension points. For example, there may be a in the form of extension points. For example, there may be a
codepoint space that is not fully allocated from the outset, and the codepoint space that is not fully allocated from the outset, and the
protocol is designed to tolerate and embrace implementations that protocol is designed to tolerate and embrace implementations that
start using more codepoints than initially allocated. start using more codepoints than initially allocated.
Sizing the codepoint space may be difficult because the range Sizing the codepoint space may be difficult because the range
required may be hard to predict. An attempt should be made to make required may be hard to predict. An attempt should be made to make
the codepoint space large enough so that it can slowly be filled over the codepoint space large enough so that it can slowly be filled over
the intended lifetime of the protocol. the intended lifetime of the protocol.
CBOR has three major extension points: CBOR has three major extension points:
o the "simple" space (values in major type 7). Of the 24 efficient o the "simple" space (values in major type 7). Of the 24 efficient
(and 224 slightly less efficient) values, only a small number have (and 224 slightly less efficient) values, only a small number have
been allocated. Implementations receiving an unknown simple data been allocated. Implementations receiving an unknown simple data
item may be able to process it as such, given that the structure item may be able to process it as such, given that the structure
of the value is indeed simple. The IANA registry in Section 7.1 of the value is indeed simple. The IANA registry in Section 8.1
is the appropriate way to address the extensibility of this is the appropriate way to address the extensibility of this
codepoint space. codepoint space.
o the "tag" space (values in major type 6). Again, only a small o the "tag" space (values in major type 6). Again, only a small
part of the codepoint space has been allocated, and the space is part of the codepoint space has been allocated, and the space is
abundant (although the early numbers are more efficient than the abundant (although the early numbers are more efficient than the
later ones). Implementations receiving an unknown tag can choose later ones). Implementations receiving an unknown tag can choose
to simply ignore it or to process it as an unknown tag wrapping to simply ignore it or to process it as an unknown tag wrapping
the following data item. The IANA registry in Section 7.2 is the the following data item. The IANA registry in Section 8.2 is the
appropriate way to address the extensibility of this codepoint appropriate way to address the extensibility of this codepoint
space. space.
o the "additional information" space. An implementation receiving o the "additional information" space. An implementation receiving
an unknown additional information value has no way to continue an unknown additional information value has no way to continue
parsing, so allocating codepoints to this space is a major step. parsing, so allocating codepoints to this space is a major step.
There are also very few codepoints left. There are also very few codepoints left.
5.2. Curating the Additional Information Space 6.2. Curating the Additional Information Space
The human mind is sometimes drawn to filling in little perceived gaps The human mind is sometimes drawn to filling in little perceived gaps
to make something neat. We expect the remaining gaps in the to make something neat. We expect the remaining gaps in the
codepoint space for the additional information values to be an codepoint space for the additional information values to be an
attractor for new ideas, just because they are there. attractor for new ideas, just because they are there.
The present specification does not manage the additional information The present specification does not manage the additional information
codepoint space by an IANA registry. Instead, allocations out of codepoint space by an IANA registry. Instead, allocations out of
this space can only be done by updating this specification. this space can only be done by updating this specification.
For an additional information value of n >= 24, the size of the For an additional information value of n >= 24, the size of the
additional data typically is 2**(n-24) bytes. Therefore, additional additional data typically is 2**(n-24) bytes. Therefore, additional
information values 28 and 29 should be viewed as candidates for information values 28 and 29 should be viewed as candidates for
128-bit and 256-bit quantities, in case a need arises to add them to 128-bit and 256-bit quantities, in case a need arises to add them to
the protocol. Additional information value 30 is then the only the protocol. Additional information value 30 is then the only
additional information value available for general allocation, and additional information value available for general allocation, and
there should be a very good reason for allocating it before assigning there should be a very good reason for allocating it before assigning
it through an update of this protocol. it through an update of this protocol.
6. Diagnostic Notation 7. Diagnostic Notation
CBOR is a binary interchange format. To facilitate documentation and CBOR is a binary interchange format. To facilitate documentation and
debugging, and in particular to facilitate communication between debugging, and in particular to facilitate communication between
entities cooperating in debugging, this section defines a simple entities cooperating in debugging, this section defines a simple
human-readable diagnostic notation. All actual interchange always human-readable diagnostic notation. All actual interchange always
happens in the binary format. happens in the binary format.
Note that this truly is a diagnostic format; it is not meant to be Note that this truly is a diagnostic format; it is not meant to be
parsed. Therefore, no formal definition (as in ABNF) is given in parsed. Therefore, no formal definition (as in ABNF) is given in
this document. (Implementers looking for a text-based format for this document. (Implementers looking for a text-based format for
skipping to change at page 35, line 39 skipping to change at page 41, line 5
padding, enclosed in single quotes, prefixed by >h< for base16, >b32< padding, enclosed in single quotes, prefixed by >h< for base16, >b32<
for base32, >h32< for base32hex, >b64< for base64 or base64url (the for base32, >h32< for base32hex, >b64< for base64 or base64url (the
actual encodings do not overlap, so the string remains unambiguous). actual encodings do not overlap, so the string remains unambiguous).
For example, the byte string 0x12345678 could be written h'12345678', For example, the byte string 0x12345678 could be written h'12345678',
b32'CI2FM6A', or b64'EjRWeA'. b32'CI2FM6A', or b64'EjRWeA'.
Unassigned simple values are given as "simple()" with the appropriate Unassigned simple values are given as "simple()" with the appropriate
integer in the parentheses. For example, "simple(42)" indicates integer in the parentheses. For example, "simple(42)" indicates
major type 7, value 42. major type 7, value 42.
6.1. Encoding Indicators 7.1. Encoding Indicators
Sometimes it is useful to indicate in the diagnostic notation which Sometimes it is useful to indicate in the diagnostic notation which
of several alternative representations were actually used; for of several alternative representations were actually used; for
example, a data item written >1.5< by a diagnostic decoder might have example, a data item written >1.5< by a diagnostic decoder might have
been encoded as a half-, single-, or double-precision float. been encoded as a half-, single-, or double-precision float.
The convention for encoding indicators is that anything starting with The convention for encoding indicators is that anything starting with
an underscore and all following characters that are alphanumeric or an underscore and all following characters that are alphanumeric or
underscore, is an encoding indicator, and can be ignored by anyone underscore, is an encoding indicator, and can be ignored by anyone
not interested in this information. Encoding indicators are always not interested in this information. Encoding indicators are always
skipping to change at page 36, line 23 skipping to change at page 41, line 36
preceding bracket or brace) was encoded with an additional preceding bracket or brace) was encoded with an additional
information value of 24+n. For example, 1.5_1 is a half-precision information value of 24+n. For example, 1.5_1 is a half-precision
floating-point number, while 1.5_3 is encoded as double precision. floating-point number, while 1.5_3 is encoded as double precision.
This encoding indicator is not shown in Appendix A. (Note that the This encoding indicator is not shown in Appendix A. (Note that the
encoding indicator "_" is thus an abbreviation of the full form "_7", encoding indicator "_" is thus an abbreviation of the full form "_7",
which is not used.) which is not used.)
As a special case, byte and text strings of indefinite length can be As a special case, byte and text strings of indefinite length can be
notated in the form (_ h'0123', h'4567') and (_ "foo", "bar"). notated in the form (_ h'0123', h'4567') and (_ "foo", "bar").
7. IANA Considerations 8. IANA Considerations
IANA has created two registries for new CBOR values. The registries IANA has created two registries for new CBOR values. The registries
are separate, that is, not under an umbrella registry, and follow the are separate, that is, not under an umbrella registry, and follow the
rules in [RFC5226]. IANA has also assigned a new MIME media type and rules in [RFC5226]. IANA has also assigned a new MIME media type and
an associated Constrained Application Protocol (CoAP) Content-Format an associated Constrained Application Protocol (CoAP) Content-Format
entry. entry.
7.1. Simple Values Registry 8.1. Simple Values Registry
IANA has created the "Concise Binary Object Representation (CBOR) IANA has created the "Concise Binary Object Representation (CBOR)
Simple Values" registry. The initial values are shown in Table 2. Simple Values" registry. The initial values are shown in Table 2.
New entries in the range 0 to 19 are assigned by Standards Action. New entries in the range 0 to 19 are assigned by Standards Action.
It is suggested that these Standards Actions allocate values starting It is suggested that these Standards Actions allocate values starting
with the number 16 in order to reserve the lower numbers for with the number 16 in order to reserve the lower numbers for
contiguous blocks (if any). contiguous blocks (if any).
New entries in the range 32 to 255 are assigned by Specification New entries in the range 32 to 255 are assigned by Specification
Required. Required.
7.2. Tags Registry 8.2. Tags Registry
IANA has created the "Concise Binary Object Representation (CBOR) IANA has created the "Concise Binary Object Representation (CBOR)
Tags" registry. The initial values are shown in Table 3. Tags" registry. The initial values are shown in Table 3.
New entries in the range 0 to 23 are assigned by Standards Action. New entries in the range 0 to 23 are assigned by Standards Action.
New entries in the range 24 to 255 are assigned by Specification New entries in the range 24 to 255 are assigned by Specification
Required. New entries in the range 256 to 18446744073709551615 are Required. New entries in the range 256 to 18446744073709551615 are
assigned by First Come First Served. The template for registration assigned by First Come First Served. The template for registration
requests is: requests is:
o Data item o Data item
o Semantics (short form) o Semantics (short form)
In addition, First Come First Served requests should include: In addition, First Come First Served requests should include:
o Point of contact o Point of contact
o Description of semantics (URL) o Description of semantics (URL) - This description is optional; the
This description is optional; the URL can point to something like URL can point to something like an Internet-Draft or a web page.
an Internet-Draft or a web page.
7.3. Media Type ("MIME Type") 8.3. Media Type ("MIME Type")
The Internet media type [RFC6838] for CBOR data is application/cbor. The Internet media type [RFC6838] for CBOR data is application/cbor.
Type name: application Type name: application
Subtype name: cbor Subtype name: cbor
Required parameters: n/a Required parameters: n/a
Optional parameters: n/a Optional parameters: n/a
Encoding considerations: binary Encoding considerations: binary
Security considerations: See Section 8 of this document Security considerations: See Section 9 of this document
Interoperability considerations: n/a Interoperability considerations: n/a
Published specification: This document Published specification: This document
Applications that use this media type: None yet, but it is expected Applications that use this media type: None yet, but it is expected
that this format will be deployed in protocols and applications. that this format will be deployed in protocols and applications.
Additional information: Additional information:
Magic number(s): n/a Magic number(s): n/a
skipping to change at page 38, line 24 skipping to change at page 43, line 24
Intended usage: COMMON Intended usage: COMMON
Restrictions on usage: none Restrictions on usage: none
Author: Author:
Carsten Bormann <cabo@tzi.org> Carsten Bormann <cabo@tzi.org>
Change controller: Change controller:
The IESG <iesg@ietf.org> The IESG <iesg@ietf.org>
7.4. CoAP Content-Format 8.4. CoAP Content-Format
Media Type: application/cbor Media Type: application/cbor
Encoding: - Encoding: -
Id: 60 Id: 60
Reference: [RFCthis] Reference: [RFCthis]
7.5. The +cbor Structured Syntax Suffix Registration 8.5. The +cbor Structured Syntax Suffix Registration
Name: Concise Binary Object Representation (CBOR) Name: Concise Binary Object Representation (CBOR)
+suffix: +cbor +suffix: +cbor
References: [RFCthis] References: [RFCthis]
Encoding Considerations: CBOR is a binary format. Encoding Considerations: CBOR is a binary format.
Interoperability Considerations: n/a Interoperability Considerations: n/a
skipping to change at page 39, line 23 skipping to change at page 44, line 23
For cases defined in +cbor, where the fragment identifier resolves For cases defined in +cbor, where the fragment identifier resolves
per the +cbor rules, then process as specified in +cbor. per the +cbor rules, then process as specified in +cbor.
For cases defined in +cbor, where the fragment identifier does For cases defined in +cbor, where the fragment identifier does
not resolve per the +cbor rules, then process as specified in not resolve per the +cbor rules, then process as specified in
"xxx/yyy+cbor". "xxx/yyy+cbor".
For cases not defined in +cbor, then process as specified in For cases not defined in +cbor, then process as specified in
"xxx/yyy+cbor". "xxx/yyy+cbor".
Security Considerations: See Section 8 of this document Security Considerations: See Section 9 of this document
Contact: Contact:
Apps Area Working Group (apps-discuss@ietf.org) Apps Area Working Group (apps-discuss@ietf.org)
Author/Change Controller: Author/Change Controller:
The Apps Area Working Group. The Apps Area Working Group.
The IESG has change control over this registration. The IESG has change control over this registration.
8. Security Considerations 9. Security Considerations
A network-facing application can exhibit vulnerabilities in its A network-facing application can exhibit vulnerabilities in its
processing logic for incoming data. Complex parsers are well known processing logic for incoming data. Complex parsers are well known
as a likely source of such vulnerabilities, such as the ability to as a likely source of such vulnerabilities, such as the ability to
remotely crash a node, or even remotely execute arbitrary code on it. remotely crash a node, or even remotely execute arbitrary code on it.
CBOR attempts to narrow the opportunities for introducing such CBOR attempts to narrow the opportunities for introducing such
vulnerabilities by reducing parser complexity, by giving the entire vulnerabilities by reducing parser complexity, by giving the entire
range of encodable values a meaning where possible. range of encodable values a meaning where possible.
Resource exhaustion attacks might attempt to lure a decoder into Resource exhaustion attacks might attempt to lure a decoder into
skipping to change at page 40, line 11 skipping to change at page 45, line 11
Applications where a CBOR data item is examined by a gatekeeper Applications where a CBOR data item is examined by a gatekeeper
function and later used by a different application may exhibit function and later used by a different application may exhibit
vulnerabilities when multiple interpretations of the data item are vulnerabilities when multiple interpretations of the data item are
possible. For example, an attacker could make use of duplicate keys possible. For example, an attacker could make use of duplicate keys
in maps and precision issues in numbers to make the gatekeeper base in maps and precision issues in numbers to make the gatekeeper base
its decisions on a different interpretation than the one that will be its decisions on a different interpretation than the one that will be
used by the second application. Protocols that are used in a used by the second application. Protocols that are used in a
security context should be defined in such a way that these multiple security context should be defined in such a way that these multiple
interpretations are reliably reduced to a single one. To facilitate interpretations are reliably reduced to a single one. To facilitate
this, encoder and decoder implementations used in such contexts this, encoder and decoder implementations used in such contexts
should provide at least one strict mode of operation (Section 3.10). should provide at least one strict mode of operation (Section 4.10).
9. Acknowledgements 10. Acknowledgements
CBOR was inspired by MessagePack. MessagePack was developed and CBOR was inspired by MessagePack. MessagePack was developed and
promoted by Sadayuki Furuhashi ("frsyuki"). This reference to promoted by Sadayuki Furuhashi ("frsyuki"). This reference to
MessagePack is solely for attribution; CBOR is not intended as a MessagePack is solely for attribution; CBOR is not intended as a
version of or replacement for MessagePack, as it has different design version of or replacement for MessagePack, as it has different design
goals and requirements. goals and requirements.
The need for functionality beyond the original MessagePack The need for functionality beyond the original MessagePack
Specification became obvious to many people at about the same time Specification became obvious to many people at about the same time
around the year 2012. BinaryPack is a minor derivation of around the year 2012. BinaryPack is a minor derivation of
skipping to change at page 40, line 38 skipping to change at page 45, line 38
separate text string representation from byte string representation. separate text string representation from byte string representation.
The encoding of the additional information in CBOR was inspired by The encoding of the additional information in CBOR was inspired by
the encoding of length information designed by Klaus Hartke for CoAP. the encoding of length information designed by Klaus Hartke for CoAP.
This document also incorporates suggestions made by many people, This document also incorporates suggestions made by many people,
notably Dan Frost, James Manger, Joe Hildebrand, Keith Moore, Matthew notably Dan Frost, James Manger, Joe Hildebrand, Keith Moore, Matthew
Lepinski, Nico Williams, Phillip Hallam-Baker, Ray Polk, Tim Bray, Lepinski, Nico Williams, Phillip Hallam-Baker, Ray Polk, Tim Bray,
Tony Finch, Tony Hansen, and Yaron Sheffer. Tony Finch, Tony Hansen, and Yaron Sheffer.
10. References 11. References
10.1. Normative References 11.1. Normative References
[ECMA262] European Computer Manufacturers Association, "ECMAScript [ECMA262] European Computer Manufacturers Association, "ECMAScript
Language Specification 5.1 Edition", ECMA Standard ECMA- Language Specification 5.1 Edition", ECMA Standard ECMA-
262, June 2011, <http://www.ecma- 262, June 2011, <http://www.ecma-
international.org/publications/files/ecma-st/ international.org/publications/files/ecma-st/
ECMA-262.pdf>. ECMA-262.pdf>.
[RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail
Extensions (MIME) Part One: Format of Internet Message Extensions (MIME) Part One: Format of Internet Message
Bodies", RFC 2045, DOI 10.17487/RFC2045, November 1996, Bodies", RFC 2045, DOI 10.17487/RFC2045, November 1996,
<https://www.rfc-editor.org/info/rfc2045>. <https://www.rfc-editor.org/info/rfc2045>.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, Requirement Levels", BCP 14, RFC 2119,
DOI 10.17487/RFC2119, March 1997, <https://www.rfc- DOI 10.17487/RFC2119, March 1997,
editor.org/info/rfc2119>. <https://www.rfc-editor.org/info/rfc2119>.
[RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: [RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet:
Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002, Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002,
<https://www.rfc-editor.org/info/rfc3339>. <https://www.rfc-editor.org/info/rfc3339>.
[RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO
10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November
2003, <https://www.rfc-editor.org/info/rfc3629>. 2003, <https://www.rfc-editor.org/info/rfc3629>.
[RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
skipping to change at page 41, line 33 skipping to change at page 46, line 33
[RFC4287] Nottingham, M., Ed. and R. Sayre, Ed., "The Atom [RFC4287] Nottingham, M., Ed. and R. Sayre, Ed., "The Atom
Syndication Format", RFC 4287, DOI 10.17487/RFC4287, Syndication Format", RFC 4287, DOI 10.17487/RFC4287,
December 2005, <https://www.rfc-editor.org/info/rfc4287>. December 2005, <https://www.rfc-editor.org/info/rfc4287>.
[RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data
Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006,
<https://www.rfc-editor.org/info/rfc4648>. <https://www.rfc-editor.org/info/rfc4648>.
[RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an
IANA Considerations Section in RFCs", RFC 5226, IANA Considerations Section in RFCs", RFC 5226,
DOI 10.17487/RFC5226, May 2008, <https://www.rfc- DOI 10.17487/RFC5226, May 2008,
editor.org/info/rfc5226>. <https://www.rfc-editor.org/info/rfc5226>.
[TIME_T] The Open Group Base Specifications, "Vol. 1: Base [TIME_T] The Open Group Base Specifications, "Vol. 1: Base
Definitions, Issue 7", Section 4.15 'Seconds Since the Definitions, Issue 7", Section 4.15 'Seconds Since the
Epoch', IEEE Std 1003.1, 2013 Edition, 2013, Epoch', IEEE Std 1003.1, 2013 Edition, 2013,
<http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/ <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/
V1_chap04.html#tag_04_15>. V1_chap04.html#tag_04_15>.
10.2. Informative References 11.2. Informative References
[ASN.1] International Telecommunication Union, "Information [ASN.1] International Telecommunication Union, "Information
Technology -- ASN.1 encoding rules: Specification of Basic Technology -- ASN.1 encoding rules: Specification of Basic
Encoding Rules (BER), Canonical Encoding Rules (CER) and Encoding Rules (BER), Canonical Encoding Rules (CER) and
Distinguished Encoding Rules (DER)", ITU-T Recommendation Distinguished Encoding Rules (DER)", ITU-T Recommendation
X.690, 1994. X.690, 1994.
[BSON] Various, "BSON - Binary JSON", 2013, [BSON] Various, "BSON - Binary JSON", 2013,
<http://bsonspec.org/>. <http://bsonspec.org/>.
skipping to change at page 42, line 17 skipping to change at page 47, line 17
[RFC0713] Haverty, J., "MSDTP-Message Services Data Transmission [RFC0713] Haverty, J., "MSDTP-Message Services Data Transmission
Protocol", RFC 713, DOI 10.17487/RFC0713, April 1976, Protocol", RFC 713, DOI 10.17487/RFC0713, April 1976,
<https://www.rfc-editor.org/info/rfc713>. <https://www.rfc-editor.org/info/rfc713>.
[RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type
Specifications and Registration Procedures", BCP 13, Specifications and Registration Procedures", BCP 13,
RFC 6838, DOI 10.17487/RFC6838, January 2013, RFC 6838, DOI 10.17487/RFC6838, January 2013,
<https://www.rfc-editor.org/info/rfc6838>. <https://www.rfc-editor.org/info/rfc6838>.
[RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object
Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049,
October 2013, <https://www.rfc-editor.org/info/rfc7049>.
[RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data [RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data
Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March
2014, <https://www.rfc-editor.org/info/rfc7159>. 2014, <https://www.rfc-editor.org/info/rfc7159>.
[RFC7228] Bormann, C., Ersue, M., and A. Keranen, "Terminology for [RFC7228] Bormann, C., Ersue, M., and A. Keranen, "Terminology for
Constrained-Node Networks", RFC 7228, Constrained-Node Networks", RFC 7228,
DOI 10.17487/RFC7228, May 2014, <https://www.rfc- DOI 10.17487/RFC7228, May 2014,
editor.org/info/rfc7228>. <https://www.rfc-editor.org/info/rfc7228>.
[UBJSON] The Buzz Media, "Universal Binary JSON Specification", [UBJSON] The Buzz Media, "Universal Binary JSON Specification",
2013, <http://ubjson.org/>. 2013, <http://ubjson.org/>.
[YAML] Ben-Kiki, O., Evans, C., and I. Net, "YAML Ain't Markup [YAML] Ben-Kiki, O., Evans, C., and I. Net, "YAML Ain't Markup
Language (YAML[TM]) Version 1.2", 3rd Edition, October Language (YAML[TM]) Version 1.2", 3rd Edition, October
2009, <http://www.yaml.org/spec/1.2/spec.html>. 2009, <http://www.yaml.org/spec/1.2/spec.html>.
Appendix A. Examples Appendix A. Examples
skipping to change at page 49, line 16 skipping to change at page 54, line 16
| 0xba | map (four-byte uint32_t for n, and then n pairs of | | 0xba | map (four-byte uint32_t for n, and then n pairs of |
| | data items follow) | | | data items follow) |
| | | | | |
| 0xbb | map (eight-byte uint64_t for n, and then n pairs of | | 0xbb | map (eight-byte uint64_t for n, and then n pairs of |
| | data items follow) | | | data items follow) |
| | | | | |
| 0xbf | map, pairs of data items follow, terminated by | | 0xbf | map, pairs of data items follow, terminated by |
| | "break" | | | "break" |
| | | | | |
| 0xc0 | Text-based date/time (data item follows; see | | 0xc0 | Text-based date/time (data item follows; see |
| | Section 2.4.1) | | | Section 3.4.1) |
| | | | | |
| 0xc1 | Epoch-based date/time (data item follows; see | | 0xc1 | Epoch-based date/time (data item follows; see |
| | Section 2.4.1) | | | Section 3.4.1) |
| | | | | |
| 0xc2 | Positive bignum (data item "byte string" follows) | | 0xc2 | Positive bignum (data item "byte string" follows) |
| | | | | |
| 0xc3 | Negative bignum (data item "byte string" follows) | | 0xc3 | Negative bignum (data item "byte string" follows) |
| | | | | |
| 0xc4 | Decimal Fraction (data item "array" follows; see | | 0xc4 | Decimal Fraction (data item "array" follows; see |
| | Section 2.4.3) | | | Section 3.4.3) |
| | | | | |
| 0xc5 | Bigfloat (data item "array" follows; see | | 0xc5 | Bigfloat (data item "array" follows; see |
| | Section 2.4.3) | | | Section 3.4.3) |
| | | | | |
| 0xc6..0xd4 | (tagged item) | | 0xc6..0xd4 | (tagged item) |
| | | | | |
| 0xd5..0xd7 | Expected Conversion (data item follows; see | | 0xd5..0xd7 | Expected Conversion (data item follows; see |
| | Section 2.4.4.2) | | | Section 3.4.4.2) |
| | | | | |
| 0xd8..0xdb | (more tagged items, 1/2/4/8 bytes and then a data | | 0xd8..0xdb | (more tagged items, 1/2/4/8 bytes and then a data |
| | item follow) | | | item follow) |
| | | | | |
| 0xe0..0xf3 | (simple value) | | 0xe0..0xf3 | (simple value) |
| | | | | |
| 0xf4 | False | | 0xf4 | False |
| | | | | |
| 0xf5 | True | | 0xf5 | True |
| | | | | |
 End of changes. 130 change blocks. 
230 lines changed or deleted 460 lines changed or added

This html diff was produced by rfcdiff 1.46. The latest version is available from http://tools.ietf.org/tools/rfcdiff/