--- 1/draft-ietf-cbor-7049bis-04.txt 2019-01-15 15:13:17.489823847 -0800 +++ 2/draft-ietf-cbor-7049bis-05.txt 2019-01-15 15:13:17.621827061 -0800 @@ -1,19 +1,19 @@ Network Working Group C. Bormann Internet-Draft Universitaet Bremen TZI Intended status: Standards Track P. Hoffman -Expires: April 26, 2019 ICANN - October 23, 2018 +Expires: July 19, 2019 ICANN + January 15, 2019 Concise Binary Object Representation (CBOR) - draft-ietf-cbor-7049bis-04 + draft-ietf-cbor-7049bis-05 Abstract The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. These design goals make it different from earlier binary serializations such as ASN.1 and MessagePack. Contributing @@ -36,97 +36,97 @@ Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at https://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." - This Internet-Draft will expire on April 26, 2019. + This Internet-Draft will expire on July 19, 2019. Copyright Notice - Copyright (c) 2018 IETF Trust and the persons identified as the + Copyright (c) 2019 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Table of Contents - 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 + 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 1.1. Objectives . . . . . . . . . . . . . . . . . . . . . . . 4 - 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 5 + 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 2. CBOR Data Models . . . . . . . . . . . . . . . . . . . . . . 7 2.1. Extended Generic Data Models . . . . . . . . . . . . . . 8 - 2.2. Specific Data Models . . . . . . . . . . . . . . . . . . 8 + 2.2. Specific Data Models . . . . . . . . . . . . . . . . . . 9 3. Specification of the CBOR Encoding . . . . . . . . . . . . . 9 3.1. Major Types . . . . . . . . . . . . . . . . . . . . . . . 10 - 3.2. Indefinite Lengths for Some Major Types . . . . . . . . . 11 - 3.2.1. Indefinite-Length Arrays and Maps . . . . . . . . . . 12 - 3.2.2. Indefinite-Length Byte Strings and Text Strings . . . 14 + 3.2. Indefinite Lengths for Some Major Types . . . . . . . . . 12 + 3.2.1. The "break" Stop Code . . . . . . . . . . . . . . . . 12 + 3.2.2. Indefinite-Length Arrays and Maps . . . . . . . . . . 12 + 3.2.3. Indefinite-Length Byte Strings and Text Strings . . . 14 3.3. Floating-Point Numbers and Values with No Content . . . . 15 3.4. Optional Tagging of Items . . . . . . . . . . . . . . . . 16 3.4.1. Date and Time . . . . . . . . . . . . . . . . . . . . 18 3.4.2. Standard Date/Time String . . . . . . . . . . . . . . 18 3.4.3. Epoch-based Date/Time . . . . . . . . . . . . . . . . 18 3.4.4. Bignums . . . . . . . . . . . . . . . . . . . . . . . 19 3.4.5. Decimal Fractions and Bigfloats . . . . . . . . . . . 20 3.4.6. Content Hints . . . . . . . . . . . . . . . . . . . . 21 3.4.6.1. Encoded CBOR Data Item . . . . . . . . . . . . . 21 3.4.6.2. Expected Later Encoding for CBOR-to-JSON - Converters . . . . . . . . . . . . . . . . . . . 21 + Converters . . . . . . . . . . . . . . . . . . . 22 3.4.6.3. Encoded Text . . . . . . . . . . . . . . . . . . 22 - 3.4.7. Self-Describe CBOR . . . . . . . . . . . . . . . . . 22 + 3.4.7. Self-Described CBOR . . . . . . . . . . . . . . . . . 23 4. Creating CBOR-Based Protocols . . . . . . . . . . . . . . . . 23 4.1. CBOR in Streaming Applications . . . . . . . . . . . . . 24 4.2. Generic Encoders and Decoders . . . . . . . . . . . . . . 24 4.3. Syntax Errors . . . . . . . . . . . . . . . . . . . . . . 25 4.3.1. Incomplete CBOR Data Items . . . . . . . . . . . . . 25 - 4.3.2. Malformed Indefinite-Length Items . . . . . . . . . . 25 + 4.3.2. Malformed Indefinite-Length Items . . . . . . . . . . 26 4.3.3. Unknown Additional Information Values . . . . . . . . 26 - 4.4. Other Decoding Errors . . . . . . . . . . . . . . . . . . 26 4.5. Handling Unknown Simple Values and Tags . . . . . . . . . 27 4.6. Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.7. Specifying Keys for Maps . . . . . . . . . . . . . . . . 28 4.7.1. Equivalence of Keys . . . . . . . . . . . . . . . . . 29 4.8. Undefined Values . . . . . . . . . . . . . . . . . . . . 30 4.9. Preferred Serialization . . . . . . . . . . . . . . . . . 30 - 4.10. Canonical CBOR . . . . . . . . . . . . . . . . . . . . . 31 + 4.10. Canonically Encoded CBOR . . . . . . . . . . . . . . . . 31 4.10.1. Length-first map key ordering . . . . . . . . . . . 33 - 4.11. Strict Mode . . . . . . . . . . . . . . . . . . . . . . . 34 + 4.11. Strict Decoding Mode . . . . . . . . . . . . . . . . . . 34 5. Converting Data between CBOR and JSON . . . . . . . . . . . . 35 - 5.1. Converting from CBOR to JSON . . . . . . . . . . . . . . 35 + 5.1. Converting from CBOR to JSON . . . . . . . . . . . . . . 36 5.2. Converting from JSON to CBOR . . . . . . . . . . . . . . 37 - 6. Future Evolution of CBOR . . . . . . . . . . . . . . . . . . 37 + 6. Future Evolution of CBOR . . . . . . . . . . . . . . . . . . 38 6.1. Extension Points . . . . . . . . . . . . . . . . . . . . 38 6.2. Curating the Additional Information Space . . . . . . . . 39 7. Diagnostic Notation . . . . . . . . . . . . . . . . . . . . . 39 7.1. Encoding Indicators . . . . . . . . . . . . . . . . . . . 40 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 41 8.1. Simple Values Registry . . . . . . . . . . . . . . . . . 41 - 8.2. Tags Registry . . . . . . . . . . . . . . . . . . . . . . 41 + 8.2. Tags Registry . . . . . . . . . . . . . . . . . . . . . . 42 8.3. Media Type ("MIME Type") . . . . . . . . . . . . . . . . 42 - 8.4. CoAP Content-Format . . . . . . . . . . . . . . . . . . . 42 + 8.4. CoAP Content-Format . . . . . . . . . . . . . . . . . . . 43 8.5. The +cbor Structured Syntax Suffix Registration . . . . . 43 9. Security Considerations . . . . . . . . . . . . . . . . . . . 44 - 10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 44 + 10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 45 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 45 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 Objectives . . . . . . . . . . . . . . . . . . . . . 58 E.1. ASN.1 DER, BER, and PER . . . . . . . . . . . . . . . . . 59 @@ -422,21 +422,21 @@ The meaning of this argument depends on the major type. For example, in major type 0, the argument is the value of the data item itself (and in major type 1 the value of the data item is computed from the argument); in major type 2 and 3 it gives the length of the string data in bytes that follows; and in major types 4 and 5 it is used to determine the number of data items enclosed. If the encoded sequence of bytes ends before the end of a data item would be reached, that encoding is not well-formed. If the encoded sequence of bytes still has bytes remaining after the outermost - encoded item is parsed, that encoding is not a single well-formed + encoded item is decoded, that encoding is not a single well-formed CBOR item. 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 constrained implementation can instead use the structure of the initial byte and following bytes for more compact code (see Appendix C for a rough impression of how this could look). 3.1. Major Types @@ -518,45 +518,48 @@ Four CBOR items (arrays, maps, byte strings, and text strings) can be encoded with an indefinite length using additional information value 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 string, is known. (The application of this is often referred to as "streaming" within a data item.) Indefinite-length arrays and maps are dealt with differently than indefinite-length byte strings and text strings. -3.2.1. Indefinite-Length Arrays and Maps +3.2.1. The "break" Stop Code - Indefinite-length arrays and maps are simply opened without - indicating the number of data items that will be included in the - array or map, using the additional information value of 31. 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 - 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 - have been included. The "break" is encoded with major type 7 and - additional information value 31 (0b111_11111) but is not itself a - data item: it is just a syntactic feature to close the array or map. - That is, the "break" stop code comes after the last item in the array - or map, and it cannot occur anywhere else in place of a data item. - In this way, indefinite-length arrays and maps look identical to + The "break" stop code is encoded with major type 7 and additional + information value 31 (0b111_11111). It is not itself a data item: it + is just a syntactic feature to close an indefinite-length item. + + If the "break" stop code appears anywhere where a data item is + expected, other than directly inside an indefinite-length string, + array, or map -- for example directly inside a definite-length array + or map -- the enclosing item is not well-formed. + +3.2.2. Indefinite-Length Arrays and Maps + + Indefinite-length arrays and maps are represented using their major + type with the additional information value of 31, followed by an + arbitrary-length sequence of items for an array or key/value pairs + for a map, followed by the "break" stop code (Section 3.2.1). In + other words, indefinite-length arrays and maps look identical to other arrays and maps except for beginning with the additional - information value 31 and ending with the "break" stop code. + information value of 31 and ending with the "break" stop code. - Arrays and maps with indefinite lengths allow any number of items - (for arrays) and key/value pairs (for maps) to be given before the - "break" stop code. There is no restriction against nesting - indefinite-length array or map items. A "break" only terminates a - single item, so nested indefinite-length items need exactly as many - "break" stop codes as there are type bytes starting an indefinite- - length item. + If the break stop code appears after a key in a map, in place of that + key's value, the map is not well-formed. + + There is no restriction against nesting indefinite-length array or + map items. A "break" only terminates a single item, so nested + indefinite-length items need exactly as many "break" stop codes as + there are type bytes starting an indefinite-length item. For example, assume an encoder wants to represent the abstract array [1, [2, 3], [4, 5]]. The definite-length encoding would be 0x8301820203820405: 83 -- Array of length 3 01 -- 1 82 -- Array of length 2 02 -- 2 03 -- 3 @@ -619,47 +622,43 @@ 0xbf6346756ef563416d7421ff BF -- Start indefinite-length map 63 -- First key, UTF-8 string length 3 46756e -- "Fun" F5 -- First value, true 63 -- Second key, UTF-8 string length 3 416d74 -- "Amt" 21 -- Second value, -2 FF -- "break" -3.2.2. Indefinite-Length Byte Strings and Text Strings +3.2.3. Indefinite-Length Byte Strings and Text Strings - Indefinite-length byte strings and text strings are actually a - concatenation of zero or more definite-length byte or text strings - ("chunks") that are together treated as one contiguous string. - Indefinite-length strings are opened with the major type and - additional information value of 31, but what follows are a series of - byte or text strings that have definite lengths (the chunks). The - 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 - would occur. The contents of the chunks are concatenated together, - and the overall length of the indefinite-length string will be the - sum of the lengths of all of the chunks. In summary, an indefinite- - length string is encoded similarly to how an indefinite-length array - of its chunks would be encoded, except that the major type of the - indefinite-length string is that of a (text or byte) string and - matches the major types of its chunks. + Indefinite-length strings are represented by a byte containing the + major type and additional information value of 31, followed by a + series of byte or text strings ("chunks") that have definite lengths, + followed by the "break" stop code (Section 3.2.1). The data item + represented by the indefinite-length string is the concatenation of + the chunks. - For indefinite-length byte strings, every data item (chunk) between - the indefinite-length indicator and the "break" MUST be a definite- - length byte string item; if the parser sees any item type other than - a byte string before it sees the "break", it is an error. + If any item between the indefinite-length string indicator + (0b010_11111 or 0b011_11111) and the "break" stop code is not a + definite-length string item of the same major type, the string is not + well-formed. + + If any definite-length text string inside an indefinite-length text + string is invalid, the indefinite-length text string is invalid. + Note that this implies that the bytes of a single UTF-8 character + cannot be spread between chunks: a new chunk can only be started at a + character boundary. For example, assume the sequence: 0b010_11111 0b010_00100 0xaabbccdd 0b010_00011 0xeeff99 0b111_11111 - 5F -- Start indefinite-length byte string 44 -- Byte string of length 4 aabbccdd -- Bytes content 43 -- Byte string of length 3 eeff99 -- Bytes content FF -- "break" After decoding, this results in a single byte string with seven bytes: 0xaabbccddeeff99. @@ -656,52 +655,48 @@ 5F -- Start indefinite-length byte string 44 -- Byte string of length 4 aabbccdd -- Bytes content 43 -- Byte string of length 3 eeff99 -- Bytes content FF -- "break" After decoding, this results in a single byte string with seven bytes: 0xaabbccddeeff99. - Text strings with indefinite lengths act the same as byte strings - with indefinite lengths, except that all their chunks MUST be - definite-length text strings. Note that this implies that the bytes - of a single UTF-8 character cannot be spread between chunks: a new - chunk can only be started at a character boundary. - 3.3. Floating-Point Numbers and Values with No Content 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 5-bit additional information in the initial byte has its own separate meaning, as defined in Table 1. Like the major types for integers, items of this major type do not carry content data; all the information is in the initial bytes. - +-------------+--------------------------------------------------+ - | 5-Bit Value | Semantics | - +-------------+--------------------------------------------------+ + +------------+------------------------------------------------------+ + | 5-Bit | Semantics | + | Value | | + +------------+------------------------------------------------------+ | 0..23 | Simple value (value 0..23) | | | | | 24 | Simple value (value 32..255 in following byte) | | | | | 25 | IEEE 754 Half-Precision Float (16 bits follow) | | | | | 26 | IEEE 754 Single-Precision Float (32 bits follow) | | | | | 27 | IEEE 754 Double-Precision Float (64 bits follow) | | | | | 28-30 | (Unassigned) | | | | | 31 | "break" stop code for indefinite-length items | - +-------------+--------------------------------------------------+ + | | (Section 3.2.1) | + +------------+------------------------------------------------------+ Table 1: Values for Additional Information in Major Type 7 As with all other major types, the 5-bit value 24 signifies a single- byte extension: it is followed by an additional byte to represent the simple value. (To minimize confusion, only the values 32 to 255 are used.) This maintains the structure of the initial bytes: as for the other major types, the length of these always depends on the additional information in the first byte. Table 2 lists the values assigned and available for simple types. @@ -719,33 +714,33 @@ | | | | 23 | Undefined value | | | | | 24..31 | (Reserved) | | | | | 32..255 | (Unassigned) | +---------+-----------------+ Table 2: Simple Values - The 5-bit values of 25, 26, and 27 are for 16-bit, 32-bit, and 64-bit - IEEE 754 binary floating-point values [IEEE.754.2008]. These - floating-point values are encoded in the additional bytes of the - appropriate size. (See Appendix D for some information about 16-bit - floating point.) - 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 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 treat these two-byte sequences as an error. Similar prohibitions apply to the unassigned simple values as well. + The 5-bit values of 25, 26, and 27 are for 16-bit, 32-bit, and 64-bit + IEEE 754 binary floating-point values [IEEE.754.2008]. These + floating-point values are encoded in the additional bytes of the + appropriate size. (See Appendix D for some information about 16-bit + floating point.) + 3.4. Optional Tagging of Items 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 type 6, and represents an integer number as indicated by the tag's argument (Section 3); the (sole) data item is carried as content data. If a tag requires structured data, this structure is encoded into the nested data item. The definition of a tag usually restricts what kinds of nested data item or items are valid. @@ -776,64 +771,64 @@ value. The content of the tagged item is the data item (the value) that is being tagged. 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 rest of this section. +-----------+--------------+----------------------------------------+ | Tag | Data Item | Semantics | +-----------+--------------+----------------------------------------+ - | 0 | UTF-8 string | Standard date/time string; see Section | - | | | 3.4.2 | + | 0 | UTF-8 string | Standard date/time string; see | + | | | Section 3.4.2 | | | | | - | 1 | multiple | Epoch-based date/time; see Section | - | | | 3.4.3 | + | 1 | multiple | Epoch-based date/time; see | + | | | Section 3.4.3 | | | | | | 2 | byte string | Positive bignum; see Section 3.4.4 | | | | | | 3 | byte string | Negative bignum; see Section 3.4.4 | | | | | | 4 | array | Decimal fraction; see Section 3.4.5 | | | | | | 5 | array | Bigfloat; see Section 3.4.5 | | | | | | 6..20 | (Unassigned) | (Unassigned) | | | | | | 21 | multiple | Expected conversion to base64url | | | | encoding; see Section 3.4.6.2 | | | | | | 22 | multiple | Expected conversion to base64 | | | | encoding; see Section 3.4.6.2 | | | | | | 23 | multiple | Expected conversion to base16 | | | | encoding; see Section 3.4.6.2 | | | | | - | 24 | byte string | Encoded CBOR data item; see Section | - | | | 3.4.6.1 | + | 24 | byte string | Encoded CBOR data item; see | + | | | Section 3.4.6.1 | | | | | | 25..31 | (Unassigned) | (Unassigned) | | | | | | 32 | UTF-8 string | URI; see Section 3.4.6.3 | | | | | | 33 | UTF-8 string | base64url; see Section 3.4.6.3 | | | | | | 34 | UTF-8 string | base64; see Section 3.4.6.3 | | | | | - | 35 | UTF-8 string | Regular expression; see Section | - | | | 3.4.6.3 | + | 35 | UTF-8 string | Regular expression; see | + | | | Section 3.4.6.3 | | | | | | 36 | UTF-8 string | MIME message; see Section 3.4.6.3 | | | | | | 37..55798 | (Unassigned) | (Unassigned) | | | | | - | 55799 | multiple | Self-describe CBOR; see Section 3.4.7 | + | 55799 | multiple | Self-described CBOR; see Section 3.4.7 | | | | | | 55800+ | (Unassigned) | (Unassigned) | +-----------+--------------+----------------------------------------+ Table 3: Values for Tags 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. @@ -858,42 +853,54 @@ known as UNIX Epoch time. Note that leap seconds are handled specially by POSIX time and this results in a 1 second discontinuity several times per decade.) Note that applications that require the expression of times beyond early 2106 cannot leave out support of 64-bit integers for the tagged value. Negative values (major type 1 and negative floating-point numbers) are interpreted as determined by the application requirements as there is no universal standard for UTC count-of-seconds time before 1970-01-01T00:00Z (this is particularly true for points in time that - precede discontinuities in national calendars). + precede discontinuities in national calendars). The same applies to + non-finite values. To indicate fractional seconds, floating point values can be used within Tag 1 instead of integer values. Note that this generally requires binary64 support, as binary16 and binary32 provide non-zero fractions of seconds only for a short period of time around early 1970. An application that requires Tag 1 support may restrict the tagged value to be an integer (or a floating-point value) only. 3.4.4. Bignums Protocols using tag values 2 and 3 extend the generic data model - (Section 2) with "bignums" representing arbitrary integers. In the - generic data model, bignum values are not equal to integers from the - basic data model, but specific data models can define that - equivalence. + (Section 2) with "bignums" representing arbitrarily sized integers. + In the generic data model, bignum values are not equal to integers + from the basic data model, but specific data models can define that + equivalence, and preferred encoding never makes use of bignums that + also can be expressed as basic integers (see below). 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. + is -1 - n. The preferred encoding of the byte string is to leave out + any leading zeroes (note that this means the preferred encoding for + n = 0 is the empty byte string, but see below). Decoders that + understand these tags MUST be able to decode bignums that do have + leading zeroes. The preferred encoding of an integer that can be + represented using major type 0 or 1 is to encode it this way instead + of as a bignum (which means that the empty string never occurs in a + bignum when using preferred encoding). Note that this means the non- + preferred choice of a bignum representation instead of a basic + integer for encoding a number is not intended to have application + semantics (just as the choice of a longer basic integer + representation than needed, such as 0x1800 for 0x00 does not). For example, the number 18446744073709551616 (2**64) is represented as 0b110_00010 (major type 6, tag 2), followed by 0b010_01001 (major type 2, length 9), followed by 0x010000000000000000 (one byte 0x01 and eight bytes 0x00). In hexadecimal: C2 -- Tag 2 49 -- Byte string of length 9 010000000000000000 -- Bytes content @@ -969,47 +976,51 @@ 3.4.6. Content Hints The tags in this section are for content hints that might be used by generic CBOR processors. These content hints do not extend the generic data model. 3.4.6.1. Encoded CBOR Data Item 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 - 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. + item is being decoded. Tag 24 (CBOR data item) can be used to tag + the embedded byte string as a data item encoded in CBOR format. 3.4.6.2. Expected Later Encoding for CBOR-to-JSON Converters Tags 21 to 23 indicate that a byte string might require a specific encoding when interoperating with a text-based representation. These 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 usage. That usage specifies that some strings are encoded as base64, base64url, and so on. The encoder uses byte strings instead of doing 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 not the converter will be generic, and therefore wants to say what it believes is the proper way to convert binary strings to JSON. The data item tagged can be a byte string or any other data item. In the latter case, the tag applies to all of the byte string data items contained in the data item, except for those contained in a nested data item tagged with an expected conversion. These three tag types suggest conversions to three of the base data - encodings defined in [RFC4648]. For base64url encoding, padding is - not used (see Section 3.2 of RFC 4648); that is, all trailing equals - signs ("=") are removed from the base64url-encoded string. Later - tags might be defined for other data encodings of RFC 4648 or for - other ways to encode binary data in strings. + encodings defined in [RFC4648]. For base64url encoding (tag 21), + padding is not used (see Section 3.2 of RFC 4648); that is, all + trailing equals signs ("=") are removed from the encoded string. For + base64 encoding (tag 22), padding is used as defined in RFC 4648. + For both base64url and base64, padding bits are set to zero (see + Section 3.5 of RFC 4648), and encoding is performed without the + inclusion of any line breaks, whitespace, or other additional + characters. Note that, for all three tags, the encoding of the empty + byte string is the empty text string. 3.4.6.3. Encoded Text Some text strings hold data that have formats widely used on the Internet, and sometimes those formats can be validated and presented to the application in appropriate form by the decoder. There are tags for some of these formats. o Tag 32 is for URIs, as defined in [RFC3986]; @@ -1024,42 +1035,42 @@ expression, or more than just the text of the regular expression itself, need to be conveyed.) o Tag 36 is for MIME messages (including all headers), as defined in [RFC2045]; 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 string form for the latter. -3.4.7. Self-Describe CBOR +3.4.7. Self-Described CBOR In many applications, it will be clear from the context that CBOR is being employed for encoding a data item. For instance, a specific protocol might specify the use of CBOR, or a media type is indicated that specifies its use. However, there may be applications where 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 may help to have some distinguishing characteristics for the data itself. Tag 55799 is defined for this purpose. It does not impart any special semantics on the data item that follows; that is, the semantics of a data item tagged with tag 55799 is exactly identical to the semantics of the data item itself. The serialization of this tag is 0xd9d9f7, which appears not to be 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 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 decode both CBOR and JSON. Such a decoder would need to mechanically distinguish the two 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 will never be found at the beginning of a JSON text. 4. Creating CBOR-Based Protocols 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 need any included or assumed schema: a decoder can take a CBOR item @@ -1144,22 +1155,22 @@ generally can choose to completely fail the decoding (issue an error and/or stop processing altogether), substitute the problematic data and data items using a decoder-specific convention that clearly indicates there has been a problem, or take some other action. 4.3.1. Incomplete CBOR Data Items The representation of a CBOR data item has a specific length, determined by its initial bytes and by the structure of any data items enclosed in the data items. If less data is available, this - 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 + can be treated as a syntax error. A decoder may also decode + incrementally, that is, decode the data item as far as it is available and present the data found so far (such as in an event- based interface), with the option of continuing the decoding once further data is available. Examples of incomplete data items include: o A decoder expects a certain number of array or map entries but instead encounters the end of the data. o A decoder processes what it expects to be the last pair in a map @@ -1187,21 +1198,21 @@ where there is no immediately enclosing (unclosed) indefinite-length item. 4.3.3. Unknown Additional Information Values At the time of writing, some additional information values are unassigned and reserved for future versions of this document (see Section 6.2). Since the overall syntax for these additional information values is not yet defined, a decoder that sees an additional information value that it does not understand cannot - continue parsing. + continue decoding. 4.4. Other Decoding Errors A CBOR data item may be syntactically well-formed but present a problem with interpreting the data encoded in it in the CBOR data model. Generally speaking, a decoder that finds a data item with such a problem might issue a warning, might stop processing altogether, might handle the error and make the problematic value available to the application as such, or take some other type of action. @@ -1427,21 +1437,21 @@ by definition variation-tolerant; the distinction is only relevant if a constrained implementation of a CBOR decoder meets a variant encoder. The preferred serialization always uses the shortest form of representing the argument (Section 3)); it also uses the shortest floating point encoding that preserves the value being encoded (see Section 4.6). Definite length encoding is preferred whenever the length is known at the time the serialization of the item starts. -4.10. Canonical CBOR +4.10. Canonically Encoded CBOR Some protocols may want encoders to only emit CBOR in a particular canonical format; those protocols might also have the decoders check that their input is canonical. Those protocols are free to define what they mean by a canonical format and what encoders and decoders are expected to do. This section defines a set of restrictions that can serve as the base of such a canonical format. A CBOR encoding satisfies the "core canonicalization requirements" if it satisfies the following restrictions: @@ -1569,21 +1579,21 @@ 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.11. Strict Mode +4.11. Strict Decoding Mode Some areas of application of CBOR do not require canonicalization (Section 4.10) but may require that different decoders reach the same (semantically equivalent) results, even in the presence of potentially malicious data. This can be required if one application (such as a firewall or other protecting entity) makes a decision based on the data that another application, which independently decodes the data, relies on. Normally, it is the responsibility of the sender to avoid ambiguously @@ -1800,21 +1810,21 @@ part of the codepoint space has been allocated, and the space is abundant (although the early numbers are more efficient than the later ones). Implementations receiving an unknown tag can choose to simply ignore it or to process it as an unknown tag wrapping the following data item. The IANA registry in Section 8.2 is the appropriate way to address the extensibility of this codepoint space. o the "additional information" space. An implementation receiving an unknown additional information value has no way to continue - parsing, so allocating codepoints to this space is a major step. + decoding, so allocating codepoints to this space is a major step. There are also very few codepoints left. 6.2. Curating the Additional Information Space The human mind is sometimes drawn to filling in little perceived gaps to make something neat. We expect the remaining gaps in the codepoint space for the additional information values to be an attractor for new ideas, just because they are there. The present specification does not manage the additional information @@ -2050,31 +2061,28 @@ vulnerabilities by reducing parser complexity, by giving the entire range of encodable values a meaning where possible. Resource exhaustion attacks might attempt to lure a decoder into allocating very big data items (strings, arrays, maps) or exhaust the stack depth by setting up deeply nested items. Decoders need to have appropriate resource management to mitigate these attacks. (Items for which very large sizes are given can also attempt to exploit integer overflow vulnerabilities.) - Applications where a CBOR data item is examined by a gatekeeper - function and later used by a different application may exhibit - vulnerabilities when multiple interpretations of the data item are - possible. For example, an attacker could make use of duplicate keys - in maps and precision issues in numbers to make the gatekeeper base - its decisions on a different interpretation than the one that will be - used by the second application. Protocols that are used in a - security context should be defined in such a way that these multiple - interpretations are reliably reduced to a single one. To facilitate - this, encoder and decoder implementations used in such contexts - should provide at least one strict mode of operation (Section 4.11). + Protocols that are used in a security context should be defined in + such a way that potential multiple interpretations are reliably + reduced to a single one. For example, an attacker could make use of + duplicate keys in maps or precision issues in numbers to make one + decoder base its decisions on a different interpretation than the one + that will be used by a second decoder. To facilitate this, encoder + and decoder implementations used in such contexts should provide at + least one strict mode of operation (Section 4.11). 10. Acknowledgements CBOR was inspired by MessagePack. MessagePack was developed and promoted by Sadayuki Furuhashi ("frsyuki"). This reference to MessagePack is solely for attribution; CBOR is not intended as a version of or replacement for MessagePack, as it has different design goals and requirements. The need for functionality beyond the original MessagePack @@ -2488,40 +2496,40 @@ | | | | 0xba | map (four-byte uint32_t for n, and then n pairs of | | | data items follow) | | | | | 0xbb | map (eight-byte uint64_t for n, and then n pairs of | | | data items follow) | | | | | 0xbf | map, pairs of data items follow, terminated by | | | "break" | | | | - | 0xc0 | Text-based date/time (data item follows; see Section | - | | 3.4.2) | + | 0xc0 | Text-based date/time (data item follows; see | + | | Section 3.4.2) | | | | | 0xc1 | Epoch-based date/time (data item follows; see | | | Section 3.4.3) | | | | | 0xc2 | Positive bignum (data item "byte string" follows) | | | | | 0xc3 | Negative bignum (data item "byte string" follows) | | | | | 0xc4 | Decimal Fraction (data item "array" follows; see | | | Section 3.4.5) | | | | - | 0xc5 | Bigfloat (data item "array" follows; see Section | - | | 3.4.5) | + | 0xc5 | Bigfloat (data item "array" follows; see | + | | Section 3.4.5) | | | | | 0xc6..0xd4 | (tagged item) | | | | - | 0xd5..0xd7 | Expected Conversion (data item follows; see Section | - | | 3.4.6.2) | + | 0xd5..0xd7 | Expected Conversion (data item follows; see | + | | Section 3.4.6.2) | | | | | 0xd8..0xdb | (more tagged items, 1/2/4/8 bytes and then a data | | | item follow) | | | | | 0xe0..0xf3 | (simple value) | | | | | 0xf4 | False | | | | | 0xf5 | True | | | | @@ -2603,21 +2611,21 @@ return -1; // signal break out else fail(); // no enclosing indefinite default: fail(); // wrong mt } return 0; // no break out } Figure 1: Pseudocode for Well-Formedness Check Note that the remaining complexity of a complete CBOR decoder is - about presenting data that has been parsed to the application in an + about presenting data that has been decoded to the application in an appropriate form. Major types 0 and 1 are designed in such a way that they can be encoded in C from a signed integer without actually doing an if-then- else for positive/negative (Figure 2). This uses the fact that (-1-n), the transformation for major type 1, is the same as ~n (bitwise complement) in C unsigned arithmetic; ~n can then be expressed as (-1)^n for the negative case, while 0^n leaves n unchanged for non-negative. The sign of a number can be converted to -1 for negative and 0 for non-negative (0 or positive) by arithmetic- @@ -2797,21 +2805,21 @@ +-------------+--------------------------+--------------------------+ Table 6: Examples for Different Levels of Conciseness Appendix F. Changes from RFC 7049 The following is a list of known changes from RFC 7049. This list is non-authoritative. It is meant to help reviewers see the significant differences. - o Updated reference for [RFC4267] to [RFC8259] in many places + o Updated reference for [RFC4627] to [RFC8259] in many places o Updated reference for [CNN-TERMS] to [RFC7228] o Added a comment to the last example in Section 2.2.1 (added "Second value") o Fixed a bug in the example in Section 2.4.2 ("29" -> "49") o Fixed a bug in the last paragraph of Section 3.6 ("0b000_11101" -> "0b000_11001")