CINXE.COM
Information technology - Programming languages - C
<?xml version='1.0' encoding='utf-8'?> <rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="std" consensus="true" docName="draft-ietf-cbor-7049bis-16" indexInclude="true" ipr="trust200902" number="8949" obsoletes="7049" prepTime="2020-12-04T16:27:22" scripts="Common,Greek,Han,Latin" sortRefs="true" submissionType="IETF" symRefs="true" tocDepth="4" tocInclude="true" xml:lang="en"> <link href="https://datatracker.ietf.org/doc/draft-ietf-cbor-7049bis-16" rel="prev"/> <link href="https://dx.doi.org/10.17487/rfc8949" rel="alternate"/> <link href="urn:issn:2070-1721" rel="alternate"/> <front> <title abbrev="CBOR">Concise Binary Object Representation (CBOR)</title> <seriesInfo name="RFC" value="8949" stream="IETF"/> <seriesInfo name="STD" value="94" stream="IETF"/> <author initials="C." surname="Bormann" fullname="Carsten Bormann"> <organization showOnFrontPage="true">Universität Bremen TZI</organization> <address> <postal> <street>Postfach 330440</street> <city>Bremen</city> <code>D-28359</code> <country>Germany</country> </postal> <phone>+49-421-218-63921</phone> <email>cabo@tzi.org</email> </address> </author> <author initials="P." surname="Hoffman" fullname="Paul Hoffman"> <organization showOnFrontPage="true">ICANN</organization> <address> <email>paul.hoffman@icann.org</email> </address> </author> <date month="12" year="2020"/> <area>Internet</area> <keyword>parser</keyword> <keyword>decoder</keyword> <keyword>encoder</keyword> <keyword>binary format</keyword> <keyword>data interchange format</keyword> <keyword>JSON</keyword> <abstract pn="section-abstract"> <t indent="0" pn="section-abstract-1">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.</t> <t indent="0" pn="section-abstract-2"> This document obsoletes RFC 7049, providing editorial improvements, new details, and errata fixes while keeping full compatibility with the interchange format of RFC 7049. It does not create a new version of the format. </t> </abstract> <boilerplate> <section anchor="status-of-memo" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.1"> <name slugifiedName="name-status-of-this-memo">Status of This Memo</name> <t indent="0" pn="section-boilerplate.1-1"> This is an Internet Standards Track document. </t> <t indent="0" pn="section-boilerplate.1-2"> This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 7841. </t> <t indent="0" pn="section-boilerplate.1-3"> Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at <eref target="https://www.rfc-editor.org/info/rfc8949" brackets="none"/>. </t> </section> <section anchor="copyright" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.2"> <name slugifiedName="name-copyright-notice">Copyright Notice</name> <t indent="0" pn="section-boilerplate.2-1"> Copyright (c) 2020 IETF Trust and the persons identified as the document authors. All rights reserved. </t> <t indent="0" pn="section-boilerplate.2-2"> This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (<eref target="https://trustee.ietf.org/license-info" brackets="none"/>) 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. </t> </section> </boilerplate> <toc> <section anchor="toc" numbered="false" removeInRFC="false" toc="exclude" pn="section-toc.1"> <name slugifiedName="name-table-of-contents">Table of Contents</name> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1"> <li pn="section-toc.1-1.1"> <t indent="0" keepWithNext="true" pn="section-toc.1-1.1.1"><xref derivedContent="1" format="counter" sectionFormat="of" target="section-1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-introduction">Introduction</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.1.2"> <li pn="section-toc.1-1.1.2.1"> <t indent="0" keepWithNext="true" pn="section-toc.1-1.1.2.1.1"><xref derivedContent="1.1" format="counter" sectionFormat="of" target="section-1.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-objectives">Objectives</xref></t> </li> <li pn="section-toc.1-1.1.2.2"> <t indent="0" keepWithNext="true" pn="section-toc.1-1.1.2.2.1"><xref derivedContent="1.2" format="counter" sectionFormat="of" target="section-1.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-terminology">Terminology</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.2"> <t indent="0" pn="section-toc.1-1.2.1"><xref derivedContent="2" format="counter" sectionFormat="of" target="section-2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-cbor-data-models">CBOR Data Models</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.2.2"> <li pn="section-toc.1-1.2.2.1"> <t indent="0" pn="section-toc.1-1.2.2.1.1"><xref derivedContent="2.1" format="counter" sectionFormat="of" target="section-2.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-extended-generic-data-model">Extended Generic Data Models</xref></t> </li> <li pn="section-toc.1-1.2.2.2"> <t indent="0" pn="section-toc.1-1.2.2.2.1"><xref derivedContent="2.2" format="counter" sectionFormat="of" target="section-2.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-specific-data-models">Specific Data Models</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.3"> <t indent="0" pn="section-toc.1-1.3.1"><xref derivedContent="3" format="counter" sectionFormat="of" target="section-3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-specification-of-the-cbor-e">Specification of the CBOR Encoding</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.3.2"> <li pn="section-toc.1-1.3.2.1"> <t indent="0" pn="section-toc.1-1.3.2.1.1"><xref derivedContent="3.1" format="counter" sectionFormat="of" target="section-3.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-major-types">Major Types</xref></t> </li> <li pn="section-toc.1-1.3.2.2"> <t indent="0" pn="section-toc.1-1.3.2.2.1"><xref derivedContent="3.2" format="counter" sectionFormat="of" target="section-3.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-indefinite-lengths-for-some">Indefinite Lengths for Some Major Types</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.3.2.2.2"> <li pn="section-toc.1-1.3.2.2.2.1"> <t indent="0" pn="section-toc.1-1.3.2.2.2.1.1"><xref derivedContent="3.2.1" format="counter" sectionFormat="of" target="section-3.2.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-the-break-stop-code">The "break" Stop Code</xref></t> </li> <li pn="section-toc.1-1.3.2.2.2.2"> <t indent="0" pn="section-toc.1-1.3.2.2.2.2.1"><xref derivedContent="3.2.2" format="counter" sectionFormat="of" target="section-3.2.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-indefinite-length-arrays-an">Indefinite-Length Arrays and Maps</xref></t> </li> <li pn="section-toc.1-1.3.2.2.2.3"> <t indent="0" pn="section-toc.1-1.3.2.2.2.3.1"><xref derivedContent="3.2.3" format="counter" sectionFormat="of" target="section-3.2.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-indefinite-length-byte-stri">Indefinite-Length Byte Strings and Text Strings</xref></t> </li> <li pn="section-toc.1-1.3.2.2.2.4"> <t indent="0" pn="section-toc.1-1.3.2.2.2.4.1"><xref derivedContent="3.2.4" format="counter" sectionFormat="of" target="section-3.2.4"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-summary-of-indefinite-lengt">Summary of Indefinite-Length Use of Major Types</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.3.2.3"> <t indent="0" pn="section-toc.1-1.3.2.3.1"><xref derivedContent="3.3" format="counter" sectionFormat="of" target="section-3.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-floating-point-numbers-and-">Floating-Point Numbers and Values with No Content</xref></t> </li> <li pn="section-toc.1-1.3.2.4"> <t indent="0" pn="section-toc.1-1.3.2.4.1"><xref derivedContent="3.4" format="counter" sectionFormat="of" target="section-3.4"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-tagging-of-items">Tagging of Items</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.3.2.4.2"> <li pn="section-toc.1-1.3.2.4.2.1"> <t indent="0" pn="section-toc.1-1.3.2.4.2.1.1"><xref derivedContent="3.4.1" format="counter" sectionFormat="of" target="section-3.4.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-standard-date-time-string">Standard Date/Time String</xref></t> </li> <li pn="section-toc.1-1.3.2.4.2.2"> <t indent="0" pn="section-toc.1-1.3.2.4.2.2.1"><xref derivedContent="3.4.2" format="counter" sectionFormat="of" target="section-3.4.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-epoch-based-date-time">Epoch-Based Date/Time</xref></t> </li> <li pn="section-toc.1-1.3.2.4.2.3"> <t indent="0" pn="section-toc.1-1.3.2.4.2.3.1"><xref derivedContent="3.4.3" format="counter" sectionFormat="of" target="section-3.4.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-bignums">Bignums</xref></t> </li> <li pn="section-toc.1-1.3.2.4.2.4"> <t indent="0" pn="section-toc.1-1.3.2.4.2.4.1"><xref derivedContent="3.4.4" format="counter" sectionFormat="of" target="section-3.4.4"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-decimal-fractions-and-bigfl">Decimal Fractions and Bigfloats</xref></t> </li> <li pn="section-toc.1-1.3.2.4.2.5"> <t indent="0" pn="section-toc.1-1.3.2.4.2.5.1"><xref derivedContent="3.4.5" format="counter" sectionFormat="of" target="section-3.4.5"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-content-hints">Content Hints</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.3.2.4.2.5.2"> <li pn="section-toc.1-1.3.2.4.2.5.2.1"> <t indent="0" pn="section-toc.1-1.3.2.4.2.5.2.1.1"><xref derivedContent="3.4.5.1" format="counter" sectionFormat="of" target="section-3.4.5.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-encoded-cbor-data-item">Encoded CBOR Data Item</xref></t> </li> <li pn="section-toc.1-1.3.2.4.2.5.2.2"> <t indent="0" pn="section-toc.1-1.3.2.4.2.5.2.2.1"><xref derivedContent="3.4.5.2" format="counter" sectionFormat="of" target="section-3.4.5.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-expected-later-encoding-for">Expected Later Encoding for CBOR-to-JSON Converters</xref></t> </li> <li pn="section-toc.1-1.3.2.4.2.5.2.3"> <t indent="0" pn="section-toc.1-1.3.2.4.2.5.2.3.1"><xref derivedContent="3.4.5.3" format="counter" sectionFormat="of" target="section-3.4.5.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-encoded-text">Encoded Text</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.3.2.4.2.6"> <t indent="0" pn="section-toc.1-1.3.2.4.2.6.1"><xref derivedContent="3.4.6" format="counter" sectionFormat="of" target="section-3.4.6"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-self-described-cbor">Self-Described CBOR</xref></t> </li> </ul> </li> </ul> </li> <li pn="section-toc.1-1.4"> <t indent="0" pn="section-toc.1-1.4.1"><xref derivedContent="4" format="counter" sectionFormat="of" target="section-4"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-serialization-consideration">Serialization Considerations</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.4.2"> <li pn="section-toc.1-1.4.2.1"> <t indent="0" pn="section-toc.1-1.4.2.1.1"><xref derivedContent="4.1" format="counter" sectionFormat="of" target="section-4.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-preferred-serialization">Preferred Serialization</xref></t> </li> <li pn="section-toc.1-1.4.2.2"> <t indent="0" pn="section-toc.1-1.4.2.2.1"><xref derivedContent="4.2" format="counter" sectionFormat="of" target="section-4.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-deterministically-encoded-c">Deterministically Encoded CBOR</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.4.2.2.2"> <li pn="section-toc.1-1.4.2.2.2.1"> <t indent="0" pn="section-toc.1-1.4.2.2.2.1.1"><xref derivedContent="4.2.1" format="counter" sectionFormat="of" target="section-4.2.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-core-deterministic-encoding">Core Deterministic Encoding Requirements</xref></t> </li> <li pn="section-toc.1-1.4.2.2.2.2"> <t indent="0" pn="section-toc.1-1.4.2.2.2.2.1"><xref derivedContent="4.2.2" format="counter" sectionFormat="of" target="section-4.2.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-additional-deterministic-en">Additional Deterministic Encoding Considerations</xref></t> </li> <li pn="section-toc.1-1.4.2.2.2.3"> <t indent="0" pn="section-toc.1-1.4.2.2.2.3.1"><xref derivedContent="4.2.3" format="counter" sectionFormat="of" target="section-4.2.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-length-first-map-key-orderi">Length-First Map Key Ordering</xref></t> </li> </ul> </li> </ul> </li> <li pn="section-toc.1-1.5"> <t indent="0" pn="section-toc.1-1.5.1"><xref derivedContent="5" format="counter" sectionFormat="of" target="section-5"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-creating-cbor-based-protoco">Creating CBOR-Based Protocols</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.5.2"> <li pn="section-toc.1-1.5.2.1"> <t indent="0" pn="section-toc.1-1.5.2.1.1"><xref derivedContent="5.1" format="counter" sectionFormat="of" target="section-5.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-cbor-in-streaming-applicati">CBOR in Streaming Applications</xref></t> </li> <li pn="section-toc.1-1.5.2.2"> <t indent="0" pn="section-toc.1-1.5.2.2.1"><xref derivedContent="5.2" format="counter" sectionFormat="of" target="section-5.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-generic-encoders-and-decode">Generic Encoders and Decoders</xref></t> </li> <li pn="section-toc.1-1.5.2.3"> <t indent="0" pn="section-toc.1-1.5.2.3.1"><xref derivedContent="5.3" format="counter" sectionFormat="of" target="section-5.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-validity-of-items">Validity of Items</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.5.2.3.2"> <li pn="section-toc.1-1.5.2.3.2.1"> <t indent="0" pn="section-toc.1-1.5.2.3.2.1.1"><xref derivedContent="5.3.1" format="counter" sectionFormat="of" target="section-5.3.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-basic-validity">Basic validity</xref></t> </li> <li pn="section-toc.1-1.5.2.3.2.2"> <t indent="0" pn="section-toc.1-1.5.2.3.2.2.1"><xref derivedContent="5.3.2" format="counter" sectionFormat="of" target="section-5.3.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-tag-validity">Tag validity</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.5.2.4"> <t indent="0" pn="section-toc.1-1.5.2.4.1"><xref derivedContent="5.4" format="counter" sectionFormat="of" target="section-5.4"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-validity-and-evolution">Validity and Evolution</xref></t> </li> <li pn="section-toc.1-1.5.2.5"> <t indent="0" pn="section-toc.1-1.5.2.5.1"><xref derivedContent="5.5" format="counter" sectionFormat="of" target="section-5.5"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-numbers">Numbers</xref></t> </li> <li pn="section-toc.1-1.5.2.6"> <t indent="0" pn="section-toc.1-1.5.2.6.1"><xref derivedContent="5.6" format="counter" sectionFormat="of" target="section-5.6"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-specifying-keys-for-maps">Specifying Keys for Maps</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.5.2.6.2"> <li pn="section-toc.1-1.5.2.6.2.1"> <t indent="0" pn="section-toc.1-1.5.2.6.2.1.1"><xref derivedContent="5.6.1" format="counter" sectionFormat="of" target="section-5.6.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-equivalence-of-keys">Equivalence of Keys</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.5.2.7"> <t indent="0" pn="section-toc.1-1.5.2.7.1"><xref derivedContent="5.7" format="counter" sectionFormat="of" target="section-5.7"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-undefined-values">Undefined Values</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.6"> <t indent="0" pn="section-toc.1-1.6.1"><xref derivedContent="6" format="counter" sectionFormat="of" target="section-6"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-converting-data-between-cbo">Converting Data between CBOR and JSON</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.6.2"> <li pn="section-toc.1-1.6.2.1"> <t indent="0" pn="section-toc.1-1.6.2.1.1"><xref derivedContent="6.1" format="counter" sectionFormat="of" target="section-6.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-converting-from-cbor-to-jso">Converting from CBOR to JSON</xref></t> </li> <li pn="section-toc.1-1.6.2.2"> <t indent="0" pn="section-toc.1-1.6.2.2.1"><xref derivedContent="6.2" format="counter" sectionFormat="of" target="section-6.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-converting-from-json-to-cbo">Converting from JSON to CBOR</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.7"> <t indent="0" pn="section-toc.1-1.7.1"><xref derivedContent="7" format="counter" sectionFormat="of" target="section-7"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-future-evolution-of-cbor">Future Evolution of CBOR</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.7.2"> <li pn="section-toc.1-1.7.2.1"> <t indent="0" pn="section-toc.1-1.7.2.1.1"><xref derivedContent="7.1" format="counter" sectionFormat="of" target="section-7.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-extension-points">Extension Points</xref></t> </li> <li pn="section-toc.1-1.7.2.2"> <t indent="0" pn="section-toc.1-1.7.2.2.1"><xref derivedContent="7.2" format="counter" sectionFormat="of" target="section-7.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-curating-the-additional-inf">Curating the Additional Information Space</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.8"> <t indent="0" pn="section-toc.1-1.8.1"><xref derivedContent="8" format="counter" sectionFormat="of" target="section-8"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-diagnostic-notation">Diagnostic Notation</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.8.2"> <li pn="section-toc.1-1.8.2.1"> <t indent="0" pn="section-toc.1-1.8.2.1.1"><xref derivedContent="8.1" format="counter" sectionFormat="of" target="section-8.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-encoding-indicators">Encoding Indicators</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.9"> <t indent="0" pn="section-toc.1-1.9.1"><xref derivedContent="9" format="counter" sectionFormat="of" target="section-9"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-iana-considerations">IANA Considerations</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.9.2"> <li pn="section-toc.1-1.9.2.1"> <t indent="0" pn="section-toc.1-1.9.2.1.1"><xref derivedContent="9.1" format="counter" sectionFormat="of" target="section-9.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-cbor-simple-values-registry">CBOR Simple Values Registry</xref></t> </li> <li pn="section-toc.1-1.9.2.2"> <t indent="0" pn="section-toc.1-1.9.2.2.1"><xref derivedContent="9.2" format="counter" sectionFormat="of" target="section-9.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-cbor-tags-registry">CBOR Tags Registry</xref></t> </li> <li pn="section-toc.1-1.9.2.3"> <t indent="0" pn="section-toc.1-1.9.2.3.1"><xref derivedContent="9.3" format="counter" sectionFormat="of" target="section-9.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-media-types-registry">Media Types Registry</xref></t> </li> <li pn="section-toc.1-1.9.2.4"> <t indent="0" pn="section-toc.1-1.9.2.4.1"><xref derivedContent="9.4" format="counter" sectionFormat="of" target="section-9.4"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-coap-content-format-registr">CoAP Content-Format Registry</xref></t> </li> <li pn="section-toc.1-1.9.2.5"> <t indent="0" pn="section-toc.1-1.9.2.5.1"><xref derivedContent="9.5" format="counter" sectionFormat="of" target="section-9.5"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-structured-syntax-suffix-re">Structured Syntax Suffix Registry</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.10"> <t indent="0" pn="section-toc.1-1.10.1"><xref derivedContent="10" format="counter" sectionFormat="of" target="section-10"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-security-considerations">Security Considerations</xref></t> </li> <li pn="section-toc.1-1.11"> <t indent="0" pn="section-toc.1-1.11.1"><xref derivedContent="11" format="counter" sectionFormat="of" target="section-11"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-references">References</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.11.2"> <li pn="section-toc.1-1.11.2.1"> <t indent="0" pn="section-toc.1-1.11.2.1.1"><xref derivedContent="11.1" format="counter" sectionFormat="of" target="section-11.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-normative-references">Normative References</xref></t> </li> <li pn="section-toc.1-1.11.2.2"> <t indent="0" pn="section-toc.1-1.11.2.2.1"><xref derivedContent="11.2" format="counter" sectionFormat="of" target="section-11.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-informative-references">Informative References</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.12"> <t indent="0" pn="section-toc.1-1.12.1"><xref derivedContent="Appendix A" format="default" sectionFormat="of" target="section-appendix.a"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-examples-of-encoded-cbor-da">Examples of Encoded CBOR Data Items</xref></t> </li> <li pn="section-toc.1-1.13"> <t indent="0" pn="section-toc.1-1.13.1"><xref derivedContent="Appendix B" format="default" sectionFormat="of" target="section-appendix.b"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-jump-table-for-initial-byte">Jump Table for Initial Byte</xref></t> </li> <li pn="section-toc.1-1.14"> <t indent="0" pn="section-toc.1-1.14.1"><xref derivedContent="Appendix C" format="default" sectionFormat="of" target="section-appendix.c"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-pseudocode">Pseudocode</xref></t> </li> <li pn="section-toc.1-1.15"> <t indent="0" pn="section-toc.1-1.15.1"><xref derivedContent="Appendix D" format="default" sectionFormat="of" target="section-appendix.d"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-half-precision">Half-Precision</xref></t> </li> <li pn="section-toc.1-1.16"> <t indent="0" pn="section-toc.1-1.16.1"><xref derivedContent="Appendix E" format="default" sectionFormat="of" target="section-appendix.e"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-comparison-of-other-binary-">Comparison of Other Binary Formats to CBOR's Design Objectives</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.16.2"> <li pn="section-toc.1-1.16.2.1"> <t indent="0" pn="section-toc.1-1.16.2.1.1"><xref derivedContent="E.1" format="counter" sectionFormat="of" target="section-e.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-asn1-der-ber-and-per">ASN.1 DER, BER, and PER</xref></t> </li> <li pn="section-toc.1-1.16.2.2"> <t indent="0" pn="section-toc.1-1.16.2.2.1"><xref derivedContent="E.2" format="counter" sectionFormat="of" target="section-e.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-messagepack">MessagePack</xref></t> </li> <li pn="section-toc.1-1.16.2.3"> <t indent="0" pn="section-toc.1-1.16.2.3.1"><xref derivedContent="E.3" format="counter" sectionFormat="of" target="section-e.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-bson">BSON</xref></t> </li> <li pn="section-toc.1-1.16.2.4"> <t indent="0" pn="section-toc.1-1.16.2.4.1"><xref derivedContent="E.4" format="counter" sectionFormat="of" target="section-e.4"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-msdtp-rfc-713">MSDTP: RFC 713</xref></t> </li> <li pn="section-toc.1-1.16.2.5"> <t indent="0" pn="section-toc.1-1.16.2.5.1"><xref derivedContent="E.5" format="counter" sectionFormat="of" target="section-e.5"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-conciseness-on-the-wire">Conciseness on the Wire</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.17"> <t indent="0" pn="section-toc.1-1.17.1"><xref derivedContent="Appendix F" format="default" sectionFormat="of" target="section-appendix.f"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-well-formedness-errors-and-">Well-Formedness Errors and Examples</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.17.2"> <li pn="section-toc.1-1.17.2.1"> <t indent="0" pn="section-toc.1-1.17.2.1.1"><xref derivedContent="F.1" format="counter" sectionFormat="of" target="section-f.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-examples-of-cbor-data-items">Examples of CBOR Data Items That Are Not Well-Formed</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.18"> <t indent="0" pn="section-toc.1-1.18.1"><xref derivedContent="Appendix G" format="default" sectionFormat="of" target="section-appendix.g"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-changes-from-rfc-7049">Changes from RFC 7049</xref></t> <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.18.2"> <li pn="section-toc.1-1.18.2.1"> <t indent="0" pn="section-toc.1-1.18.2.1.1"><xref derivedContent="G.1" format="counter" sectionFormat="of" target="section-g.1"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-errata-processing-and-cleri">Errata Processing and Clerical Changes</xref></t> </li> <li pn="section-toc.1-1.18.2.2"> <t indent="0" pn="section-toc.1-1.18.2.2.1"><xref derivedContent="G.2" format="counter" sectionFormat="of" target="section-g.2"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-changes-in-iana-considerati">Changes in IANA Considerations</xref></t> </li> <li pn="section-toc.1-1.18.2.3"> <t indent="0" pn="section-toc.1-1.18.2.3.1"><xref derivedContent="G.3" format="counter" sectionFormat="of" target="section-g.3"/>. <xref derivedContent="" format="title" sectionFormat="of" target="name-changes-in-suggestions-and-">Changes in Suggestions and Other Informational Components</xref></t> </li> </ul> </li> <li pn="section-toc.1-1.19"> <t indent="0" pn="section-toc.1-1.19.1"><xref derivedContent="" format="none" sectionFormat="of" target="section-appendix.h"/><xref derivedContent="" format="title" sectionFormat="of" target="name-acknowledgements">Acknowledgements</xref></t> </li> <li pn="section-toc.1-1.20"> <t indent="0" pn="section-toc.1-1.20.1"><xref derivedContent="" format="none" sectionFormat="of" target="section-appendix.i"/><xref derivedContent="" format="title" sectionFormat="of" target="name-authors-addresses">Authors' Addresses</xref></t> </li> </ul> </section> </toc> </front> <middle> <section anchor="introduction" toc="include" numbered="true" removeInRFC="false" pn="section-1"> <name slugifiedName="name-introduction">Introduction</name> <t indent="0" pn="section-1-1">There are hundreds of standardized formats for binary representation of structured data (also known as binary serialization formats). Of those, some are for specific domains of information, while others are generalized for arbitrary data. In the IETF, probably the best-known formats in the latter category are ASN.1's BER and DER <xref target="ASN.1" format="default" sectionFormat="of" derivedContent="ASN.1"/>.</t> <t indent="0" pn="section-1-2">The format defined here follows some specific design goals that are not well met by current formats. The underlying data model is an extended version of the JSON data model <xref target="RFC8259" format="default" sectionFormat="of" derivedContent="RFC8259"/>. It is important to note that this is not a proposal that the grammar in RFC 8259 be extended in general, since doing so would cause a significant backwards incompatibility with already deployed JSON documents. Instead, this document simply defines its own data model that starts from JSON.</t> <t indent="0" pn="section-1-3"><xref target="comparison-app" format="default" sectionFormat="of" derivedContent="Appendix E"/> lists some existing binary formats and discusses how well they do or do not fit the design objectives of the Concise Binary Object Representation (CBOR).</t> <t indent="0" pn="section-1-4"> This document obsoletes <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/>, providing editorial improvements, new details, and errata fixes while keeping full compatibility with the interchange format of RFC 7049. It does not create a new version of the format. </t> <section anchor="objectives" toc="include" numbered="true" removeInRFC="false" pn="section-1.1"> <name slugifiedName="name-objectives">Objectives</name> <t indent="0" pn="section-1.1-1">The objectives of CBOR, roughly in decreasing order of importance, are:</t> <ol spacing="normal" type="1" indent="adaptive" start="1" pn="section-1.1-2"><li pn="section-1.1-2.1" derivedCounter="1."> <t indent="0" pn="section-1.1-2.1.1">The representation must be able to unambiguously encode most common data formats used in Internet standards. </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-1.1-2.1.2"> <li pn="section-1.1-2.1.2.1">It must represent a reasonable set of basic data types and structures using binary encoding. "Reasonable" here is largely influenced by the capabilities of JSON, with the major addition of binary byte strings. The structures supported are limited to arrays and trees; loops and lattice-style graphs are not supported.</li> <li pn="section-1.1-2.1.2.2">There is no requirement that all data formats be uniquely encoded; that is, it is acceptable that the number "7" might be encoded in multiple different ways.</li> </ul> </li> <li pn="section-1.1-2.2" derivedCounter="2."> <t indent="0" pn="section-1.1-2.2.1">The code for an encoder or decoder must be able to be compact in order to support systems with very limited memory, processor power, and instruction sets. </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-1.1-2.2.2"> <li pn="section-1.1-2.2.2.1">An encoder and a decoder need to be implementable in a very small amount of code (for example, in class 1 constrained nodes as defined in <xref target="RFC7228" format="default" sectionFormat="of" derivedContent="RFC7228"/>).</li> <li pn="section-1.1-2.2.2.2">The format should use contemporary machine representations of data (for example, not requiring binary-to-decimal conversion).</li> </ul> </li> <li pn="section-1.1-2.3" derivedCounter="3."> <t indent="0" pn="section-1.1-2.3.1">Data must be able to be decoded without a schema description. </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-1.1-2.3.2"> <li pn="section-1.1-2.3.2.1">Similar to JSON, encoded data should be self-describing so that a generic decoder can be written.</li> </ul> </li> <li pn="section-1.1-2.4" derivedCounter="4."> <t indent="0" pn="section-1.1-2.4.1">The serialization must be reasonably compact, but data compactness is secondary to code compactness for the encoder and decoder. </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-1.1-2.4.2"> <li pn="section-1.1-2.4.2.1">"Reasonable" here is bounded by JSON as an upper bound in size and by the implementation complexity, which limits the amount of effort that can go into achieving that compactness. Using either general compression schemes or extensive bit-fiddling violates the complexity goals.</li> </ul> </li> <li pn="section-1.1-2.5" derivedCounter="5."> <t indent="0" pn="section-1.1-2.5.1">The format must be applicable to both constrained nodes and high-volume applications. </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-1.1-2.5.2"> <li pn="section-1.1-2.5.2.1">This means it must be reasonably frugal in CPU usage for both encoding and decoding. This is relevant both for constrained nodes and for potential usage in applications with a very high volume of data.</li> </ul> </li> <li pn="section-1.1-2.6" derivedCounter="6."> <t indent="0" pn="section-1.1-2.6.1">The format must support all JSON data types for conversion to and from JSON. </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-1.1-2.6.2"> <li pn="section-1.1-2.6.2.1">It must support a reasonable level of conversion as long as the data represented is within the capabilities of JSON. It must be possible to define a unidirectional mapping towards JSON for all types of data.</li> </ul> </li> <li pn="section-1.1-2.7" derivedCounter="7."> <t indent="0" pn="section-1.1-2.7.1">The format must be extensible, and the extended data must be decodable by earlier decoders. </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-1.1-2.7.2"> <li pn="section-1.1-2.7.2.1">The format is designed for decades of use.</li> <li pn="section-1.1-2.7.2.2">The format must support a form of extensibility that allows fallback so that a decoder that does not understand an extension can still decode the message.</li> <li pn="section-1.1-2.7.2.3">The format must be able to be extended in the future by later IETF standards.</li> </ul> </li> </ol> </section> <section anchor="terminology" toc="include" numbered="true" removeInRFC="false" pn="section-1.2"> <name slugifiedName="name-terminology">Terminology</name> <t indent="0" pn="section-1.2-1">The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>", "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as described in BCP 14 <xref target="RFC2119" format="default" sectionFormat="of" derivedContent="RFC2119"/> <xref target="RFC8174" format="default" sectionFormat="of" derivedContent="RFC8174"/> when, and only when, they appear in all capitals, as shown here. </t> <t indent="0" pn="section-1.2-2">The term "byte" is used in its now-customary sense as a synonym for "octet". All multi-byte values are encoded in network byte order (that is, most significant byte first, also known as "big-endian").</t> <t indent="0" pn="section-1.2-3">This specification makes use of the following terminology:</t> <dl newline="false" spacing="normal" indent="3" pn="section-1.2-4"> <dt pn="section-1.2-4.1">Data item:</dt> <dd pn="section-1.2-4.2"> A single piece of CBOR data. The structure of a data item may contain zero, one, or more nested data items. The term is used both for the data item in representation format and for the abstract idea that can be derived from that by a decoder; the former can be addressed specifically by using the term "encoded data item".</dd> <dt pn="section-1.2-4.3">Decoder:</dt> <dd pn="section-1.2-4.4"> A process that decodes a well-formed encoded CBOR data item and makes it available to an application. Formally speaking, a decoder contains a parser to break up the input using the syntax rules of CBOR, as well as a semantic processor to prepare the data in a form suitable to the application.</dd> <dt pn="section-1.2-4.5">Encoder:</dt> <dd pn="section-1.2-4.6"> A process that generates the (well-formed) representation format of a CBOR data item from application information.</dd> <dt pn="section-1.2-4.7">Data Stream:</dt> <dd pn="section-1.2-4.8"> A sequence of zero or more data items, not further assembled into a larger containing data item (see <xref target="RFC8742" format="default" sectionFormat="of" derivedContent="RFC8742"/> for one application). The independent data items that make up a data stream are sometimes also referred to as "top-level data items".</dd> <dt pn="section-1.2-4.9">Well-formed:</dt> <dd pn="section-1.2-4.10"> A data item that follows the syntactic structure of CBOR. A well-formed data item uses the initial bytes and the byte strings and/or data items that are implied by their values as defined in CBOR and does not include following extraneous data. CBOR decoders by definition only return contents from well-formed data items.</dd> <dt pn="section-1.2-4.11">Valid:</dt> <dd pn="section-1.2-4.12"> A data item that is well-formed and also follows the semantic restrictions that apply to CBOR data items (<xref target="semantic-errors" format="default" sectionFormat="of" derivedContent="Section 5.3"/>).</dd> <dt pn="section-1.2-4.13">Expected:</dt> <dd pn="section-1.2-4.14"> Besides its normal English meaning, the term "expected" is used to describe requirements beyond CBOR validity that an application has on its input data. Well-formed (processable at all), valid (checked by a validity-checking generic decoder), and expected (checked by the application) form a hierarchy of layers of acceptability.</dd> <dt pn="section-1.2-4.15">Stream decoder:</dt> <dd pn="section-1.2-4.16"> A process that decodes a data stream and makes each of the data items in the sequence available to an application as they are received.</dd> </dl> <t indent="0" pn="section-1.2-5">Terms and concepts for floating-point values such as Infinity, NaN (not a number), negative zero, and subnormal are defined in <xref target="IEEE754" format="default" sectionFormat="of" derivedContent="IEEE754"/>.</t> <t indent="0" pn="section-1.2-6">Where bit arithmetic or data types are explained, this document uses the notation familiar from the programming language C <xref target="C" format="default" sectionFormat="of" derivedContent="C"/>, except that ".." denotes a range that includes both ends given, and superscript notation denotes exponentiation. For example, 2 to the power of 64 is notated: 2<sup>64</sup>. In the plain-text version of this specification, superscript notation is not available and therefore is rendered by a surrogate notation. That notation is not optimized for this RFC; it is unfortunately ambiguous with C's exclusive-or (which is only used in the appendices, which in turn do not use exponentiation) and requires circumspection from the reader of the plain-text version. </t> <t indent="0" pn="section-1.2-7">Examples and pseudocode assume that signed integers use two's complement representation and that right shifts of signed integers perform sign extension; these assumptions are also specified in Sections 6.8.1 (basic.fundamental) and 7.6.7 (expr.shift) of the 2020 version of C++ (currently available as a final draft, <xref target="Cplusplus20" format="default" sectionFormat="of" derivedContent="Cplusplus20"/>).</t> <t indent="0" pn="section-1.2-8">Similar to the "0x" notation for hexadecimal numbers, numbers in binary notation are prefixed with "0b". Underscores can be added to a number solely for readability, so 0b00100001 (0x21) might be written 0b001_00001 to emphasize the desired interpretation of the bits in the byte; in this case, it is split into three bits and five bits. Encoded CBOR data items are sometimes given in the "0x" or "0b" notation; these values are first interpreted as numbers as in C and are then interpreted as byte strings in network byte order, including any leading zero bytes expressed in the notation.</t> <t indent="0" pn="section-1.2-9">Words may be <em>italicized</em> for emphasis; in the plain text form of this specification, this is indicated by surrounding words with underscore characters. Verbatim text (e.g., names from a programming language) may be set in <tt>monospace</tt> type; in plain text, this is approximated somewhat ambiguously by surrounding the text in double quotes (which also retain their usual meaning).</t> </section> </section> <section anchor="cbor-data-models" toc="include" numbered="true" removeInRFC="false" pn="section-2"> <name slugifiedName="name-cbor-data-models">CBOR Data Models</name> <t indent="0" pn="section-2-1">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 data model is extensible by the registration of "simple values" and tags. Applications can then create a subset of the resulting extended generic data model to build their specific data models.</t> <t indent="0" pn="section-2-2">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.</t> <t indent="0" pn="section-2-3">In the basic (unextended) generic data model defined in <xref target="encoding" format="default" sectionFormat="of" derivedContent="Section 3"/>, a data item is one of the following:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-2-4"> <li pn="section-2-4.1">an integer in the range -2<sup>64</sup>..2<sup>64</sup>-1 inclusive</li> <li pn="section-2-4.2">a simple value, identified by a number between 0 and 255, but distinct from that number itself</li> <li pn="section-2-4.3">a floating-point value, distinct from an integer, out of the set representable by IEEE 754 binary64 (including non-finites) <xref target="IEEE754" format="default" sectionFormat="of" derivedContent="IEEE754"/></li> <li pn="section-2-4.4">a sequence of zero or more bytes ("byte string")</li> <li pn="section-2-4.5">a sequence of zero or more Unicode code points ("text string")</li> <li pn="section-2-4.6">a sequence of zero or more data items ("array")</li> <li pn="section-2-4.7">a mapping (mathematical function) from zero or more data items ("keys") each to a data item ("values"), ("map")</li> <li pn="section-2-4.8">a tagged data item ("tag"), comprising a tag number (an integer in the range 0..2<sup>64</sup>-1) and the tag content (a data item)</li> </ul> <t indent="0" pn="section-2-5">Note that integer and floating-point values are distinct in this model, even if they have the same numeric value.</t> <t indent="0" pn="section-2-6">Also note that serialization variants are not visible at the generic data model level. This deliberate absence of visibility includes the number of bytes of the encoded floating-point value. It also includes the choice of encoding for an "argument" (see <xref target="encoding" format="default" sectionFormat="of" derivedContent="Section 3"/>) such as the encoding for an integer, the encoding for the length of a text or byte string, the encoding for the number of elements in an array or pairs in a map, or the encoding for a tag number.</t> <section anchor="extended-generic-data-models" toc="include" numbered="true" removeInRFC="false" pn="section-2.1"> <name slugifiedName="name-extended-generic-data-model">Extended Generic Data Models</name> <t indent="0" pn="section-2.1-1">This basic generic data model has been extended in this document by the registration of a number of simple values and tag numbers, such as:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-2.1-2"> <li pn="section-2.1-2.1"> <tt>false</tt>, <tt>true</tt>, <tt>null</tt>, and <tt>undefined</tt> (simple values identified by 20..23, <xref target="fpnocont" format="default" sectionFormat="of" derivedContent="Section 3.3"/>)</li> <li pn="section-2.1-2.2">integer and floating-point values with a larger range and precision than the above (tag numbers 2 to 5, <xref target="tags" format="default" sectionFormat="of" derivedContent="Section 3.4"/>)</li> <li pn="section-2.1-2.3">application data types such as a point in time or date/time string defined in RFC 3339 (tag numbers 1 and 0, <xref target="tags" format="default" sectionFormat="of" derivedContent="Section 3.4"/>)</li> </ul> <t indent="0" pn="section-2.1-3">Additional 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 application interface within the basic generic data model, i.e., as generic simple values or generic tags.</t> <t indent="0" pn="section-2.1-4">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 tag numbers, but never shrinks.</t> <t indent="0" pn="section-2.1-5">While there is a strong expectation that generic encoders and decoders can represent <tt>false</tt>, <tt>true</tt>, and <tt>null</tt> (<tt>undefined</tt> is intentionally omitted) in the form appropriate for their programming environment, the implementation of the data model extensions created by tags is truly optional and a matter of implementation quality.</t> </section> <section anchor="specific-data-models" toc="include" numbered="true" removeInRFC="false" pn="section-2.2"> <name slugifiedName="name-specific-data-models">Specific Data Models</name> <t indent="0" pn="section-2.2-1">The specific data model for a CBOR-based protocol usually takes a subset of 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 and specifying the types of data items, it is preferable to identify the types by their generic data model names ("negative integer", "array") instead of referring to aspects of their CBOR representation ("major type 1", "major type 4").</t> <t indent="0" pn="section-2.2-2"> Specific data models can also specify value equivalency (including values of different types) for the purposes of map keys and encoder freedom. For example, in the generic data model, a valid map <bcp14>MAY</bcp14> have both <tt>0</tt> and <tt>0.0</tt> as keys, and an encoder <bcp14>MUST NOT</bcp14> encode <tt>0.0</tt> as an integer (major type 0, <xref target="majortypes" format="default" sectionFormat="of" derivedContent="Section 3.1"/>). However, if a specific data model declares that floating-point and integer representations of integral values are equivalent, using both map keys <tt>0</tt> and <tt>0.0</tt> in a single map would be considered duplicates, even while encoded as different major types, and so invalid; and an encoder could encode integral-valued floats as integers or vice versa, perhaps to save encoded bytes.</t> </section> </section> <section anchor="encoding" toc="include" numbered="true" removeInRFC="false" pn="section-3"> <name slugifiedName="name-specification-of-the-cbor-e">Specification of the CBOR Encoding</name> <t indent="0" pn="section-3-1">A CBOR data item (<xref target="cbor-data-models" format="default" sectionFormat="of" derivedContent="Section 2"/>) is encoded to or decoded from a byte string carrying a well-formed encoded data item as described in this section. The encoding is summarized in <xref target="jumptable" format="default" sectionFormat="of" derivedContent="Table 7"/> in <xref target="jump-table" format="default" sectionFormat="of" derivedContent="Appendix B"/>, indexed by the initial byte. An encoder <bcp14>MUST</bcp14> produce only well-formed encoded data items. A decoder <bcp14>MUST NOT</bcp14> return a decoded data item when it encounters input that is not a well-formed encoded CBOR data item (this does not detract from the usefulness of diagnostic and recovery tools that might make available some information from a damaged encoded CBOR data item).</t> <t indent="0" pn="section-3-2">The initial byte of each encoded data item contains both information about the major type (the high-order 3 bits, described in <xref target="majortypes" format="default" sectionFormat="of" derivedContent="Section 3.1"/>) and additional information (the low-order 5 bits). With a few exceptions, the additional information's value describes how to load an unsigned integer "argument":</t> <dl newline="false" spacing="normal" indent="3" pn="section-3-3"> <dt pn="section-3-3.1">Less than 24:</dt> <dd pn="section-3-3.2"> The argument's value is the value of the additional information.</dd> <dt pn="section-3-3.3">24, 25, 26, or 27:</dt> <dd pn="section-3-3.4"> The argument's value is held in the following 1, 2, 4, or 8 bytes, respectively, in network byte order. For major type 7 and additional information value 25, 26, 27, these bytes are not used as an integer argument, but as a floating-point value (see <xref target="fpnocont" format="default" sectionFormat="of" derivedContent="Section 3.3"/>).</dd> <dt pn="section-3-3.5">28, 29, 30:</dt> <dd pn="section-3-3.6"> These values are reserved for future additions to the CBOR format. In the present version of CBOR, the encoded item is not well-formed.</dd> <dt pn="section-3-3.7">31:</dt> <dd pn="section-3-3.8"> No argument value is derived. If the major type is 0, 1, or 6, the encoded item is not well-formed. For major types 2 to 5, the item's length is indefinite, and for major type 7, the byte does not constitute a data item at all but terminates an indefinite-length item; all are described in <xref target="indefinite" format="default" sectionFormat="of" derivedContent="Section 3.2"/>.</dd> </dl> <t indent="0" pn="section-3-4">The initial byte and any additional bytes consumed to construct the argument are collectively referred to as the <em>head</em> of the data item.</t> <t indent="0" pn="section-3-5">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 follow; and in major types 4 and 5, it is used to determine the number of data items enclosed.</t> <t indent="0" pn="section-3-6">If the encoded sequence of bytes ends before the end of a data item, that item is not well-formed. If the encoded sequence of bytes still has bytes remaining after the outermost encoded item is decoded, that encoding is not a single well-formed CBOR item. Depending on the application, the decoder may either treat the encoding as not well-formed or just identify the start of the remaining bytes to the application.</t> <t indent="0" pn="section-3-7">A CBOR decoder implementation can be based on a jump table with all 256 defined values for the initial byte (<xref target="jumptable" format="default" sectionFormat="of" derivedContent="Table 7"/>). A decoder in a constrained implementation can instead use the structure of the initial byte and following bytes for more compact code (see <xref target="pseudocode" format="default" sectionFormat="of" derivedContent="Appendix C"/> for a rough impression of how this could look).</t> <section anchor="majortypes" toc="include" numbered="true" removeInRFC="false" pn="section-3.1"> <name slugifiedName="name-major-types">Major Types</name> <t indent="0" pn="section-3.1-1">The following lists the major types and the additional information and other bytes associated with the type.</t> <dl newline="true" spacing="normal" indent="3" pn="section-3.1-2"> <dt pn="section-3.1-2.1">Major type 0:</dt> <dd pn="section-3.1-2.2"> An unsigned integer in the range 0..2<sup>64</sup>-1 inclusive. The value of the encoded item is the argument itself. For example, the integer 10 is denoted as the one byte 0b000_01010 (major type 0, additional information 10). The integer 500 would be 0b000_11001 (major type 0, additional information 25) followed by the two bytes 0x01f4, which is 500 in decimal.</dd> <dt pn="section-3.1-2.3">Major type 1:</dt> <dd pn="section-3.1-2.4"> A negative integer in the range -2<sup>64</sup>..-1 inclusive. The value of the item is -1 minus the argument. For example, the integer -500 would be 0b001_11001 (major type 1, additional information 25) followed by the two bytes 0x01f3, which is 499 in decimal.</dd> <dt pn="section-3.1-2.5">Major type 2:</dt> <dd pn="section-3.1-2.6"> A byte string. The number of bytes in the string is equal to the argument. For example, a byte string whose length is 5 would have an initial byte of 0b010_00101 (major type 2, additional information 5 for the length), followed by 5 bytes of binary content. A byte string whose length is 500 would have 3 initial bytes of 0b010_11001 (major type 2, additional information 25 to indicate a two-byte length) followed by the two bytes 0x01f4 for a length of 500, followed by 500 bytes of binary content.</dd> <dt pn="section-3.1-2.7">Major type 3:</dt> <dd pn="section-3.1-2.8"> A text string (<xref target="cbor-data-models" format="default" sectionFormat="of" derivedContent="Section 2"/>) encoded as UTF-8 <xref target="RFC3629" format="default" sectionFormat="of" derivedContent="RFC3629"/>. The number of bytes in the string is equal to the argument. A string containing an invalid UTF-8 sequence is well-formed but invalid (<xref target="terminology" format="default" sectionFormat="of" derivedContent="Section 1.2"/>). This type is provided for systems that need to interpret or display human-readable text, and allows the differentiation between unstructured bytes and text that has a specified repertoire (that of Unicode) and encoding (UTF-8). In contrast to formats such as JSON, the Unicode characters in this type are never escaped. Thus, a newline character (U+000A) is always represented in a string as the byte 0x0a, and never as the bytes 0x5c6e (the characters "\" and "n") nor as 0x5c7530303061 (the characters "\", "u", "0", "0", "0", and "a").</dd> <dt pn="section-3.1-2.9">Major type 4:</dt> <dd pn="section-3.1-2.10"> An array of data items. In other formats, arrays are also called lists, sequences, or tuples (a "CBOR sequence" is something slightly different, though <xref target="RFC8742" format="default" sectionFormat="of" derivedContent="RFC8742"/>). The argument is the number of data items in the array. Items in an array do not need to all be of the same type. For example, an array that contains 10 items of any type would have an initial byte of 0b100_01010 (major type 4, additional information 10 for the length) followed by the 10 remaining items.</dd> <dt pn="section-3.1-2.11">Major type 5:</dt> <dd pn="section-3.1-2.12"> A map of pairs of data items. Maps are also called tables, dictionaries, hashes, or objects (in JSON). A map is comprised of pairs of data items, each pair consisting of a key that is immediately followed by a value. The argument is the number of <em>pairs</em> of data items in the map. For example, a map that contains 9 pairs would have an initial byte of 0b101_01001 (major type 5, additional information 9 for the number of pairs) followed by the 18 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. Because items in a map come in pairs, their total number is always even: a map that contains an odd number of items (no value data present after the last key data item) is not well-formed. A map that has duplicate keys may be well-formed, but it is not valid, and thus it causes indeterminate decoding; see also <xref target="map-keys" format="default" sectionFormat="of" derivedContent="Section 5.6"/>.</dd> <dt pn="section-3.1-2.13">Major type 6:</dt> <dd pn="section-3.1-2.14"> A tagged data item ("tag") whose tag number, an integer in the range 0..2<sup>64</sup>-1 inclusive, is the argument and whose enclosed data item (<em>tag content</em>) is the single encoded data item that follows the head. See <xref target="tags" format="default" sectionFormat="of" derivedContent="Section 3.4"/>.</dd> <dt pn="section-3.1-2.15">Major type 7:</dt> <dd pn="section-3.1-2.16"> Floating-point numbers and simple values, as well as the "break" stop code. See <xref target="fpnocont" format="default" sectionFormat="of" derivedContent="Section 3.3"/>.</dd> </dl> <t indent="0" pn="section-3.1-3">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 (<xref target="jumptable" format="default" sectionFormat="of" derivedContent="Table 7"/>).</t> <t indent="0" pn="section-3.1-4">In major types 6 and 7, many of the possible values are reserved for future specification. See <xref target="ianacons" format="default" sectionFormat="of" derivedContent="Section 9"/> for more information on these values.</t> <t indent="0" pn="section-3.1-5"><xref target="major-type-table" format="default" sectionFormat="of" derivedContent="Table 1"/> summarizes the major types defined by CBOR, ignoring <xref target="indefinite" format="default" sectionFormat="of" derivedContent="Section 3.2"/> for now. The number N in this table stands for the argument.</t> <table anchor="major-type-table" align="center" pn="table-1"> <name slugifiedName="name-overview-over-the-definite-">Overview over the Definite-Length Use of CBOR Major Types (N = Argument)</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">Major Type</th> <th align="left" colspan="1" rowspan="1">Meaning</th> <th align="left" colspan="1" rowspan="1">Content</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">0</td> <td align="left" colspan="1" rowspan="1">unsigned integer N</td> <td align="left" colspan="1" rowspan="1">-</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1</td> <td align="left" colspan="1" rowspan="1">negative integer -1-N</td> <td align="left" colspan="1" rowspan="1">-</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">2</td> <td align="left" colspan="1" rowspan="1">byte string</td> <td align="left" colspan="1" rowspan="1">N bytes</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">3</td> <td align="left" colspan="1" rowspan="1">text string</td> <td align="left" colspan="1" rowspan="1">N bytes (UTF-8 text)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">4</td> <td align="left" colspan="1" rowspan="1">array</td> <td align="left" colspan="1" rowspan="1">N data items (elements)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">5</td> <td align="left" colspan="1" rowspan="1">map</td> <td align="left" colspan="1" rowspan="1">2N data items (key/value pairs)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">6</td> <td align="left" colspan="1" rowspan="1">tag of number N</td> <td align="left" colspan="1" rowspan="1">1 data item</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">7</td> <td align="left" colspan="1" rowspan="1">simple/float</td> <td align="left" colspan="1" rowspan="1">-</td> </tr> </tbody> </table> </section> <section anchor="indefinite" toc="include" numbered="true" removeInRFC="false" pn="section-3.2"> <name slugifiedName="name-indefinite-lengths-for-some">Indefinite Lengths for Some Major Types</name> <t indent="0" pn="section-3.2-1">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 ability to start sending a data item before all of it is known is often referred to as "streaming" within that data item.)</t> <t indent="0" pn="section-3.2-2">Indefinite-length arrays and maps are dealt with differently than indefinite-length strings (byte strings and text strings).</t> <section anchor="break" toc="include" numbered="true" removeInRFC="false" pn="section-3.2.1"> <name slugifiedName="name-the-break-stop-code">The "break" Stop Code</name> <t indent="0" pn="section-3.2.1-1">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.</t> <t indent="0" pn="section-3.2.1-2">If the "break" stop code appears 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.</t> </section> <section anchor="indef" toc="include" numbered="true" removeInRFC="false" pn="section-3.2.2"> <name slugifiedName="name-indefinite-length-arrays-an">Indefinite-Length Arrays and Maps</name> <t indent="0" pn="section-3.2.2-1">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 zero or more items for an array or key/value pairs for a map, followed by the "break" stop code (<xref target="break" format="default" sectionFormat="of" derivedContent="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 of 31 and ending with the "break" stop code.</t> <t indent="0" pn="section-3.2.2-2">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.</t> <t indent="0" pn="section-3.2.2-3">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.</t> <t indent="0" pn="section-3.2.2-4">For example, assume an encoder wants to represent the abstract array [1, [2, 3], [4, 5]]. The definite-length encoding would be 0x8301820203820405:</t> <artwork type="hex-dump" align="left" pn="section-3.2.2-5"> 83 -- Array of length 3 01 -- 1 82 -- Array of length 2 02 -- 2 03 -- 3 82 -- Array of length 2 04 -- 4 05 -- 5 </artwork> <t indent="0" pn="section-3.2.2-6">Indefinite-length encoding could be applied independently to each of the three arrays encoded in this data item, as required, leading to representations such as:</t> <artwork type="hex-dump" align="left" pn="section-3.2.2-7"> 0x9f018202039f0405ffff 9F -- Start indefinite-length array 01 -- 1 82 -- Array of length 2 02 -- 2 03 -- 3 9F -- Start indefinite-length array 04 -- 4 05 -- 5 FF -- "break" (inner array) FF -- "break" (outer array) </artwork> <artwork type="hex-dump" align="left" pn="section-3.2.2-8"> 0x9f01820203820405ff 9F -- Start indefinite-length array 01 -- 1 82 -- Array of length 2 02 -- 2 03 -- 3 82 -- Array of length 2 04 -- 4 05 -- 5 FF -- "break" </artwork> <artwork type="hex-dump" align="left" pn="section-3.2.2-9"> 0x83018202039f0405ff 83 -- Array of length 3 01 -- 1 82 -- Array of length 2 02 -- 2 03 -- 3 9F -- Start indefinite-length array 04 -- 4 05 -- 5 FF -- "break" </artwork> <artwork type="hex-dump" align="left" pn="section-3.2.2-10"> 0x83019f0203ff820405 83 -- Array of length 3 01 -- 1 9F -- Start indefinite-length array 02 -- 2 03 -- 3 FF -- "break" 82 -- Array of length 2 04 -- 4 05 -- 5 </artwork> <t indent="0" pn="section-3.2.2-11">An example of an indefinite-length map (that happens to have two key/value pairs) might be:</t> <artwork type="hex-dump" align="left" pn="section-3.2.2-12"> 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" </artwork> </section> <section anchor="indefinite-length-byte-strings-and-text-strings" toc="include" numbered="true" removeInRFC="false" pn="section-3.2.3"> <name slugifiedName="name-indefinite-length-byte-stri">Indefinite-Length Byte Strings and Text Strings</name> <t indent="0" pn="section-3.2.3-1">Indefinite-length strings are represented by a byte containing the major type for byte string or text string with an additional information value of 31, followed by a series of zero or more strings of the specified type ("chunks") that have definite lengths, and finished by the "break" stop code (<xref target="break" format="default" sectionFormat="of" derivedContent="Section 3.2.1"/>). The data item represented by the indefinite-length string is the concatenation of the chunks. If no chunks are present, the data item is an empty string of the specified type. Zero-length chunks, while not particularly useful, are permitted.</t> <t indent="0" pn="section-3.2.3-2">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.</t> <t indent="0" pn="section-3.2.3-3">The design does not allow nesting indefinite-length strings as chunks into indefinite-length strings. If it were allowed, it would require decoder implementations to keep a stack, or at least a count, of nesting levels. It is unnecessary on the encoder side because the inner indefinite-length string would consist of chunks, and these could instead be put directly into the outer indefinite-length string.</t> <t indent="0" pn="section-3.2.3-4">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 UTF-8 bytes of a single Unicode code point (scalar value) cannot be spread between chunks: a new chunk of a text string can only be started at a code point boundary.</t> <t indent="0" pn="section-3.2.3-5">For example, assume an encoded data item consisting of the bytes:</t> <artwork type="hex-dump" align="left" pn="section-3.2.3-6"> 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" </artwork> <t indent="0" pn="section-3.2.3-7">After decoding, this results in a single byte string with seven bytes: 0xaabbccddeeff99.</t> </section> <section anchor="summary-of-indefinite-length-use-of-major-types" toc="include" numbered="true" removeInRFC="false" pn="section-3.2.4"> <name slugifiedName="name-summary-of-indefinite-lengt">Summary of Indefinite-Length Use of Major Types</name> <t indent="0" pn="section-3.2.4-1"><xref target="major-type-indef-table" format="default" sectionFormat="of" derivedContent="Table 2"/> summarizes the major types defined by CBOR as used for indefinite-length encoding (with additional information set to 31).</t> <table anchor="major-type-indef-table" align="center" pn="table-2"> <name slugifiedName="name-overview-of-the-indefinite-">Overview of the Indefinite-Length Use of CBOR Major Types (Additional Information = 31)</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">Major Type</th> <th align="left" colspan="1" rowspan="1">Meaning</th> <th align="left" colspan="1" rowspan="1">Enclosed up to "break" Stop Code</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">0</td> <td align="left" colspan="1" rowspan="1">(not well-formed)</td> <td align="left" colspan="1" rowspan="1">-</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1</td> <td align="left" colspan="1" rowspan="1">(not well-formed)</td> <td align="left" colspan="1" rowspan="1">-</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">2</td> <td align="left" colspan="1" rowspan="1">byte string</td> <td align="left" colspan="1" rowspan="1">definite-length byte strings</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">3</td> <td align="left" colspan="1" rowspan="1">text string</td> <td align="left" colspan="1" rowspan="1">definite-length text strings</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">4</td> <td align="left" colspan="1" rowspan="1">array</td> <td align="left" colspan="1" rowspan="1">data items (elements)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">5</td> <td align="left" colspan="1" rowspan="1">map</td> <td align="left" colspan="1" rowspan="1">data items (key/value pairs)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">6</td> <td align="left" colspan="1" rowspan="1">(not well-formed)</td> <td align="left" colspan="1" rowspan="1">-</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">7</td> <td align="left" colspan="1" rowspan="1">"break" stop code</td> <td align="left" colspan="1" rowspan="1">-</td> </tr> </tbody> </table> </section> </section> <section anchor="fpnocont" toc="include" numbered="true" removeInRFC="false" pn="section-3.3"> <name slugifiedName="name-floating-point-numbers-and-">Floating-Point Numbers and Values with No Content</name> <t indent="0" pn="section-3.3-1">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 <xref target="fpnoconttbl" format="default" sectionFormat="of" derivedContent="Table 3"/>. Like the major types for integers, items of this major type do not carry content data; all the information is in the initial bytes (the head).</t> <table anchor="fpnoconttbl" align="center" pn="table-3"> <name slugifiedName="name-values-for-additional-infor">Values for Additional Information in Major Type 7</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">5-Bit Value</th> <th align="left" colspan="1" rowspan="1">Semantics</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">0..23</td> <td align="left" colspan="1" rowspan="1">Simple value (value 0..23)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">24</td> <td align="left" colspan="1" rowspan="1">Simple value (value 32..255 in following byte)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">25</td> <td align="left" colspan="1" rowspan="1">IEEE 754 Half-Precision Float (16 bits follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">26</td> <td align="left" colspan="1" rowspan="1">IEEE 754 Single-Precision Float (32 bits follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">27</td> <td align="left" colspan="1" rowspan="1">IEEE 754 Double-Precision Float (64 bits follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">28-30</td> <td align="left" colspan="1" rowspan="1">Reserved, not well-formed in the present document</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">31</td> <td align="left" colspan="1" rowspan="1">"break" stop code for indefinite-length items (<xref target="break" format="default" sectionFormat="of" derivedContent="Section 3.2.1"/>)</td> </tr> </tbody> </table> <t indent="0" pn="section-3.3-3">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. <xref target="fpnoconttbl2" format="default" sectionFormat="of" derivedContent="Table 4"/> lists the numeric values assigned and available for simple values.</t> <table anchor="fpnoconttbl2" align="center" pn="table-4"> <name slugifiedName="name-simple-values">Simple Values</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">Value</th> <th align="left" colspan="1" rowspan="1">Semantics</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">0..19</td> <td align="left" colspan="1" rowspan="1">(unassigned)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">20</td> <td align="left" colspan="1" rowspan="1">false</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">21</td> <td align="left" colspan="1" rowspan="1">true</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">22</td> <td align="left" colspan="1" rowspan="1">null</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">23</td> <td align="left" colspan="1" rowspan="1">undefined</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">24..31</td> <td align="left" colspan="1" rowspan="1">(reserved)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">32..255</td> <td align="left" colspan="1" rowspan="1">(unassigned)</td> </tr> </tbody> </table> <t indent="0" pn="section-3.3-5">An encoder <bcp14>MUST NOT</bcp14> issue two-byte sequences that start with 0xf8 (major type 7, additional information 24) and continue with a byte less than 0x20 (32 decimal). Such sequences are not well-formed. (This implies that an encoder cannot encode <tt>false</tt>, <tt>true</tt>, <tt>null</tt>, or <tt>undefined</tt> in two-byte sequences and that only the one-byte variants of these are well-formed; more generally speaking, each simple value only has a single representation variant).</t> <t indent="0" pn="section-3.3-6">The 5-bit values of 25, 26, and 27 are for 16-bit, 32-bit, and 64-bit IEEE 754 binary floating-point values <xref target="IEEE754" format="default" sectionFormat="of" derivedContent="IEEE754"/>. These floating-point values are encoded in the additional bytes of the appropriate size. (See <xref target="half-precision" format="default" sectionFormat="of" derivedContent="Appendix D"/> for some information about 16-bit floating-point numbers.)</t> </section> <section anchor="tags" toc="include" numbered="true" removeInRFC="false" pn="section-3.4"> <name slugifiedName="name-tagging-of-items">Tagging of Items</name> <t indent="0" pn="section-3.4-1">In CBOR, a data item can be enclosed by a tag to give it some additional semantics, as uniquely identified by a <em>tag number</em>. The tag is major type 6, its argument (<xref target="encoding" format="default" sectionFormat="of" derivedContent="Section 3"/>) indicates the tag number, and it contains a single enclosed data item, the <em>tag content</em>. (If a tag requires further structure to its content, this structure is provided by the enclosed data item.) We use the term <em>tag</em> for the entire data item consisting of both a tag number and the tag content: the tag content is the data item that is being tagged.</t> <t indent="0" pn="section-3.4-2">For example, assume that a byte string of length 12 is marked with a tag of number 2 to indicate it is an unsigned <em>bignum</em> (<xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/>). The encoded data item would start with a byte 0b110_00010 (major type 6, additional information 2 for the tag number) followed by the encoded tag content: 0b010_01100 (major type 2, additional information 12 for the length) followed by the 12 bytes of the bignum.</t> <t indent="0" pn="section-3.4-3">In the extended generic data model, a tag number's definition describes the additional semantics conveyed with the tag number. These semantics may include equivalence of some tagged data items with other data items, including some that can be represented in the basic generic data model. For instance, 0xc24101, a bignum the tag content of which is the byte string with the single byte 0x01, is equivalent to an integer 1, which could also be encoded as 0x01, 0x1801, or 0x190001. The tag definition may specify a preferred serialization (<xref target="preferred" format="default" sectionFormat="of" derivedContent="Section 4.1"/>) that is recommended for generic encoders; this may prefer basic generic data model representations over ones that employ a tag.</t> <t indent="0" pn="section-3.4-4">The tag definition usually defines which nested data items are valid for such tags. Tag definitions may restrict their content to a very specific syntactic structure, as the tags defined in this document do, or they may define their content more semantically. An example for the latter is how tags 40 and 1040 accept multiple ways to represent arrays <xref target="RFC8746" format="default" sectionFormat="of" derivedContent="RFC8746"/>. </t> <t indent="0" pn="section-3.4-5">As a matter of convention, many tags do not accept <tt>null</tt> or <tt>undefined</tt> values as tag content; instead, the expectation is that a <tt>null</tt> or <tt>undefined</tt> value can be used in place of the entire tag; <xref target="epochdatetimesect" format="default" sectionFormat="of" derivedContent="Section 3.4.2"/> provides some further considerations for one specific tag about the handling of this convention in application protocols and in mapping to platform types.</t> <t indent="0" pn="section-3.4-6">Decoders do not need to understand tags of every tag number, and tags may be of little value in applications where the implementation creating a particular CBOR data item and the implementation decoding that stream know the semantic meaning of each item in the data flow. The primary purpose of tags in this specification is to define common data types such as dates. A secondary purpose is to provide conversion hints when it is foreseen that the CBOR data item needs to be translated into a different format, requiring hints about the content of items. Understanding the semantics of tags is optional for a decoder; it can simply present both the tag number and the tag content to the application, without interpreting the additional semantics of the tag.</t> <t indent="0" pn="section-3.4-7">A tag applies semantics to the data item it encloses. Tags can nest: if tag A encloses tag B, which encloses data item C, tag A applies to the result of applying tag B on data item C.</t> <t indent="0" pn="section-3.4-8">IANA maintains a registry of tag numbers as described in <xref target="ianatags" format="default" sectionFormat="of" derivedContent="Section 9.2"/>. <xref target="tagvalues" format="default" sectionFormat="of" derivedContent="Table 5"/> provides a list of tag numbers that were defined in <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/> with definitions in the rest of this section. (Tag number 35 was also defined in <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/>; a discussion of this tag number follows in <xref target="encodedtext" format="default" sectionFormat="of" derivedContent="Section 3.4.5.3"/>.) Note that many other tag numbers have been defined since the publication of <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/>; see the registry described at <xref target="ianatags" format="default" sectionFormat="of" derivedContent="Section 9.2"/> for the complete list.</t> <table anchor="tagvalues" align="center" pn="table-5"> <name slugifiedName="name-tag-numbers-defined-in-rfc-">Tag Numbers Defined in RFC 7049</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">Tag</th> <th align="left" colspan="1" rowspan="1">Data Item</th> <th align="left" colspan="1" rowspan="1">Semantics</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">0</td> <td align="left" colspan="1" rowspan="1">text string</td> <td align="left" colspan="1" rowspan="1">Standard date/time string; see <xref target="stringdatetimesect" format="default" sectionFormat="of" derivedContent="Section 3.4.1"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1</td> <td align="left" colspan="1" rowspan="1">integer or float</td> <td align="left" colspan="1" rowspan="1">Epoch-based date/time; see <xref target="epochdatetimesect" format="default" sectionFormat="of" derivedContent="Section 3.4.2"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">2</td> <td align="left" colspan="1" rowspan="1">byte string</td> <td align="left" colspan="1" rowspan="1">Unsigned bignum; see <xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">3</td> <td align="left" colspan="1" rowspan="1">byte string</td> <td align="left" colspan="1" rowspan="1">Negative bignum; see <xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">4</td> <td align="left" colspan="1" rowspan="1">array</td> <td align="left" colspan="1" rowspan="1">Decimal fraction; see <xref target="fractions" format="default" sectionFormat="of" derivedContent="Section 3.4.4"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">5</td> <td align="left" colspan="1" rowspan="1">array</td> <td align="left" colspan="1" rowspan="1">Bigfloat; see <xref target="fractions" format="default" sectionFormat="of" derivedContent="Section 3.4.4"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">21</td> <td align="left" colspan="1" rowspan="1">(any)</td> <td align="left" colspan="1" rowspan="1">Expected conversion to base64url encoding; see <xref target="convexpect" format="default" sectionFormat="of" derivedContent="Section 3.4.5.2"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">22</td> <td align="left" colspan="1" rowspan="1">(any)</td> <td align="left" colspan="1" rowspan="1">Expected conversion to base64 encoding; see <xref target="convexpect" format="default" sectionFormat="of" derivedContent="Section 3.4.5.2"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">23</td> <td align="left" colspan="1" rowspan="1">(any)</td> <td align="left" colspan="1" rowspan="1">Expected conversion to base16 encoding; see <xref target="convexpect" format="default" sectionFormat="of" derivedContent="Section 3.4.5.2"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">24</td> <td align="left" colspan="1" rowspan="1">byte string</td> <td align="left" colspan="1" rowspan="1">Encoded CBOR data item; see <xref target="embedded-di" format="default" sectionFormat="of" derivedContent="Section 3.4.5.1"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">32</td> <td align="left" colspan="1" rowspan="1">text string</td> <td align="left" colspan="1" rowspan="1">URI; see <xref target="encodedtext" format="default" sectionFormat="of" derivedContent="Section 3.4.5.3"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">33</td> <td align="left" colspan="1" rowspan="1">text string</td> <td align="left" colspan="1" rowspan="1">base64url; see <xref target="encodedtext" format="default" sectionFormat="of" derivedContent="Section 3.4.5.3"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">34</td> <td align="left" colspan="1" rowspan="1">text string</td> <td align="left" colspan="1" rowspan="1">base64; see <xref target="encodedtext" format="default" sectionFormat="of" derivedContent="Section 3.4.5.3"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">36</td> <td align="left" colspan="1" rowspan="1">text string</td> <td align="left" colspan="1" rowspan="1">MIME message; see <xref target="encodedtext" format="default" sectionFormat="of" derivedContent="Section 3.4.5.3"/></td> </tr> <tr> <td align="left" colspan="1" rowspan="1">55799</td> <td align="left" colspan="1" rowspan="1">(any)</td> <td align="left" colspan="1" rowspan="1">Self-described CBOR; see <xref target="self-describe" format="default" sectionFormat="of" derivedContent="Section 3.4.6"/></td> </tr> </tbody> </table> <t indent="0" pn="section-3.4-10">Conceptually, tags are interpreted in the generic data model, not at (de-)serialization time. A small number of tags (at this time, tag number 25 and tag number 29 <xref target="IANA.cbor-tags" format="default" sectionFormat="of" derivedContent="IANA.cbor-tags"/>) have been registered with semantics that may require processing at (de-)serialization time: the decoder needs to be aware of, and the encoder needs to be in control of, the exact sequence in which data items are encoded into the CBOR data item. This means these tags cannot be implemented on top of an arbitrary generic CBOR encoder/decoder (which might not reflect the serialization order for entries in a map at the data model level and vice versa); their implementation therefore typically needs to be integrated into the generic encoder/decoder. The definition of new tags with this property is <bcp14>NOT RECOMMENDED</bcp14>.</t> <t indent="0" pn="section-3.4-11">IANA allocated tag numbers 65535, 4294967295, and 18446744073709551615 (binary all-ones in 16-bit, 32-bit, and 64-bit). These can be used as a convenience for implementers who want a single-integer data structure to indicate either the presence of a specific tag or absence of a tag. That allocation is described in <xref target="I-D.bormann-cbor-notable-tags" section="10" sectionFormat="of" format="default" derivedLink="https://tools.ietf.org/html/draft-bormann-cbor-notable-tags-02#section-10" derivedContent="CBOR-TAGS"/>. These tags are not intended to occur in actual CBOR data items; implementations <bcp14>MAY</bcp14> flag such an occurrence as an error.</t> <t indent="0" pn="section-3.4-12">Protocols can extend the generic data model (<xref target="cbor-data-models" format="default" sectionFormat="of" derivedContent="Section 2"/>) with data items representing points in time by using tag numbers 0 and 1, with arbitrarily sized integers by using tag numbers 2 and 3, and with floating-point values of arbitrary size and precision by using tag numbers 4 and 5.</t> <section anchor="stringdatetimesect" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.1"> <name slugifiedName="name-standard-date-time-string">Standard Date/Time String</name> <t indent="0" pn="section-3.4.1-1">Tag number 0 contains a text string in the standard format described by the <tt>date-time</tt> production in <xref target="RFC3339" format="default" sectionFormat="of" derivedContent="RFC3339"/>, as refined by <xref target="RFC4287" section="3.3" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4287#section-3.3" derivedContent="RFC4287"/>, representing the point in time described there. A nested item of another type or a text string that doesn't match the format described in <xref target="RFC4287" format="default" sectionFormat="of" derivedContent="RFC4287"/> is invalid.</t> </section> <section anchor="epochdatetimesect" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.2"> <name slugifiedName="name-epoch-based-date-time">Epoch-Based Date/Time</name> <t indent="0" pn="section-3.4.2-1">Tag number 1 contains a numerical value counting the number of seconds from 1970-01-01T00:00Z in UTC time to the represented point in civil time.</t> <t indent="0" pn="section-3.4.2-2">The tag content <bcp14>MUST</bcp14> be an unsigned or negative integer (major types 0 and 1) or a floating-point number (major type 7 with additional information 25, 26, or 27). Other contained types are invalid.</t> <t indent="0" pn="section-3.4.2-3">Nonnegative values (major type 0 and nonnegative floating-point numbers) stand for time values on or after 1970-01-01T00:00Z UTC and are interpreted according to POSIX <xref target="TIME_T" format="default" sectionFormat="of" derivedContent="TIME_T"/>. (POSIX time is also known as "UNIX Epoch time".) 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 tag content.</t> <t indent="0" pn="section-3.4.2-4">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). The same applies to non-finite values.</t> <t indent="0" pn="section-3.4.2-5">To indicate fractional seconds, floating-point values can be used within tag number 1 instead of integer values. Note that this generally requires binary64 support, as binary16 and binary32 provide nonzero fractions of seconds only for a short period of time around early 1970. An application that requires tag number 1 support may restrict the tag content to be an integer (or a floating-point value) only.</t> <t indent="0" pn="section-3.4.2-6">Note that platform types for date/time may include <tt>null</tt> or <tt>undefined</tt> values, which may also be desirable at an application protocol level. While emitting tag number 1 values with non-finite tag content values (e.g., with NaN for undefined date/time values or with Infinity for an expiry date that is not set) may seem an obvious way to handle this, using untagged <tt>null</tt> or <tt>undefined</tt> avoids the use of non-finites and results in a shorter encoding. Application protocol designers are encouraged to consider these cases and include clear guidelines for handling them.</t> </section> <section anchor="bignums" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.3"> <name slugifiedName="name-bignums">Bignums</name> <t indent="0" pn="section-3.4.3-1">Protocols using tag numbers 2 and 3 extend the generic data model (<xref target="cbor-data-models" format="default" sectionFormat="of" derivedContent="Section 2"/>) with "bignums" representing arbitrarily sized integers. In the basic generic data model, bignum values are not equal to integers from the same model, but the extended generic data model created by this tag definition defines equivalence based on numeric value, and preferred serialization (<xref target="preferred" format="default" sectionFormat="of" derivedContent="Section 4.1"/>) never makes use of bignums that also can be expressed as basic integers (see below).</t> <t indent="0" pn="section-3.4.3-2">Bignums are encoded as a byte string data item, which is interpreted as an unsigned integer n in network byte order. Contained items of other types are invalid. For tag number 2, the value of the bignum is n. For tag number 3, the value of the bignum is -1 - n. The preferred serialization of the byte string is to leave out any leading zeroes (note that this means the preferred serialization for n = 0 is the empty byte string, but see below). Decoders that understand these tags <bcp14>MUST</bcp14> be able to decode bignums that do have leading zeroes. The preferred serialization 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 serialization). 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).</t> <t indent="0" pn="section-3.4.3-3">For example, the number 18446744073709551616 (2<sup>64</sup>) is represented as 0b110_00010 (major type 6, tag number 2), followed by 0b010_01001 (major type 2, length 9), followed by 0x010000000000000000 (one byte 0x01 and eight bytes 0x00). In hexadecimal:</t> <artwork type="hex-dump" align="left" pn="section-3.4.3-4"> C2 -- Tag 2 49 -- Byte string of length 9 010000000000000000 -- Bytes content </artwork> </section> <section anchor="fractions" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.4"> <name slugifiedName="name-decimal-fractions-and-bigfl">Decimal Fractions and Bigfloats</name> <t indent="0" pn="section-3.4.4-1">Protocols using tag number 4 extend the generic data model with data items representing arbitrary-length decimal fractions of the form m*(10<sup>e</sup>). Protocols using tag number 5 extend the generic data model with data items representing arbitrary-length binary fractions of the form m*(2<sup>e</sup>). As with bignums, values of different types are not equal in the generic data model.</t> <t indent="0" pn="section-3.4.4-2">Decimal fractions combine an integer mantissa with a base-10 scaling factor. They are most useful if an application needs the exact representation of a decimal fraction such as 1.1 because there is no exact representation for many decimal fractions in binary floating-point representations.</t> <t indent="0" pn="section-3.4.4-3">"Bigfloats" combine an integer mantissa with a base-2 scaling factor. They are binary floating-point values that can exceed the range or the precision of the three IEEE 754 formats supported by CBOR (<xref target="fpnocont" format="default" sectionFormat="of" derivedContent="Section 3.3"/>). Bigfloats may also be used by constrained applications that need some basic binary floating-point capability without the need for supporting IEEE 754.</t> <t indent="0" pn="section-3.4.4-4">A decimal fraction or a bigfloat is represented as a tagged array that contains exactly two integer numbers: an exponent e and a mantissa m. Decimal fractions (tag number 4) use base-10 exponents; the value of a decimal fraction data item is m*(10<sup>e</sup>). Bigfloats (tag number 5) use base-2 exponents; the value of a bigfloat data item is m*(2<sup>e</sup>). The exponent e <bcp14>MUST</bcp14> be represented in an integer of major type 0 or 1, while the mantissa can also be a bignum (<xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/>). Contained items with other structures are invalid.</t> <t indent="0" pn="section-3.4.4-5">An example of a decimal fraction is the representation of the number 273.15 as 0b110_00100 (major type 6 for tag, additional information 4 for the tag number), followed by 0b100_00010 (major type 4 for the array, additional information 2 for the length of the array), followed by 0b001_00001 (major type 1 for the first integer, additional information 1 for the value of -2), followed by 0b000_11001 (major type 0 for the second integer, additional information 25 for a two-byte value), followed by 0b0110101010110011 (27315 in two bytes). In hexadecimal:</t> <artwork type="hex-dump" align="left" pn="section-3.4.4-6"> C4 -- Tag 4 82 -- Array of length 2 21 -- -2 19 6ab3 -- 27315 </artwork> <t indent="0" pn="section-3.4.4-7">An example of a bigfloat is the representation of the number 1.5 as 0b110_00101 (major type 6 for tag, additional information 5 for the tag number), followed by 0b100_00010 (major type 4 for the array, additional information 2 for the length of the array), followed by 0b001_00000 (major type 1 for the first integer, additional information 0 for the value of -1), followed by 0b000_00011 (major type 0 for the second integer, additional information 3 for the value of 3). In hexadecimal:</t> <artwork type="hex-dump" align="left" pn="section-3.4.4-8"> C5 -- Tag 5 82 -- Array of length 2 20 -- -1 03 -- 3 </artwork> <t indent="0" pn="section-3.4.4-9">Decimal fractions and bigfloats provide no representation of Infinity, -Infinity, or NaN; if these are needed in place of a decimal fraction or bigfloat, the IEEE 754 half-precision representations from <xref target="fpnocont" format="default" sectionFormat="of" derivedContent="Section 3.3"/> can be used.</t> </section> <section anchor="content-hints" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.5"> <name slugifiedName="name-content-hints">Content Hints</name> <t indent="0" pn="section-3.4.5-1">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.</t> <section anchor="embedded-di" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.5.1"> <name slugifiedName="name-encoded-cbor-data-item">Encoded CBOR Data Item</name> <t indent="0" pn="section-3.4.5.1-1">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 decoded. Tag number 24 (CBOR data item) can be used to tag the embedded byte string as a single data item encoded in CBOR format. Contained items that aren't byte strings are invalid. A contained byte string is valid if it encodes a well-formed CBOR data item; validity checking of the decoded CBOR item is not required for tag validity (but could be offered by a generic decoder as a special option).</t> </section> <section anchor="convexpect" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.5.2"> <name slugifiedName="name-expected-later-encoding-for">Expected Later Encoding for CBOR-to-JSON Converters</name> <t indent="0" pn="section-3.4.5.2-1">Tag numbers 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.</t> <t indent="0" pn="section-3.4.5.2-2">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.</t> <t indent="0" pn="section-3.4.5.2-3">These three tag numbers suggest conversions to three of the base data encodings defined in <xref target="RFC4648" format="default" sectionFormat="of" derivedContent="RFC4648"/>. Tag number 21 suggests conversion to base64url encoding (<xref target="RFC4648" section="5" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4648#section-5" derivedContent="RFC4648"/>) where padding is not used (see <xref target="RFC4648" section="3.2" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4648#section-3.2" derivedContent="RFC4648"/>); that is, all trailing equals signs ("=") are removed from the encoded string. Tag number 22 suggests conversion to classical base64 encoding (<xref target="RFC4648" section="4" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4648#section-4" derivedContent="RFC4648"/>) with padding as defined in RFC 4648. For both base64url and base64, padding bits are set to zero (see <xref target="RFC4648" section="3.5" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4648#section-3.5" derivedContent="RFC4648"/>), and the conversion to alternate encoding is performed on the contents of the byte string (that is, without adding any line breaks, whitespace, or other additional characters). Tag number 23 suggests conversion to base16 (hex) encoding with uppercase alphabetics (see <xref target="RFC4648" section="8" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4648#section-8" derivedContent="RFC4648"/>). Note that, for all three tag numbers, the encoding of the empty byte string is the empty text string.</t> </section> <section anchor="encodedtext" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.5.3"> <name slugifiedName="name-encoded-text">Encoded Text</name> <t indent="0" pn="section-3.4.5.3-1">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.</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-3.4.5.3-2"> <li pn="section-3.4.5.3-2.1">Tag number 32 is for URIs, as defined in <xref target="RFC3986" format="default" sectionFormat="of" derivedContent="RFC3986"/>. If the text string doesn't match the <tt>URI-reference</tt> production, the string is invalid.</li> <li pn="section-3.4.5.3-2.2"> <t indent="0" pn="section-3.4.5.3-2.2.1">Tag numbers 33 and 34 are for base64url- and base64-encoded text strings, respectively, as defined in <xref target="RFC4648" format="default" sectionFormat="of" derivedContent="RFC4648"/>. If any of the following apply: </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-3.4.5.3-2.2.2"> <li pn="section-3.4.5.3-2.2.2.1">the encoded text string contains non-alphabet characters or only 1 alphabet character in the last block of 4 (where alphabet is defined by <xref target="RFC4648" section="5" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4648#section-5" derivedContent="RFC4648"/> for tag number 33 and <xref target="RFC4648" section="4" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4648#section-4" derivedContent="RFC4648"/> for tag number 34), or</li> <li pn="section-3.4.5.3-2.2.2.2">the padding bits in a 2- or 3-character block are not 0, or</li> <li pn="section-3.4.5.3-2.2.2.3">the base64 encoding has the wrong number of padding characters, or</li> <li pn="section-3.4.5.3-2.2.2.4">the base64url encoding has padding characters,</li> </ul> <t indent="0" pn="section-3.4.5.3-2.2.3"> the string is invalid.</t> </li> <li pn="section-3.4.5.3-2.3">Tag number 36 is for MIME messages (including all headers), as defined in <xref target="RFC2045" format="default" sectionFormat="of" derivedContent="RFC2045"/>. A text string that isn't a valid MIME message is invalid. (For this tag, validity checking may be particularly onerous for a generic decoder and might therefore not be offered. Note that many MIME messages are general binary data and therefore cannot be represented in a text string; <xref target="IANA.cbor-tags" format="default" sectionFormat="of" derivedContent="IANA.cbor-tags"/> lists a registration for tag number 257 that is similar to tag number 36 but uses a byte string as its tag content.)</li> </ul> <t indent="0" pn="section-3.4.5.3-3">Note that tag numbers 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.</t> <t indent="0" pn="section-3.4.5.3-4"><xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/> also defined a tag number 35 for regular expressions that are in Perl Compatible Regular Expressions (PCRE/PCRE2) form <xref target="PCRE" format="default" sectionFormat="of" derivedContent="PCRE"/> or in JavaScript regular expression syntax <xref target="ECMA262" format="default" sectionFormat="of" derivedContent="ECMA262"/>. The state of the art in these regular expression specifications has since advanced and is continually advancing, so this specification does not attempt to update the references. Instead, this tag remains available (as registered in <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/>) for applications that specify the particular regular expression variant they use out-of-band (possibly by limiting the usage to a defined common subset of both PCRE and ECMA262). As this specification clarifies tag validity beyond <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/>, we note that due to the open way the tag was defined in <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/>, any contained string value needs to be valid at the CBOR tag level (but then may not be "expected" at the application level).</t> </section> </section> <section anchor="self-describe" toc="include" numbered="true" removeInRFC="false" pn="section-3.4.6"> <name slugifiedName="name-self-described-cbor">Self-Described CBOR</name> <t indent="0" pn="section-3.4.6-1">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 that does not have disambiguating metadata. Here, it may help to have some distinguishing characteristics for the data itself.</t> <t indent="0" pn="section-3.4.6-2">Tag number 55799 is defined for this purpose, specifically for use at the start of a stored encoded CBOR data item as specified by an application. It does not impart any special semantics on the data item that it encloses; that is, the semantics of the tag content enclosed in tag number 55799 is exactly identical to the semantics of the tag content itself.</t> <t indent="0" pn="section-3.4.6-3">The serialization of this tag's head is 0xd9d9f7, which does not appear to be in use as a distinguishing mark for any frequently used file types. In particular, 0xd9d9f7 is not a valid start of a Unicode text in any Unicode encoding if it is followed by a valid CBOR data item.</t> <t indent="0" pn="section-3.4.6-4">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 number 55799, the serialization of which will never be found at the beginning of a JSON text.</t> </section> </section> </section> <section anchor="serialization-considerations" toc="include" numbered="true" removeInRFC="false" pn="section-4"> <name slugifiedName="name-serialization-consideration">Serialization Considerations</name> <section anchor="preferred" toc="include" numbered="true" removeInRFC="false" pn="section-4.1"> <name slugifiedName="name-preferred-serialization">Preferred Serialization</name> <t indent="0" pn="section-4.1-1">For some values at the data model level, CBOR provides multiple serializations. For many applications, it is desirable that an encoder always chooses a preferred serialization (preferred encoding); however, the present specification does not put the burden of enforcing this preference on either the encoder or decoder.</t> <t indent="0" pn="section-4.1-2">Some constrained decoders may be limited in their ability to decode non-preferred serializations: for example, if only integers below 1_000_000_000 (one billion) are expected in an application, the decoder may leave out the code that would be needed to decode 64-bit arguments in integers. An encoder that always uses preferred serialization ("preferred encoder") interoperates with this decoder for the numbers that can occur in this application. Generally speaking, a preferred encoder is more universally interoperable (and also less wasteful) than one that, say, always uses 64-bit integers.</t> <t indent="0" pn="section-4.1-3">Similarly, a constrained encoder may be limited in the variety of representation variants it supports such that it does not emit preferred serializations ("variant encoder"). For instance, a constrained encoder could be designed to always use the 32-bit variant for an integer that it encodes even if a short representation is available (assuming that there is no application need for integers that can only be represented with the 64-bit variant). A decoder that does not rely on receiving only preferred serializations ("variation-tolerant decoder") can therefore be said to be more universally interoperable (it might very well optimize for the case of receiving preferred serializations, though). Full implementations of CBOR decoders are by definition variation tolerant; the distinction is only relevant if a constrained implementation of a CBOR decoder meets a variant encoder.</t> <t indent="0" pn="section-4.1-4">The preferred serialization always uses the shortest form of representing the argument (<xref target="encoding" format="default" sectionFormat="of" derivedContent="Section 3"/>); it also uses the shortest floating-point encoding that preserves the value being encoded.</t> <t indent="0" pn="section-4.1-5">The preferred serialization for a floating-point value is the shortest floating-point encoding that preserves its value, e.g., 0xf94580 for the number 5.5, and 0xfa45ad9c00 for the number 5555.5. For NaN values, a shorter encoding is preferred if zero-padding the shorter significand towards the right reconstitutes the original NaN value (for many applications, the single NaN encoding 0xf97e00 will suffice).</t> <t indent="0" pn="section-4.1-6">Definite-length encoding is preferred whenever the length is known at the time the serialization of the item starts.</t> </section> <section anchor="det-enc" toc="include" numbered="true" removeInRFC="false" pn="section-4.2"> <name slugifiedName="name-deterministically-encoded-c">Deterministically Encoded CBOR</name> <t indent="0" pn="section-4.2-1">Some protocols may want encoders to only emit CBOR in a particular deterministic format; those protocols might also have the decoders check that their input is in that deterministic format. Those protocols are free to define what they mean by a "deterministic 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 deterministic format.</t> <section anchor="core-det" toc="include" numbered="true" removeInRFC="false" pn="section-4.2.1"> <name slugifiedName="name-core-deterministic-encoding">Core Deterministic Encoding Requirements</name> <t indent="0" pn="section-4.2.1-1">A CBOR encoding satisfies the "core deterministic encoding requirements" if it satisfies the following restrictions:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-4.2.1-2"> <li pn="section-4.2.1-2.1"> <t indent="0" pn="section-4.2.1-2.1.1">Preferred serialization <bcp14>MUST</bcp14> be used. In particular, this means that arguments (see <xref target="encoding" format="default" sectionFormat="of" derivedContent="Section 3"/>) for integers, lengths in major types 2 through 5, and tags <bcp14>MUST</bcp14> be as short as possible, for instance: </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-4.2.1-2.1.2"> <li pn="section-4.2.1-2.1.2.1">0 to 23 and -1 to -24 <bcp14>MUST</bcp14> be expressed in the same byte as the major type;</li> <li pn="section-4.2.1-2.1.2.2">24 to 255 and -25 to -256 <bcp14>MUST</bcp14> be expressed only with an additional uint8_t;</li> <li pn="section-4.2.1-2.1.2.3">256 to 65535 and -257 to -65536 <bcp14>MUST</bcp14> be expressed only with an additional uint16_t;</li> <li pn="section-4.2.1-2.1.2.4">65536 to 4294967295 and -65537 to -4294967296 <bcp14>MUST</bcp14> be expressed only with an additional uint32_t.</li> </ul> <t indent="0" pn="section-4.2.1-2.1.3"> Floating-point values also <bcp14>MUST</bcp14> use the shortest form that preserves the value, e.g., 1.5 is encoded as 0xf93e00 (binary16) and 1000000.5 as 0xfa49742408 (binary32). (One implementation of this is 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 value, use the shorter form and repeat the process with a test conversion to a 16-bit float. This also works to select 16-bit float for positive and negative Infinity as well.)</t> </li> <li pn="section-4.2.1-2.2">Indefinite-length items <bcp14>MUST NOT</bcp14> appear. They can be encoded as definite-length items instead.</li> <li pn="section-4.2.1-2.3"> <t indent="0" pn="section-4.2.1-2.3.1">The keys in every map <bcp14>MUST</bcp14> be sorted in the bytewise lexicographic order of their deterministic encodings. For example, the following keys are sorted correctly: </t> <ol spacing="normal" type="1" indent="adaptive" start="1" pn="section-4.2.1-2.3.2"><li pn="section-4.2.1-2.3.2.1" derivedCounter="1.">10, encoded as 0x0a.</li> <li pn="section-4.2.1-2.3.2.2" derivedCounter="2.">100, encoded as 0x1864.</li> <li pn="section-4.2.1-2.3.2.3" derivedCounter="3.">-1, encoded as 0x20.</li> <li pn="section-4.2.1-2.3.2.4" derivedCounter="4.">"z", encoded as 0x617a.</li> <li pn="section-4.2.1-2.3.2.5" derivedCounter="5.">"aa", encoded as 0x626161.</li> <li pn="section-4.2.1-2.3.2.6" derivedCounter="6.">[100], encoded as 0x811864.</li> <li pn="section-4.2.1-2.3.2.7" derivedCounter="7.">[-1], encoded as 0x8120.</li> <li pn="section-4.2.1-2.3.2.8" derivedCounter="8.">false, encoded as 0xf4.</li> </ol> </li> </ul> <aside pn="section-4.2.1-3"> <t indent="0" pn="section-4.2.1-3.1"> Implementation note: the self-delimiting nature of the CBOR encoding means that there are no two well-formed CBOR encoded data items where one is a prefix of the other. The bytewise lexicographic comparison of deterministic encodings of different map keys therefore always ends in a position where the byte differs between the keys, before the end of a key is reached.</t> </aside> </section> <section anchor="additional-deterministic-encoding-considerations" toc="include" numbered="true" removeInRFC="false" pn="section-4.2.2"> <name slugifiedName="name-additional-deterministic-en">Additional Deterministic Encoding Considerations</name> <t indent="0" pn="section-4.2.2-1">CBOR tags present additional considerations for deterministic encoding. If a CBOR-based protocol were to provide the same semantics for the presence and absence of a specific tag (e.g., by allowing both tag 1 data items and raw numbers in a date/time position, treating the latter as if they were tagged), the deterministic format would not allow the presence of the tag, based on the "shortest form" principle. For example, a protocol might give encoders the choice of representing a URL as either a text string or, using <xref target="encodedtext" format="default" sectionFormat="of" derivedContent="Section 3.4.5.3"/>, tag number 32 containing a text string. This protocol's deterministic encoding needs either to require that the tag is present or to require that it is absent, not allow either one.</t> <t indent="0" pn="section-4.2.2-2">In a protocol that does require tags in certain places to obtain specific semantics, the tag needs to appear in the deterministic format as well. Deterministic encoding considerations also apply to the content of tags.</t> <t indent="0" pn="section-4.2.2-3">If a protocol includes a field that can express integers with an absolute value of 2<sup>64</sup> or larger using tag numbers 2 or 3 (<xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/>), the protocol's deterministic encoding needs to specify whether smaller integers are also expressed using these tags or using major types 0 and 1. Preferred serialization uses the latter choice, which is therefore recommended.</t> <t indent="0" pn="section-4.2.2-4">Protocols that include floating-point values, whether represented using basic floating-point values (<xref target="fpnocont" format="default" sectionFormat="of" derivedContent="Section 3.3"/>) or using tags (or both), may need to define extra requirements on their deterministic encodings, such as:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-4.2.2-5"> <li pn="section-4.2.2-5.1">Although IEEE floating-point values can represent both positive and negative zero as distinct values, the application might not distinguish these and might decide to represent all zero values with a positive sign, disallowing negative zero. (The application may also want to restrict the precision of floating-point values in such a way that there is never a need to represent 64-bit -- or even 32-bit -- floating-point values.)</li> <li pn="section-4.2.2-5.2"> <t indent="0" pn="section-4.2.2-5.2.1">If a protocol includes a field that can express floating-point values, with a specific data model that declares integer and floating-point values to be interchangeable, the protocol's deterministic encoding needs to specify whether, for example, the integer 1.0 is encoded as 0x01 (unsigned integer), 0xf93c00 (binary16), 0xfa3f800000 (binary32), or 0xfb3ff0000000000000 (binary64). Example rules for this are: </t> <ol spacing="normal" type="1" indent="adaptive" start="1" pn="section-4.2.2-5.2.2"><li pn="section-4.2.2-5.2.2.1" derivedCounter="1.">Encode integral values that fit in 64 bits as values from major types 0 and 1, and other values as the preferred (smallest of 16-, 32-, or 64-bit) floating-point representation that accurately represents the value,</li> <li pn="section-4.2.2-5.2.2.2" derivedCounter="2.">Encode all values as the preferred floating-point representation that accurately represents the value, even for integral values, or</li> <li pn="section-4.2.2-5.2.2.3" derivedCounter="3.">Encode all values as 64-bit floating-point representations.</li> </ol> <t indent="0" pn="section-4.2.2-5.2.3"> Rule 1 straddles the boundaries between integers and floating-point values, and Rule 3 does not use preferred serialization, so Rule 2 may be a good choice in many cases.</t> </li> <li pn="section-4.2.2-5.3">If NaN is an allowed value, and there is no intent to support NaN payloads or signaling NaNs, the protocol needs to pick a single representation, typically 0xf97e00. If that simple choice is not possible, specific attention will be needed for NaN handling.</li> <li pn="section-4.2.2-5.4">Subnormal numbers (nonzero numbers with the lowest possible exponent of a given IEEE 754 number format) may be flushed to zero outputs or be treated as zero inputs in some floating-point implementations. A protocol's deterministic encoding may want to specifically accommodate such implementations while creating an onus on other implementations by excluding subnormal numbers from interchange, interchanging zero instead.</li> <li pn="section-4.2.2-5.5">The same number can be represented by different decimal fractions, by different bigfloats, and by different forms under other tags that may be defined to express numeric values. Depending on the implementation, it may not always be practical to determine whether any of these forms (or forms in the basic generic data model) are equivalent. An application protocol that presents choices of this kind for the representation format of numbers needs to be explicit about how the formats for deterministic encoding are to be chosen.</li> </ul> </section> <section anchor="length-first" toc="include" numbered="true" removeInRFC="false" pn="section-4.2.3"> <name slugifiedName="name-length-first-map-key-orderi">Length-First Map Key Ordering</name> <t indent="0" pn="section-4.2.3-1">The core deterministic encoding requirements (<xref target="core-det" format="default" sectionFormat="of" derivedContent="Section 4.2.1"/>) sort map keys in a different order from the one suggested by <xref target="RFC7049" section="3.9" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc7049#section-3.9" derivedContent="RFC7049"/> (called "Canonical CBOR" there). Protocols that need to be compatible with the order specified in <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/> can instead be specified in terms of this specification's "length-first core deterministic encoding requirements":</t> <t indent="0" pn="section-4.2.3-2">A CBOR encoding satisfies the "length-first core deterministic encoding requirements" if it satisfies the core deterministic encoding requirements except that the keys in every map <bcp14>MUST</bcp14> be sorted such that:</t> <ol spacing="normal" type="1" indent="adaptive" start="1" pn="section-4.2.3-3"><li pn="section-4.2.3-3.1" derivedCounter="1.">If two keys have different lengths, the shorter one sorts earlier;</li> <li pn="section-4.2.3-3.2" derivedCounter="2.">If two keys have the same length, the one with the lower value in (bytewise) lexical order sorts earlier.</li> </ol> <t indent="0" pn="section-4.2.3-4">For example, under the length-first core deterministic encoding requirements, the following keys are sorted correctly:</t> <ol spacing="normal" type="1" indent="adaptive" start="1" pn="section-4.2.3-5"><li pn="section-4.2.3-5.1" derivedCounter="1.">10, encoded as 0x0a.</li> <li pn="section-4.2.3-5.2" derivedCounter="2.">-1, encoded as 0x20.</li> <li pn="section-4.2.3-5.3" derivedCounter="3.">false, encoded as 0xf4.</li> <li pn="section-4.2.3-5.4" derivedCounter="4.">100, encoded as 0x1864.</li> <li pn="section-4.2.3-5.5" derivedCounter="5.">"z", encoded as 0x617a.</li> <li pn="section-4.2.3-5.6" derivedCounter="6.">[-1], encoded as 0x8120.</li> <li pn="section-4.2.3-5.7" derivedCounter="7.">"aa", encoded as 0x626161.</li> <li pn="section-4.2.3-5.8" derivedCounter="8.">[100], encoded as 0x811864.</li> </ol> <aside pn="section-4.2.3-6"> <t indent="0" pn="section-4.2.3-6.1">Although <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/> used the term "Canonical CBOR" for its form of requirements on deterministic encoding, this document avoids this term because "canonicalization" is often associated with specific uses of deterministic encoding only. The terms are essentially interchangeable, however, and the set of core requirements in this document could also be called "Canonical CBOR", while the length-first-ordered version of that could be called "Old Canonical CBOR".</t> </aside> </section> </section> </section> <section anchor="creating-cbor-based-protocols" toc="include" numbered="true" removeInRFC="false" pn="section-5"> <name slugifiedName="name-creating-cbor-based-protoco">Creating CBOR-Based Protocols</name> <t indent="0" pn="section-5-1">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 and decode it with no other knowledge.</t> <t indent="0" pn="section-5-2">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 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 subsequent values are zero or more floating-point numbers" or "the item is a map that has byte strings for keys and contains a pair whose key is 0xab01".</t> <t indent="0" pn="section-5-3">CBOR-based protocols <bcp14>MUST</bcp14> specify how their decoders handle invalid and other unexpected data. CBOR-based protocols <bcp14>MAY</bcp14> specify that they treat arbitrary valid data as unexpected. Encoders for CBOR-based protocols <bcp14>MUST</bcp14> produce only valid items, that is, the protocol cannot be designed to make use of invalid items. An encoder can be capable of encoding as many or as few types of values as is required by the protocol in which it is used; a decoder can be 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 restrictions allows CBOR to be used in extremely constrained environments.</t> <t indent="0" pn="section-5-4">The rest of this section discusses some considerations in creating CBOR-based protocols. With few exceptions, it is advisory only and explicitly excludes any language from BCP 14 <xref target="RFC2119" format="default" sectionFormat="of" derivedContent="RFC2119"/> <xref target="RFC8174" format="default" sectionFormat="of" derivedContent="RFC8174"/> other than words that could be interpreted as "<bcp14>MAY</bcp14>" in the sense of BCP 14. The exceptions aim at facilitating interoperability of CBOR-based protocols while making use of a wide variety of both generic and application-specific encoders and decoders.</t> <section anchor="cbor-in-streaming-applications" toc="include" numbered="true" removeInRFC="false" pn="section-5.1"> <name slugifiedName="name-cbor-in-streaming-applicati">CBOR in Streaming Applications</name> <t indent="0" pn="section-5.1-1">In a streaming application, a data stream may be composed of a sequence of CBOR data items concatenated back-to-back. In such an environment, the decoder immediately begins decoding a new data item if data is found after the end of a previous data item.</t> <t indent="0" pn="section-5.1-2">Not all of the bytes making up a data item may be immediately available to the decoder; some decoders will buffer additional data until a complete data item can be presented to the application. Other decoders can present partial information about a top-level data item to an application, such as the nested data items that could already be decoded, or even parts of a byte string that hasn't completely arrived yet. Such an application also <bcp14>MUST</bcp14> have a matching streaming security mechanism, where the desired protection is available for incremental data presented to the application.</t> <t indent="0" pn="section-5.1-3">Note that some applications and protocols will not want to use indefinite-length encoding. Using indefinite-length encoding allows an encoder to not need to marshal all the data for counting, but it requires a decoder to allocate increasing amounts of memory while waiting for the end of the item. This might be fine for some applications but not others.</t> </section> <section anchor="generic" toc="include" numbered="true" removeInRFC="false" pn="section-5.2"> <name slugifiedName="name-generic-encoders-and-decode">Generic Encoders and Decoders</name> <t indent="0" pn="section-5.2-1">A generic CBOR decoder can decode all well-formed encoded CBOR data items and present the data items to an application. See <xref target="pseudocode" format="default" sectionFormat="of" derivedContent="Appendix C"/>. (The diagnostic notation, <xref target="diagnostic-notation" format="default" sectionFormat="of" derivedContent="Section 8"/>, may be used to present well-formed CBOR values to humans.)</t> <t indent="0" pn="section-5.2-2">Generic CBOR encoders provide an application interface that allows the application to specify any well-formed value to be encoded as a CBOR data item, including simple values and tags unknown to the encoder.</t> <t indent="0" pn="section-5.2-3">Even though CBOR attempts to minimize these cases, not all well-formed CBOR data is valid: for example, the encoded text string <tt>0x62c0ae</tt> does not contain valid UTF-8 (because <xref target="RFC3629" format="default" sectionFormat="of" derivedContent="RFC3629"/> requires always using the shortest form) and so is not a valid CBOR item. Also, specific tags may make semantic constraints that may be violated, for instance, by a bignum tag enclosing another tag or by an instance of tag number 0 containing a byte string or containing a text string with contents that do not match the <tt>date-time</tt> production of <xref target="RFC3339" format="default" sectionFormat="of" derivedContent="RFC3339"/>. There is no requirement that generic encoders and decoders make unnatural choices for their application interface to enable the processing of invalid data. Generic encoders and decoders are expected to forward simple values and tags even if their specific codepoints are not registered at the time the encoder/decoder is written (<xref target="validity-checking" format="default" sectionFormat="of" derivedContent="Section 5.4"/>).</t> </section> <section anchor="semantic-errors" toc="include" numbered="true" removeInRFC="false" pn="section-5.3"> <name slugifiedName="name-validity-of-items">Validity of Items</name> <t indent="0" pn="section-5.3-1">A well-formed but invalid CBOR data item (<xref target="terminology" format="default" sectionFormat="of" derivedContent="Section 1.2"/>) presents a problem with interpreting the data encoded in it in the CBOR data model. A CBOR-based protocol could be specified in several layers, in which the lower layers don't process the semantics of some of the CBOR data they forward. These layers can't notice any validity errors in data they don't process and <bcp14>MUST</bcp14> forward that data as-is. The first layer that does process the semantics of an invalid CBOR item <bcp14>MUST</bcp14> pick one of two choices:</t> <ol spacing="normal" type="1" indent="adaptive" start="1" pn="section-5.3-2"><li pn="section-5.3-2.1" derivedCounter="1.">Replace the problematic item with an error marker and continue with the next item, or</li> <li pn="section-5.3-2.2" derivedCounter="2.">Issue an error and stop processing altogether.</li> </ol> <t indent="0" pn="section-5.3-3">A CBOR-based protocol <bcp14>MUST</bcp14> specify which of these options its decoders take for each kind of invalid item they might encounter.</t> <t indent="0" pn="section-5.3-4">Such problems might occur at the basic validity level of CBOR or in the context of tags (tag validity).</t> <section anchor="basic-validity" toc="include" numbered="true" removeInRFC="false" pn="section-5.3.1"> <name slugifiedName="name-basic-validity">Basic validity</name> <t indent="0" pn="section-5.3.1-1">Two kinds of validity errors can occur in the basic generic data model:</t> <dl newline="false" spacing="normal" indent="3" pn="section-5.3.1-2"> <dt pn="section-5.3.1-2.1">Duplicate keys in a map:</dt> <dd pn="section-5.3.1-2.2"> Generic decoders (<xref target="generic" format="default" sectionFormat="of" derivedContent="Section 5.2"/>) make data available to applications using the native CBOR data model. That data model includes maps (key-value mappings with unique keys), not multimaps (key-value mappings where multiple entries can have 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 instance of that key, or it might stop processing altogether. On the other hand, a "streaming decoder" may not even be able to notice. See <xref target="map-keys" format="default" sectionFormat="of" derivedContent="Section 5.6"/> for more discussion of keys in maps.</dd> <dt pn="section-5.3.1-2.3">Invalid UTF-8 string:</dt> <dd pn="section-5.3.1-2.4"> A decoder might or might not want to verify that the sequence of bytes in a UTF-8 string (major type 3) is actually valid UTF-8 and react appropriately.</dd> </dl> </section> <section anchor="tag-validity" toc="include" numbered="true" removeInRFC="false" pn="section-5.3.2"> <name slugifiedName="name-tag-validity">Tag validity</name> <t indent="0" pn="section-5.3.2-1">Two additional kinds of validity errors are introduced by adding tags to the basic generic data model:</t> <dl newline="false" spacing="normal" indent="3" pn="section-5.3.2-2"> <dt pn="section-5.3.2-2.1">Inadmissible type for tag content:</dt> <dd pn="section-5.3.2-2.2"> Tag numbers (<xref target="tags" format="default" sectionFormat="of" derivedContent="Section 3.4"/>) specify what type of data item is supposed to be used as their tag content; for example, the tag numbers for unsigned or negative bignums are supposed to be put on byte strings. A decoder that decodes the tagged data item into a native representation (a native big integer in this example) is expected to check the type of the data item being tagged. Even decoders that don't have such native representations available in their environment may perform the check on those tags known to them and react appropriately.</dd> <dt pn="section-5.3.2-2.3">Inadmissible value for tag content:</dt> <dd pn="section-5.3.2-2.4"> The type of data item may be admissible for a tag's content, but the specific value may not be; e.g., a value of "yesterday" is not acceptable for the content of tag 0, even though it properly is a text string. A decoder that normally ingests such tags into equivalent platform types might present this tag to the application in a similar way to how it would present a tag with an unknown tag number (<xref target="validity-checking" format="default" sectionFormat="of" derivedContent="Section 5.4"/>).</dd> </dl> </section> </section> <section anchor="validity-checking" toc="include" numbered="true" removeInRFC="false" pn="section-5.4"> <name slugifiedName="name-validity-and-evolution">Validity and Evolution</name> <t indent="0" pn="section-5.4-1">A decoder with validity checking will expend the effort to reliably detect data items with validity errors. For example, such a decoder needs to have an API that reports an error (and does not return data) for a CBOR data item that contains any of the validity errors listed in the previous subsection.</t> <t indent="0" pn="section-5.4-2">The set of tags defined in the "Concise Binary Object Representation (CBOR) Tags" registry (<xref target="ianatags" format="default" sectionFormat="of" derivedContent="Section 9.2"/>), as well as the set of simple values defined in the "Concise Binary Object Representation (CBOR) Simple Values" registry (<xref target="ianasimple" format="default" sectionFormat="of" derivedContent="Section 9.1"/>), can grow at any time beyond the set understood by a generic decoder. A validity-checking decoder can do one of two things when it encounters such a case that it does not recognize:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-5.4-3"> <li pn="section-5.4-3.1">It can report an error (and not return data). Note that treating this case as an error can cause ossification and is thus not encouraged. This error is not a validity error, per se. This kind of error is more likely to be raised by a decoder that would be performing validity checking if this were a known case.</li> <li pn="section-5.4-3.2">It can emit the unknown item (type, value, and, for tags, the decoded tagged data item) to the application calling the decoder, and then give the application an indication that the decoder did not recognize that tag number or simple value.</li> </ul> <t indent="0" pn="section-5.4-4">The latter approach, which is also appropriate for decoders that do not support validity checking, provides forward compatibility with newly registered tags and simple values without the requirement to update the encoder at the same time as the calling application. (For this, the decoder's API needs the ability to mark unknown items so that the calling application can handle them in a manner appropriate for the program.)</t> <t indent="0" pn="section-5.4-5">Since some of the processing needed for validity checking may have an appreciable cost (in particular with duplicate detection for maps), support of validity checking is not a requirement placed on all CBOR decoders.</t> <t indent="0" pn="section-5.4-6">Some encoders will rely on their applications to provide input data in such a way that valid CBOR results from the encoder. A generic encoder may also want to provide a validity-checking mode where it reliably limits its output to valid CBOR, independent of whether or not its application is indeed providing API-conformant data.</t> </section> <section anchor="numbers" toc="include" numbered="true" removeInRFC="false" pn="section-5.5"> <name slugifiedName="name-numbers">Numbers</name> <t indent="0" pn="section-5.5-1">CBOR-based protocols should take into account that different language environments pose different restrictions on the range and precision of numbers that are representable. For example, the basic JavaScript number system treats all numbers as floating-point values, which may result in the silent loss of precision in decoding integers with more than 53 significant bits. Another example is that, since CBOR keeps the sign bit for its integer representation in the major type, it has one bit more for signed numbers of a certain length (e.g., -2<sup>64</sup>..2<sup>64</sup>-1 for 1+8-byte integers) than the typical platform signed integer representation of the same length (-2<sup>63</sup>..2<sup>63</sup>-1 for 8-byte int64_t). A protocol that uses numbers should define its expectations on the handling of nontrivial numbers in decoders and receiving applications.</t> <t indent="0" pn="section-5.5-2">A CBOR-based protocol that includes floating-point numbers can restrict which of the three formats (half-precision, single-precision, and double-precision) are to be supported. For an integer-only application, a protocol may want to completely exclude the use of floating-point values.</t> <t indent="0" pn="section-5.5-3">A CBOR-based protocol designed for compactness may want to exclude specific integer encodings that are longer than necessary for the application, such as to save the need to implement 64-bit integers. There is an expectation that encoders will use the most compact integer representation that can represent a given value. However, a compact application that does not require deterministic encoding should accept values that use a longer-than-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 the given size. Similar considerations apply to floating-point values; decoding both preferred serializations and longer-than-needed ones is recommended.</t> <t indent="0" pn="section-5.5-4">CBOR-based protocols for constrained applications that provide a choice between representing a specific number as an integer and as a decimal fraction or bigfloat (such as when the exponent is small and nonnegative) might express a quality-of-implementation expectation that the integer representation is used directly.</t> </section> <section anchor="map-keys" toc="include" numbered="true" removeInRFC="false" pn="section-5.6"> <name slugifiedName="name-specifying-keys-for-maps">Specifying Keys for Maps</name> <t indent="0" pn="section-5.6-1">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 interwork with JSON-based applications, conversion is simplified by limiting keys to text strings only; otherwise, there has to be a specified mapping from the other CBOR types to text strings, and this often leads to implementation errors. In applications where keys are numeric in nature, and numeric ordering of keys is important to the application, directly using the numbers for the keys is useful.</t> <t indent="0" pn="section-5.6-2">If multiple types of keys are to be used, consideration should be given to how these types would be represented in the specific programming environments that are to be used. For example, in JavaScript Maps <xref target="ECMA262" format="default" sectionFormat="of" derivedContent="ECMA262"/>, a key of integer 1 cannot be distinguished from a key of floating-point 1.0. This means that, if integer keys are used, the protocol needs to avoid the use of floating-point keys the values of which happen to be integer numbers in the same map.</t> <t indent="0" pn="section-5.6-3">Decoders that deliver data items nested within a CBOR data item immediately on decoding them ("streaming decoders") often do not keep the state that is necessary to ascertain uniqueness of a key in a map. Similarly, an encoder that can start encoding data items before the enclosing data item is completely available ("streaming encoder") may want to reduce its overhead significantly by relying on its data source to maintain uniqueness.</t> <t indent="0" pn="section-5.6-4">A CBOR-based protocol <bcp14>MUST</bcp14> define what to do when a receiving application sees multiple identical keys in a map. The resulting rule in the protocol <bcp14>MUST</bcp14> respect the CBOR data model: it cannot prescribe a specific handling of the entries 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 decoder has to stop with an error. When processing maps that exhibit entries with duplicate keys, a generic decoder might do one of the following:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-5.6-5"> <li pn="section-5.6-5.1">Not accept maps with duplicate keys (that is, enforce validity for maps, see also <xref target="validity-checking" format="default" sectionFormat="of" derivedContent="Section 5.4"/>). These generic decoders are universally useful. An application may still need to perform its own duplicate checking based on application rules (for instance, if the application equates integers and floating-point values in map key positions for specific maps).</li> <li pn="section-5.6-5.2">Pass all map entries to the application, including ones with duplicate keys. This requires that the application handle (check against) duplicate keys, even if the application rules are identical to the generic data model rules.</li> <li pn="section-5.6-5.3">Lose some entries with duplicate keys, e.g., deliver only the final (or first) entry out of the entries with the same key. With such a generic decoder, applications may get different results for a specific key on different runs, and with different generic decoders, which value is returned is based on generic decoder implementation and the actual order of keys in the map. In particular, applications cannot validate key uniqueness on their own as they do not necessarily see all entries; they may not be able to use such a generic decoder if they need to validate key uniqueness. These generic decoders can only be used in situations where the data source and transfer always provide valid maps; this is not possible if the data source and transfer can be attacked.</li> </ul> <t indent="0" pn="section-5.6-6">Generic decoders need to document which of these three approaches they implement.</t> <t indent="0" pn="section-5.6-7">The CBOR data model for maps does not allow ascribing semantics to the order of the key/value pairs in the map representation. Thus, a CBOR-based protocol <bcp14>MUST NOT</bcp14> specify that changing the key/value pair order in a map changes the semantics, except to specify that some orders are disallowed, for example, where they would not meet the requirements of a deterministic encoding (<xref target="det-enc" format="default" sectionFormat="of" derivedContent="Section 4.2"/>). (Any secondary effects of map ordering such as on timing, cache usage, and other potential side channels are not considered part of the semantics but may be enough reason on their own for a protocol to require a deterministic encoding format.)</t> <t indent="0" pn="section-5.6-8">Applications for constrained devices should consider using small integers as keys if they have maps with a small number of frequently used keys; for instance, a set of 24 or fewer keys can be encoded in a single byte as unsigned integers, up to 48 if negative integers are also used. Less frequently occurring keys can then use integers with longer encodings.</t> <section anchor="equivalence-of-keys" toc="include" numbered="true" removeInRFC="false" pn="section-5.6.1"> <name slugifiedName="name-equivalence-of-keys">Equivalence of Keys</name> <t indent="0" pn="section-5.6.1-1">The specific data model that applies to a CBOR data item is used to determine whether keys occurring in maps are duplicates or distinct.</t> <t indent="0" pn="section-5.6.1-2">At the generic data model level, numerically equivalent integer and floating-point values are distinct from each other, as they are from the various big numbers (Tags 2 to 5). Similarly, text strings are distinct from byte strings, even if composed of the same bytes. A tagged value is distinct from an untagged value or from a value tagged with a different tag number.</t> <t indent="0" pn="section-5.6.1-3">Within each of these groups, numeric values are distinct unless they are numerically equal (specifically, -0.0 is equal to 0.0); for the purpose of map key equivalence, NaN values are equivalent if they have the same significand after zero-extending both significands at the right to 64 bits.</t> <t indent="0" pn="section-5.6.1-4">Both byte strings and text strings are compared byte by byte, arrays are compared element by element, and are equal if they have the same number of bytes/elements and the same values at the same positions. 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.</t> <t indent="0" pn="section-5.6.1-5">Tagged values are equal if both the tag number and the tag content are equal. (Note that a generic decoder that provides processing for a specific tag may not be able to distinguish some semantically equivalent values, e.g., if leading zeroes occur in the content of tag 2 or tag 3 (<xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/>).) Simple values are equal if they simply have the same value. Nothing else is equal in the generic data model; a simple value 2 is not equivalent to an integer 2, and an array is never equivalent to a map.</t> <t indent="0" pn="section-5.6.1-6">As discussed in <xref target="specific-data-models" format="default" sectionFormat="of" derivedContent="Section 2.2"/>, specific data models can make values equivalent for the purpose of comparing map keys that are distinct in the generic data model. Note that this implies that a generic decoder may deliver a decoded map to an application that needs to be checked for duplicate map keys by that application (alternatively, the decoder may provide a programming interface to perform this service for the application). Specific data models are not able to distinguish values for map keys that are equal for this purpose at the generic data model level.</t> </section> </section> <section anchor="undefined-values" toc="include" numbered="true" removeInRFC="false" pn="section-5.7"> <name slugifiedName="name-undefined-values">Undefined Values</name> <t indent="0" pn="section-5.7-1">In some CBOR-based protocols, the simple value (<xref target="fpnocont" format="default" sectionFormat="of" derivedContent="Section 3.3"/>) of <tt>undefined</tt> 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 data items to be encoded without harm.</t> </section> </section> <section anchor="converting-data-between-cbor-and-json" toc="include" numbered="true" removeInRFC="false" pn="section-6"> <name slugifiedName="name-converting-data-between-cbo">Converting Data between CBOR and JSON</name> <t indent="0" pn="section-6-1">This section gives non-normative advice about converting between CBOR and JSON. Implementations of converters <bcp14>MAY</bcp14> use whichever advice here they want.</t> <t indent="0" pn="section-6-2">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 bytes, not characters.</t> <section anchor="converting-from-cbor-to-json" toc="include" numbered="true" removeInRFC="false" pn="section-6.1"> <name slugifiedName="name-converting-from-cbor-to-jso">Converting from CBOR to JSON</name> <t indent="0" pn="section-6.1-1">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 consider what to do in those cases. The following non-normative advice deals with these by converting them to a single substitute value, such as a JSON null.</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-6.1-2"> <li pn="section-6.1-2.1">An integer (major type 0 or 1) becomes a JSON number.</li> <li pn="section-6.1-2.2">A byte string (major type 2) that is not embedded in a tag that specifies a proposed encoding is encoded in base64url without padding and becomes a JSON string.</li> <li pn="section-6.1-2.3">A UTF-8 string (major type 3) becomes a JSON string. Note that JSON requires escaping certain characters (<xref target="RFC8259" section="7" sectionFormat="comma" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8259#section-7" derivedContent="RFC8259"/>): quotation mark (U+0022), reverse solidus (U+005C), and the "C0 control characters" (U+0000 through U+001F). All other characters are copied unchanged into the JSON UTF-8 string.</li> <li pn="section-6.1-2.4">An array (major type 4) becomes a JSON array.</li> <li pn="section-6.1-2.5">A map (major type 5) becomes a JSON object. This is possible directly only if all keys are UTF-8 strings. A converter might also convert other keys into UTF-8 strings (such as by converting integers into strings containing their decimal representation); however, doing so introduces a danger of key collision. Note also that, if tags on UTF-8 strings are ignored as proposed below, this will cause a key collision if the tags are different but the strings are the same.</li> <li pn="section-6.1-2.6">False (major type 7, additional information 20) becomes a JSON false.</li> <li pn="section-6.1-2.7">True (major type 7, additional information 21) becomes a JSON true.</li> <li pn="section-6.1-2.8">Null (major type 7, additional information 22) becomes a JSON null.</li> <li pn="section-6.1-2.9">A floating-point value (major type 7, additional information 25 through 27) becomes a JSON number if it is finite (that is, it can be represented in a JSON number); if the value is non-finite (NaN, or positive or negative Infinity), it is represented by the substitute value.</li> <li pn="section-6.1-2.10">Any other simple value (major type 7, any additional information value not yet discussed) is represented by the substitute value.</li> <li pn="section-6.1-2.11">A bignum (major type 6, tag number 2 or 3) is represented by encoding its byte string in base64url without padding and becomes a JSON string. For tag number 3 (negative bignum), a "~" (ASCII tilde) is inserted before the base-encoded value. (The conversion to a binary blob instead of a number is to prevent a likely numeric overflow for the JSON decoder.)</li> <li pn="section-6.1-2.12">A byte string with an encoding hint (major type 6, tag number 21 through 23) is encoded as described by the hint and becomes a JSON string.</li> <li pn="section-6.1-2.13">For all other tags (major type 6, any other tag number), the tag content is represented as a JSON value; the tag number is ignored.</li> <li pn="section-6.1-2.14">Indefinite-length items are made definite before conversion.</li> </ul> <t indent="0" pn="section-6.1-3">A CBOR-to-JSON converter may want to keep to the JSON profile I-JSON <xref target="RFC7493" format="default" sectionFormat="of" derivedContent="RFC7493"/>, to maximize interoperability and increase confidence that the JSON output can be processed with predictable results. For example, this has implications on the range of integers that can be represented reliably, as well as on the top-level items that may be supported by older JSON implementations.</t> </section> <section anchor="converting-from-json" toc="include" numbered="true" removeInRFC="false" pn="section-6.2"> <name slugifiedName="name-converting-from-json-to-cbo">Converting from JSON to CBOR</name> <t indent="0" pn="section-6.2-1">All JSON values, once decoded, directly map into one or more CBOR values. As with any kind of CBOR generation, decisions have to be made with respect to number representation. In a suggested conversion:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-6.2-2"> <li pn="section-6.2-2.1">JSON numbers without fractional parts (integer numbers) are represented as integers (major types 0 and 1, possibly major type 6, tag number 2 and 3), choosing the shortest form; integers longer than an implementation-defined threshold may instead be represented as floating-point values. The default range that is represented as integer is -2<sup>53</sup>+1..2<sup>53</sup>-1 (fully exploiting the range for exact integers in the binary64 representation often used for decoding JSON <xref target="RFC7493" format="default" sectionFormat="of" derivedContent="RFC7493"/>). A CBOR-based protocol, or a generic converter implementation, may choose -2<sup>32</sup>..2<sup>32</sup>-1 or -2<sup>64</sup>..2<sup>64</sup>-1 (fully using the integer ranges available in CBOR with uint32_t or uint64_t, respectively) or even -2<sup>31</sup>..2<sup>31</sup>-1 or -2<sup>63</sup>..2<sup>63</sup>-1 (using popular ranges for two's complement signed integers). (If the JSON was generated from a JavaScript implementation, its precision is already limited to 53 bits maximum.)</li> <li pn="section-6.2-2.2">Numbers with fractional parts are represented as floating-point values, performing the decimal-to-binary conversion based on the precision provided by IEEE 754 binary64. The mathematical value of the JSON number is converted to binary64 using the roundTiesToEven procedure in Section 4.3.1 of <xref target="IEEE754" format="default" sectionFormat="of" derivedContent="IEEE754"/>. Then, when encoding in CBOR, the preferred serialization uses the shortest floating-point representation exactly representing this conversion result; for instance, 1.5 is represented in a 16-bit floating-point value (not all implementations will be capable of efficiently finding the minimum form, though). Instead of using the default binary64 precision, there may be an implementation-defined limit to the precision of the conversion that will affect the precision of the represented values. Decimal representation should only be used on the CBOR side if that is specified in a protocol.</li> </ul> <t indent="0" pn="section-6.2-3">CBOR has been designed to generally provide a more compact encoding than JSON. One implementation strategy that might come to mind is to perform a JSON-to-CBOR encoding in place in a single buffer. This strategy would need to carefully consider a number of pathological cases, such as that some strings represented with no or very few 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 floating-point representations might cause expansion from some short decimal representations (1.1, 1e9) in JSON. This may be hard to get right, and any ensuing vulnerabilities may be exploited by an attacker.</t> </section> </section> <section anchor="future-evolution-of-cbor" toc="include" numbered="true" removeInRFC="false" pn="section-7"> <name slugifiedName="name-future-evolution-of-cbor">Future Evolution of CBOR</name> <t indent="0" pn="section-7-1">Successful protocols evolve over time. New ideas appear, implementation platforms improve, related protocols are developed and evolve, and new requirements from applications and protocols are added. Facilitating protocol evolution is therefore an important design consideration for any protocol development.</t> <t indent="0" pn="section-7-2">For protocols that will use CBOR, CBOR provides some useful mechanisms to facilitate their evolution. Best practices for this are well known, particularly from JSON format development of JSON-based protocols. Therefore, such best practices are outside the scope of this specification.</t> <t indent="0" pn="section-7-3">However, facilitating the evolution of CBOR itself is very well within its scope. CBOR is designed to both provide a stable basis for development of CBOR-based protocols and to be able to evolve. Since a successful protocol may live for decades, CBOR needs to be designed for decades of use and evolution. This section provides some guidance for the evolution of CBOR. It is necessarily more subjective than other parts of this document. It is also necessarily incomplete, lest it turn into a textbook on protocol development.</t> <section anchor="extension-points" toc="include" numbered="true" removeInRFC="false" pn="section-7.1"> <name slugifiedName="name-extension-points">Extension Points</name> <t indent="0" pn="section-7.1-1">In a protocol design, opportunities for evolution are often included in the form of extension points. For example, there may be a codepoint space that is not fully allocated from the outset, and the protocol is designed to tolerate and embrace implementations that start using more codepoints than initially allocated.</t> <t indent="0" pn="section-7.1-2">Sizing the codepoint space may be difficult because the range required may be hard to predict. Protocol designs should attempt to make the codepoint space large enough so that it can slowly be filled over the intended lifetime of the protocol.</t> <t indent="0" pn="section-7.1-3">CBOR has three major extension points:</t> <dl spacing="normal" indent="3" newline="false" pn="section-7.1-4"> <dt pn="section-7.1-4.1">the "simple" space (values in major type 7):</dt> <dd pn="section-7.1-4.2">Of the 24 efficient (and 224 slightly less efficient) values, only a small number have been allocated. Implementations receiving an unknown simple data item may easily be able to process it as such, given that the structure of the value is indeed simple. The IANA registry in <xref target="ianasimple" format="default" sectionFormat="of" derivedContent="Section 9.1"/> is the appropriate way to address the extensibility of this codepoint space.</dd> <dt pn="section-7.1-4.3">the "tag" space (values in major type 6):</dt> <dd pn="section-7.1-4.4"> The total codepoint space is abundant; only a tiny part of it has been allocated. However, not all of these codepoints are equally efficient: the first 24 only consume a single ("1+0") byte, and half of them have already been allocated. The next 232 values only consume two ("1+1") bytes, with nearly a quarter already allocated. These subspaces need some curation to last for a few more decades. Implementations receiving an unknown tag number can choose to process just the enclosed tag content or, preferably, to process the tag as an unknown tag number wrapping the tag content. The IANA registry in <xref target="ianatags" format="default" sectionFormat="of" derivedContent="Section 9.2"/> is the appropriate way to address the extensibility of this codepoint space.</dd> <dt pn="section-7.1-4.5">the "additional information" space:</dt> <dd pn="section-7.1-4.6">An implementation receiving an unknown additional information value has no way to continue decoding, so allocating codepoints in this space is a major step beyond just exercising an extension point. There are also very few codepoints left. See also <xref target="curating" format="default" sectionFormat="of" derivedContent="Section 7.2"/>.</dd> </dl> </section> <section anchor="curating" toc="include" numbered="true" removeInRFC="false" pn="section-7.2"> <name slugifiedName="name-curating-the-additional-inf">Curating the Additional Information Space</name> <t indent="0" pn="section-7.2-1">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.</t> <t indent="0" pn="section-7.2-2">The present specification does not manage the additional information codepoint space by an IANA registry. Instead, allocations out of this space can only be done by updating this specification.</t> <t indent="0" pn="section-7.2-3">For an additional information value of n >= 24, the size of the additional data typically is 2<sup>n-24</sup> bytes. Therefore, additional 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 the protocol. Additional information value 30 is then the only additional information value available for general allocation, and there should be a very good reason for allocating it before assigning it through an update of the present specification.</t> </section> </section> <section anchor="diagnostic-notation" toc="include" numbered="true" removeInRFC="false" pn="section-8"> <name slugifiedName="name-diagnostic-notation">Diagnostic Notation</name> <t indent="0" pn="section-8-1">CBOR is a binary interchange format. To facilitate documentation and debugging, and in particular to facilitate communication between entities cooperating in debugging, this section defines a simple human-readable diagnostic notation. All actual interchange always happens in the binary format.</t> <t indent="0" pn="section-8-2">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 this document. (Implementers looking for a text-based format for representing CBOR data items in configuration files may also want to consider YAML <xref target="YAML" format="default" sectionFormat="of" derivedContent="YAML"/>.)</t> <t indent="0" pn="section-8-3">The diagnostic notation is loosely based on JSON as it is defined in RFC 8259, extending it where needed.</t> <t indent="0" pn="section-8-4">The notation borrows the JSON syntax for numbers (integer and floating-point), True (>true<), False (>false<), Null (>null<), UTF-8 strings, arrays, and maps (maps are called objects in JSON; the diagnostic notation extends JSON here by allowing any data item in the key position). Undefined is written >undefined< as in JavaScript. The non-finite floating-point numbers Infinity, -Infinity, and NaN are written exactly as in this sentence (this is also a way they can be written in JavaScript, although JSON does not allow them). A tag is written as an integer number for the tag number, followed by the tag content in parentheses; for instance, a date in the format specified by RFC 3339 (ISO 8601) could be notated as:</t> <t indent="5" pn="section-8-5">0("2013-03-21T20:04:00Z")</t> <t indent="0" pn="section-8-6">or the equivalent relative time as the following:</t> <t indent="5" pn="section-8-7">1(1363896240)</t> <t indent="0" pn="section-8-8">Byte strings are notated in one of the base encodings, without padding, enclosed in single quotes, prefixed by >h< for base16, >b32< for base32, >h32< for base32hex, >b64< for base64 or base64url (the actual encodings do not overlap, so the string remains unambiguous). For example, the byte string 0x12345678 could be written h'12345678', b32'CI2FM6A', or b64'EjRWeA'.</t> <t indent="0" pn="section-8-9">Unassigned simple values are given as "simple()" with the appropriate integer in the parentheses. For example, "simple(42)" indicates major type 7, value 42.</t> <t indent="0" pn="section-8-10">A number of useful extensions to the diagnostic notation defined here are provided in <xref target="RFC8610" section="G" sectionFormat="of" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8610#appendix-G" derivedContent="RFC8610"/>, "Extended Diagnostic Notation" (EDN). Similarly, this notation could be extended in a separate document to provide documentation for NaN payloads, which are not covered in this document. </t> <section anchor="encoding-indicators" toc="include" numbered="true" removeInRFC="false" pn="section-8.1"> <name slugifiedName="name-encoding-indicators">Encoding Indicators</name> <t indent="0" pn="section-8.1-1">Sometimes it is useful to indicate in the diagnostic notation which of several alternative representations were actually used; for example, a data item written >1.5< by a diagnostic decoder might have been encoded as a half-, single-, or double-precision float.</t> <t indent="0" pn="section-8.1-2">The convention for encoding indicators is that anything starting with an underscore and all following characters that are alphanumeric or underscore is an encoding indicator, and can be ignored by anyone not interested in this information. For example, <tt>_</tt> or <tt>_3</tt>. Encoding indicators are always optional.</t> <t indent="0" pn="section-8.1-3">A single underscore can be written after the opening brace of a map or the opening bracket of an array to indicate that the data item was represented in indefinite-length format. For example, [_ 1, 2] contains an indicator that an indefinite-length representation was used to represent the data item [1, 2].</t> <t indent="0" pn="section-8.1-4">An underscore followed by a decimal digit n indicates that the preceding item (or, for arrays and maps, the item starting with the preceding bracket or brace) was encoded with an additional 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. This encoding indicator is not shown in <xref target="examples" format="default" sectionFormat="of" derivedContent="Appendix A"/>. (Note that the encoding indicator "_" is thus an abbreviation of the full form "_7", which is not used.)</t> <t indent="0" pn="section-8.1-5">The detailed chunk structure of byte and text strings of indefinite length can be notated in the form (_ h'0123', h'4567') and (_ "foo", "bar"). However, for an indefinite-length string with no chunks inside, (_ ) would be ambiguous as to whether a byte string (0x5fff) or a text string (0x7fff) is meant and is therefore not used. The basic forms ''_ and ""_ can be used instead and are reserved for the case of no chunks only -- not as short forms for the (permitted, but not really useful) encodings with only empty chunks, which need to be notated as (_ ''), (_ ""), etc., to preserve the chunk structure.</t> </section> </section> <section anchor="ianacons" toc="include" numbered="true" removeInRFC="false" pn="section-9"> <name slugifiedName="name-iana-considerations">IANA Considerations</name> <t indent="0" pn="section-9-1">IANA has created two registries for new CBOR values. The registries are separate, that is, not under an umbrella registry, and follow the rules in <xref target="RFC8126" format="default" sectionFormat="of" derivedContent="RFC8126"/>. IANA has also assigned a new media type, an associated CoAP Content-Format entry, and a structured syntax suffix.</t> <section anchor="ianasimple" toc="include" numbered="true" removeInRFC="false" pn="section-9.1"> <name slugifiedName="name-cbor-simple-values-registry">CBOR Simple Values Registry</name> <t indent="0" pn="section-9.1-1">IANA has created the "Concise Binary Object Representation (CBOR) Simple Values" registry at <xref target="IANA.cbor-simple-values" format="default" sectionFormat="of" derivedContent="IANA.cbor-simple-values"/>. The initial values are shown in <xref target="fpnoconttbl2" format="default" sectionFormat="of" derivedContent="Table 4"/>.</t> <t indent="0" pn="section-9.1-2">New entries in the range 0 to 19 are assigned by Standards Action <xref target="RFC8126" format="default" sectionFormat="of" derivedContent="RFC8126"/>. It is suggested that IANA allocate values starting with the number 16 in order to reserve the lower numbers for contiguous blocks (if any).</t> <t indent="0" pn="section-9.1-3">New entries in the range 32 to 255 are assigned by Specification Required.</t> </section> <section anchor="ianatags" toc="include" numbered="true" removeInRFC="false" pn="section-9.2"> <name slugifiedName="name-cbor-tags-registry">CBOR Tags Registry</name> <t indent="0" pn="section-9.2-1">IANA has created the "Concise Binary Object Representation (CBOR) Tags" registry at <xref target="IANA.cbor-tags" format="default" sectionFormat="of" derivedContent="IANA.cbor-tags"/>. The tags that were defined in <xref target="RFC7049" format="default" sectionFormat="of" derivedContent="RFC7049"/> are described in detail in <xref target="tags" format="default" sectionFormat="of" derivedContent="Section 3.4"/>, and other tags have already been defined since then.</t> <t indent="0" pn="section-9.2-2">New entries in the range 0 to 23 ("1+0") are assigned by Standards Action. New entries in the ranges 24 to 255 ("1+1") and 256 to 32767 (lower half of "1+2") are assigned by Specification Required. New entries in the range 32768 to 18446744073709551615 (upper half of "1+2", "1+4", and "1+8") are assigned by First Come First Served. The template for registration requests is:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-9.2-3"> <li pn="section-9.2-3.1">Data item</li> <li pn="section-9.2-3.2">Semantics (short form)</li> </ul> <t indent="0" pn="section-9.2-4">In addition, First Come First Served requests should include:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-9.2-5"> <li pn="section-9.2-5.1">Point of contact</li> <li pn="section-9.2-5.2">Description of semantics (URL) -- This description is optional; the URL can point to something like an Internet-Draft or a web page.</li> </ul> <t indent="0" pn="section-9.2-6">Applicants exercising the First Come First Served range and making a suggestion for a tag number that is not representable in 32 bits (i.e., larger than 4294967295) should be aware that this could reduce interoperability with implementations that do not support 64-bit numbers.</t> </section> <section anchor="media-type-mime-type" toc="include" numbered="true" removeInRFC="false" pn="section-9.3"> <name slugifiedName="name-media-types-registry">Media Types Registry</name> <t indent="0" pn="section-9.3-1">The Internet media type <xref target="RFC6838" format="default" sectionFormat="of" derivedContent="RFC6838"/> ("MIME type") for a single encoded CBOR data item is "application/cbor" as defined in the "Media Types" registry <xref target="IANA.media-types" format="default" sectionFormat="of" derivedContent="IANA.media-types"/>:</t> <dl newline="false" spacing="normal" indent="3" pn="section-9.3-2"> <dt pn="section-9.3-2.1">Type name:</dt> <dd pn="section-9.3-2.2">application</dd> <dt pn="section-9.3-2.3">Subtype name:</dt> <dd pn="section-9.3-2.4">cbor</dd> <dt pn="section-9.3-2.5">Required parameters:</dt> <dd pn="section-9.3-2.6">n/a</dd> <dt pn="section-9.3-2.7">Optional parameters:</dt> <dd pn="section-9.3-2.8">n/a</dd> <dt pn="section-9.3-2.9">Encoding considerations:</dt> <dd pn="section-9.3-2.10">Binary</dd> <dt pn="section-9.3-2.11">Security considerations:</dt> <dd pn="section-9.3-2.12">See <xref target="securitycons" format="default" sectionFormat="of" derivedContent="Section 10"/> of RFC 8949.</dd> <dt pn="section-9.3-2.13">Interoperability considerations:</dt> <dd pn="section-9.3-2.14">n/a</dd> <dt pn="section-9.3-2.15">Published specification:</dt> <dd pn="section-9.3-2.16">RFC 8949</dd> <dt pn="section-9.3-2.17">Applications that use this media type:</dt> <dd pn="section-9.3-2.18">Many</dd> <dt pn="section-9.3-2.19">Additional information:</dt> <dd pn="section-9.3-2.20"> <t indent="0" pn="section-9.3-2.20.1"><br/></t> <dl spacing="compact" indent="3" newline="false" pn="section-9.3-2.20.2"> <dt pn="section-9.3-2.20.2.1">Magic number(s):</dt> <dd pn="section-9.3-2.20.2.2"> n/a</dd> <dt pn="section-9.3-2.20.2.3">File extension(s):</dt> <dd pn="section-9.3-2.20.2.4"> .cbor</dd> <dt pn="section-9.3-2.20.2.5">Macintosh file type code(s):</dt> <dd pn="section-9.3-2.20.2.6">n/a</dd> </dl> </dd> <dt pn="section-9.3-2.21">Person & email address to contact for further information:</dt> <dd pn="section-9.3-2.22">IETF CBOR Working Group (cbor@ietf.org) or IETF Applications and Real-Time Area (art@ietf.org)</dd> <dt pn="section-9.3-2.23">Intended usage:</dt> <dd pn="section-9.3-2.24">COMMON</dd> <dt pn="section-9.3-2.25">Restrictions on usage:</dt> <dd pn="section-9.3-2.26">none</dd> <dt pn="section-9.3-2.27">Author:</dt> <dd pn="section-9.3-2.28">IETF CBOR Working Group (cbor@ietf.org)</dd> <dt pn="section-9.3-2.29">Change controller:</dt> <dd pn="section-9.3-2.30">The IESG (iesg@ietf.org)</dd> </dl> </section> <section anchor="coap-content-format" toc="include" numbered="true" removeInRFC="false" pn="section-9.4"> <name slugifiedName="name-coap-content-format-registr">CoAP Content-Format Registry</name> <t indent="0" pn="section-9.4-1">The CoAP Content-Format for CBOR has been registered in the "CoAP Content-Formats" subregistry within the "Constrained RESTful Environments (CoRE) Parameters" registry <xref target="IANA.core-parameters" format="default" sectionFormat="of" derivedContent="IANA.core-parameters"/>:</t> <dl indent="3" newline="false" spacing="normal" pn="section-9.4-2"> <dt pn="section-9.4-2.1">Media Type:</dt> <dd pn="section-9.4-2.2">application/cbor</dd> <dt pn="section-9.4-2.3">Encoding:</dt> <dd pn="section-9.4-2.4">-</dd> <dt pn="section-9.4-2.5">ID:</dt> <dd pn="section-9.4-2.6">60</dd> <dt pn="section-9.4-2.7">Reference:</dt> <dd pn="section-9.4-2.8">RFC 8949</dd> </dl> </section> <section anchor="the-cbor-structured-syntax-suffix-registration" toc="include" numbered="true" removeInRFC="false" pn="section-9.5"> <name slugifiedName="name-structured-syntax-suffix-re">Structured Syntax Suffix Registry</name> <t indent="0" pn="section-9.5-1">The structured syntax suffix <xref target="RFC6838" format="default" sectionFormat="of" derivedContent="RFC6838"/> for media types based on a single encoded CBOR data item is +cbor, which IANA has registered in the "Structured Syntax Suffixes" registry <xref target="IANA.structured-suffix" format="default" sectionFormat="of" derivedContent="IANA.structured-suffix"/>:</t> <dl indent="3" newline="false" spacing="normal" pn="section-9.5-2"> <dt pn="section-9.5-2.1">Name:</dt> <dd pn="section-9.5-2.2">Concise Binary Object Representation (CBOR)</dd> <dt pn="section-9.5-2.3">+suffix:</dt> <dd pn="section-9.5-2.4">+cbor</dd> <dt pn="section-9.5-2.5">References:</dt> <dd pn="section-9.5-2.6">RFC 8949</dd> <dt pn="section-9.5-2.7">Encoding Considerations:</dt> <dd pn="section-9.5-2.8">CBOR is a binary format.</dd> <dt pn="section-9.5-2.9">Interoperability Considerations:</dt> <dd pn="section-9.5-2.10">n/a</dd> <dt pn="section-9.5-2.11">Fragment Identifier Considerations:</dt> <dd pn="section-9.5-2.12"> <t indent="0" pn="section-9.5-2.12.1"> The syntax and semantics of fragment identifiers specified for +cbor <bcp14>SHOULD</bcp14> be as specified for "application/cbor". (At publication of RFC 8949, there is no fragment identification syntax defined for "application/cbor".)</t> <t indent="0" pn="section-9.5-2.12.2">The syntax and semantics for fragment identifiers for a specific "xxx/yyy+cbor" <bcp14>SHOULD</bcp14> be processed as follows: </t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-9.5-2.12.3"> <li pn="section-9.5-2.12.3.1">For cases defined in +cbor, where the fragment identifier resolves per the +cbor rules, then process as specified in +cbor.</li> <li pn="section-9.5-2.12.3.2">For cases defined in +cbor, where the fragment identifier does not resolve per the +cbor rules, then process as specified in "xxx/yyy+cbor".</li> <li pn="section-9.5-2.12.3.3">For cases not defined in +cbor, then process as specified in "xxx/yyy+cbor".</li> </ul> </dd> <dt pn="section-9.5-2.13">Security Considerations:</dt> <dd pn="section-9.5-2.14">See <xref target="securitycons" format="default" sectionFormat="of" derivedContent="Section 10"/> of RFC 8949.</dd> <dt pn="section-9.5-2.15">Contact:</dt> <dd pn="section-9.5-2.16"> IETF CBOR Working Group (cbor@ietf.org) or IETF Applications and Real-Time Area (art@ietf.org)</dd> <dt pn="section-9.5-2.17">Author/Change Controller:</dt> <dd pn="section-9.5-2.18">IETF</dd> </dl> </section> </section> <section anchor="securitycons" toc="include" numbered="true" removeInRFC="false" pn="section-10"> <name slugifiedName="name-security-considerations">Security Considerations</name> <t indent="0" pn="section-10-1">A network-facing application can exhibit vulnerabilities in its processing logic for incoming data. Complex parsers are well known as a likely source of such vulnerabilities, such as the ability to remotely crash a node, or even remotely execute arbitrary code on it. CBOR attempts to narrow the opportunities for introducing such vulnerabilities by reducing parser complexity, by giving the entire range of encodable values a meaning where possible.</t> <t indent="0" pn="section-10-2">Because CBOR decoders are often used as a first step in processing unvalidated input, they need to be fully prepared for all types of hostile input that may be designed to corrupt, overrun, or achieve control of the system decoding the CBOR data item. A CBOR decoder needs to assume that all input may be hostile even if it has been checked by a firewall, has come over a secure channel such as TLS, is encrypted or signed, or has come from some other source that is presumed trusted.</t> <t indent="0" pn="section-10-3"><xref target="preferred" format="default" sectionFormat="of" derivedContent="Section 4.1"/> gives examples of limitations in interoperability when using a constrained CBOR decoder with input from a CBOR encoder that uses a non-preferred serialization. When a single data item is consumed both by such a constrained decoder and a full decoder, it can lead to security issues that can be exploited by an attacker who can inject or manipulate content.</t> <t indent="0" pn="section-10-4">As discussed throughout this document, there are many values that can be considered "equivalent" in some circumstances and "not equivalent" in others. As just one example, the numeric value for the number "one" might be expressed as an integer or a bignum. A system interpreting CBOR input might accept either form for the number "one", or might reject one (or both) forms. Such acceptance or rejection can have security implications in the program that is using the interpreted input.</t> <t indent="0" pn="section-10-5">Hostile input may be constructed to overrun buffers, to overflow or underflow integer arithmetic, or to cause other decoding disruption. CBOR data items might have lengths or sizes that are intentionally extremely large or too short. Resource exhaustion attacks might attempt to lure a decoder into allocating very big data items (strings, arrays, maps, or even arbitrary precision numbers) 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.)</t> <t indent="0" pn="section-10-6">A CBOR decoder, by definition, only accepts well-formed CBOR; this is the first step to its robustness. Input that is not well-formed CBOR causes no further processing from the point where the lack of well-formedness was detected. If possible, any data decoded up to this point should have no impact on the application using the CBOR decoder.</t> <t indent="0" pn="section-10-7">In addition to ascertaining well-formedness, a CBOR decoder might also perform validity checks on the CBOR data. Alternatively, it can leave those checks to the application using the decoder. This choice needs to be clearly documented in the decoder. Beyond the validity at the CBOR level, an application also needs to ascertain that the input is in alignment with the application protocol that is serialized in CBOR.</t> <t indent="0" pn="section-10-8">The input check itself may consume resources. This is usually linear in the size of the input, which means that an attacker has to spend resources that are commensurate to the resources spent by the defender on input validation. However, an attacker might be able to craft inputs that will take longer for a target decoder to process than for the attacker to produce. Processing for arbitrary-precision numbers may exceed linear effort. Also, some hash-table implementations that are used by decoders to build in-memory representations of maps can be attacked to spend quadratic effort, unless a secret key (see Section 7 of <xref target="SIPHASH_LNCS" format="default" sectionFormat="of" derivedContent="SIPHASH_LNCS"/>, also <xref target="SIPHASH_OPEN" format="default" sectionFormat="of" derivedContent="SIPHASH_OPEN"/>) or some other mitigation is employed. Such superlinear efforts can be exploited by an attacker to exhaust resources at or before the input validator; they therefore need to be avoided in a CBOR decoder implementation. Note that tag number definitions and their implementations can add security considerations of this kind; this should then be discussed in the security considerations of the tag number definition.</t> <t indent="0" pn="section-10-9">CBOR encoders do not receive input directly from the network and are thus not directly attackable in the same way as CBOR decoders. However, CBOR encoders often have an API that takes input from another level in the implementation and can be attacked through that API. The design and implementation of that API should assume the behavior of its caller may be based on hostile input or on coding mistakes. It should check inputs for buffer overruns, overflow and underflow of integer arithmetic, and other such errors that are aimed to disrupt the encoder.</t> <t indent="0" pn="section-10-10">Protocols should be defined in such a way that potential multiple interpretations are reliably reduced to a single interpretation. For example, an attacker could make use of invalid input such as duplicate keys in maps, or exploit different precision in processing numbers to make one application base its decisions on a different interpretation than the one that will be used by a second application. To facilitate consistent interpretation, encoder and decoder implementations should provide a validity-checking mode of operation (<xref target="validity-checking" format="default" sectionFormat="of" derivedContent="Section 5.4"/>). Note, however, that a generic decoder cannot know about all requirements that an application poses on its input data; it is therefore not relieving the application from performing its own input checking. Also, since the set of defined tag numbers evolves, the application may employ a tag number that is not yet supported for validity checking by the generic decoder it uses. Generic decoders therefore need to document which tag numbers they support and what validity checking they provide for those tag numbers as well as for basic CBOR (UTF-8 checking, duplicate map key checking).</t> <t indent="0" pn="section-10-11"><xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/> notes that using the non-preferred choice of a bignum representation instead of a basic integer for encoding a number is not intended to have application semantics, but it can have such semantics if an application receiving CBOR data is using a decoder in the basic generic data model. This disparity causes a security issue if the two sets of semantics differ. Thus, applications using CBOR need to specify the data model that they are using for each use of CBOR data.</t> <t indent="0" pn="section-10-12">It is common to convert CBOR data to other formats. In many cases, CBOR has more expressive types than other formats; this is particularly true for the common conversion to JSON. The loss of type information can cause security issues for the systems that are processing the less-expressive data.</t> <t indent="0" pn="section-10-13"><xref target="converting-from-json" format="default" sectionFormat="of" derivedContent="Section 6.2"/> describes a possibly common usage scenario of converting between CBOR and JSON that could allow an attack if the attacker knows that the application is performing the conversion.</t> <t indent="0" pn="section-10-14">Security considerations for the use of base16 and base64 from <xref target="RFC4648" format="default" sectionFormat="of" derivedContent="RFC4648"/>, and the use of UTF-8 from <xref target="RFC3629" format="default" sectionFormat="of" derivedContent="RFC3629"/>, are relevant to CBOR as well.</t> </section> </middle> <back> <displayreference target="I-D.bormann-cbor-notable-tags" to="CBOR-TAGS"/> <references pn="section-11"> <name slugifiedName="name-references">References</name> <references pn="section-11.1"> <name slugifiedName="name-normative-references">Normative References</name> <reference anchor="C" target="https://www.iso.org/standard/74528.html" quoteTitle="true" derivedAnchor="C"> <front> <title>Information technology - Programming languages - C</title> <author> <organization showOnFrontPage="true">International Organization for Standardization</organization> </author> <date year="2018" month="June"/> </front> <seriesInfo name="ISO/IEC" value="9899:2018"/> <refcontent>Fourth Edition</refcontent> </reference> <reference anchor="Cplusplus20" target="https://isocpp.org/files/papers/N4860.pdf" quoteTitle="true" derivedAnchor="Cplusplus20"> <front> <title>Programming languages - C++</title> <author> <organization showOnFrontPage="true">International Organization for Standardization</organization> </author> <date year="2020" month="March"/> </front> <seriesInfo name="ISO/IEC" value="DIS 14882"/> <seriesInfo name="ISO/IEC" value="ISO/IEC JTC1 SC22 WG21 N 4860"/> <refcontent>Sixth Edition</refcontent> </reference> <reference anchor="IEEE754" target="https://ieeexplore.ieee.org/document/8766229" quoteTitle="true" derivedAnchor="IEEE754"> <front> <title>IEEE Standard for Floating-Point Arithmetic</title> <author> <organization showOnFrontPage="true">IEEE</organization> </author> <date/> </front> <seriesInfo name="IEEE Std" value="754-2019"/> <seriesInfo name="DOI" value="10.1109/IEEESTD.2019.8766229"/> </reference> <reference anchor="RFC2045" target="https://www.rfc-editor.org/info/rfc2045" quoteTitle="true" derivedAnchor="RFC2045"> <front> <title>Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies</title> <author initials="N." surname="Freed" fullname="N. Freed"> <organization showOnFrontPage="true"/> </author> <author initials="N." surname="Borenstein" fullname="N. Borenstein"> <organization showOnFrontPage="true"/> </author> <date year="1996" month="November"/> <abstract> <t indent="0">This initial document specifies the various headers used to describe the structure of MIME messages. [STANDARDS-TRACK]</t> </abstract> </front> <seriesInfo name="RFC" value="2045"/> <seriesInfo name="DOI" value="10.17487/RFC2045"/> </reference> <reference anchor="RFC2119" target="https://www.rfc-editor.org/info/rfc2119" quoteTitle="true" derivedAnchor="RFC2119"> <front> <title>Key words for use in RFCs to Indicate Requirement Levels</title> <author initials="S." surname="Bradner" fullname="S. Bradner"> <organization showOnFrontPage="true"/> </author> <date year="1997" month="March"/> <abstract> <t indent="0">In many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t> </abstract> </front> <seriesInfo name="BCP" value="14"/> <seriesInfo name="RFC" value="2119"/> <seriesInfo name="DOI" value="10.17487/RFC2119"/> </reference> <reference anchor="RFC3339" target="https://www.rfc-editor.org/info/rfc3339" quoteTitle="true" derivedAnchor="RFC3339"> <front> <title>Date and Time on the Internet: Timestamps</title> <author initials="G." surname="Klyne" fullname="G. Klyne"> <organization showOnFrontPage="true"/> </author> <author initials="C." surname="Newman" fullname="C. Newman"> <organization showOnFrontPage="true"/> </author> <date year="2002" month="July"/> <abstract> <t indent="0">This document defines a date and time format for use in Internet protocols that is a profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.</t> </abstract> </front> <seriesInfo name="RFC" value="3339"/> <seriesInfo name="DOI" value="10.17487/RFC3339"/> </reference> <reference anchor="RFC3629" target="https://www.rfc-editor.org/info/rfc3629" quoteTitle="true" derivedAnchor="RFC3629"> <front> <title>UTF-8, a transformation format of ISO 10646</title> <author initials="F." surname="Yergeau" fullname="F. Yergeau"> <organization showOnFrontPage="true"/> </author> <date year="2003" month="November"/> <abstract> <t indent="0">ISO/IEC 10646-1 defines a large character set called the Universal Character Set (UCS) which encompasses most of the world's writing systems. The originally proposed encodings of the UCS, however, were not compatible with many current applications and protocols, and this has led to the development of UTF-8, the object of this memo. UTF-8 has the characteristic of preserving the full US-ASCII range, providing compatibility with file systems, parsers and other software that rely on US-ASCII values but are transparent to other values. This memo obsoletes and replaces RFC 2279.</t> </abstract> </front> <seriesInfo name="STD" value="63"/> <seriesInfo name="RFC" value="3629"/> <seriesInfo name="DOI" value="10.17487/RFC3629"/> </reference> <reference anchor="RFC3986" target="https://www.rfc-editor.org/info/rfc3986" quoteTitle="true" derivedAnchor="RFC3986"> <front> <title>Uniform Resource Identifier (URI): Generic Syntax</title> <author initials="T." surname="Berners-Lee" fullname="T. Berners-Lee"> <organization showOnFrontPage="true"/> </author> <author initials="R." surname="Fielding" fullname="R. Fielding"> <organization showOnFrontPage="true"/> </author> <author initials="L." surname="Masinter" fullname="L. Masinter"> <organization showOnFrontPage="true"/> </author> <date year="2005" month="January"/> <abstract> <t indent="0">A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource. This specification defines the generic URI syntax and a process for resolving URI references that might be in relative form, along with guidelines and security considerations for the use of URIs on the Internet. The URI syntax defines a grammar that is a superset of all valid URIs, allowing an implementation to parse the common components of a URI reference without knowing the scheme-specific requirements of every possible identifier. This specification does not define a generative grammar for URIs; that task is performed by the individual specifications of each URI scheme. [STANDARDS-TRACK]</t> </abstract> </front> <seriesInfo name="STD" value="66"/> <seriesInfo name="RFC" value="3986"/> <seriesInfo name="DOI" value="10.17487/RFC3986"/> </reference> <reference anchor="RFC4287" target="https://www.rfc-editor.org/info/rfc4287" quoteTitle="true" derivedAnchor="RFC4287"> <front> <title>The Atom Syndication Format</title> <author initials="M." surname="Nottingham" fullname="M. Nottingham" role="editor"> <organization showOnFrontPage="true"/> </author> <author initials="R." surname="Sayre" fullname="R. Sayre" role="editor"> <organization showOnFrontPage="true"/> </author> <date year="2005" month="December"/> <abstract> <t indent="0">This document specifies Atom, an XML-based Web content and metadata syndication format. [STANDARDS-TRACK]</t> </abstract> </front> <seriesInfo name="RFC" value="4287"/> <seriesInfo name="DOI" value="10.17487/RFC4287"/> </reference> <reference anchor="RFC4648" target="https://www.rfc-editor.org/info/rfc4648" quoteTitle="true" derivedAnchor="RFC4648"> <front> <title>The Base16, Base32, and Base64 Data Encodings</title> <author initials="S." surname="Josefsson" fullname="S. Josefsson"> <organization showOnFrontPage="true"/> </author> <date year="2006" month="October"/> <abstract> <t indent="0">This document describes the commonly used base 64, base 32, and base 16 encoding schemes. It also discusses the use of line-feeds in encoded data, use of padding in encoded data, use of non-alphabet characters in encoded data, use of different encoding alphabets, and canonical encodings. [STANDARDS-TRACK]</t> </abstract> </front> <seriesInfo name="RFC" value="4648"/> <seriesInfo name="DOI" value="10.17487/RFC4648"/> </reference> <reference anchor="RFC8126" target="https://www.rfc-editor.org/info/rfc8126" quoteTitle="true" derivedAnchor="RFC8126"> <front> <title>Guidelines for Writing an IANA Considerations Section in RFCs</title> <author initials="M." surname="Cotton" fullname="M. Cotton"> <organization showOnFrontPage="true"/> </author> <author initials="B." surname="Leiba" fullname="B. Leiba"> <organization showOnFrontPage="true"/> </author> <author initials="T." surname="Narten" fullname="T. Narten"> <organization showOnFrontPage="true"/> </author> <date year="2017" month="June"/> <abstract> <t indent="0">Many protocols make use of points of extensibility that use constants to identify various protocol parameters. To ensure that the values in these fields do not have conflicting uses and to promote interoperability, their allocations are often coordinated by a central record keeper. For IETF protocols, that role is filled by the Internet Assigned Numbers Authority (IANA).</t> <t indent="0">To make assignments in a given registry prudently, guidance describing the conditions under which new values should be assigned, as well as when and how modifications to existing values can be made, is needed. This document defines a framework for the documentation of these guidelines by specification authors, in order to assure that the provided guidance for the IANA Considerations is clear and addresses the various issues that are likely in the operation of a registry.</t> <t indent="0">This is the third edition of this document; it obsoletes RFC 5226.</t> </abstract> </front> <seriesInfo name="BCP" value="26"/> <seriesInfo name="RFC" value="8126"/> <seriesInfo name="DOI" value="10.17487/RFC8126"/> </reference> <reference anchor="RFC8174" target="https://www.rfc-editor.org/info/rfc8174" quoteTitle="true" derivedAnchor="RFC8174"> <front> <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title> <author initials="B." surname="Leiba" fullname="B. Leiba"> <organization showOnFrontPage="true"/> </author> <date year="2017" month="May"/> <abstract> <t indent="0">RFC 2119 specifies common key words that may be used in protocol specifications. This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.</t> </abstract> </front> <seriesInfo name="BCP" value="14"/> <seriesInfo name="RFC" value="8174"/> <seriesInfo name="DOI" value="10.17487/RFC8174"/> </reference> <reference anchor="TIME_T" target="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16" quoteTitle="true" derivedAnchor="TIME_T"> <front> <title>The Open Group Base Specifications</title> <author> <organization showOnFrontPage="true">The Open Group</organization> </author> <date year="2018"/> </front> <seriesInfo name="IEEE Std" value="1003.1"/> <refcontent>Section 4.16, 'Seconds Since the Epoch'</refcontent> <refcontent>Issue 7, 2018 Edition</refcontent> </reference> </references> <references pn="section-11.2"> <name slugifiedName="name-informative-references">Informative References</name> <reference anchor="ASN.1" target="https://www.itu.int/rec/T-REC-X.690-201508-I/en" quoteTitle="true" derivedAnchor="ASN.1"> <front> <title>Information Technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)</title> <author> <organization showOnFrontPage="true">International Telecommunication Union</organization> </author> <date year="2015"/> </front> <seriesInfo name="ITU-T" value="Recommendation X.690"/> </reference> <reference anchor="BSON" target="http://bsonspec.org/" quoteTitle="true" derivedAnchor="BSON"> <front> <title>BSON - Binary JSON</title> <author> <organization showOnFrontPage="true">Various</organization> </author> </front> </reference> <reference anchor="I-D.bormann-cbor-notable-tags" quoteTitle="true" target="https://tools.ietf.org/html/draft-bormann-cbor-notable-tags-02" derivedAnchor="CBOR-TAGS"> <front> <title>Notable CBOR Tags</title> <author initials="C" surname="Bormann" fullname="Carsten Bormann"> <organization showOnFrontPage="true"/> </author> <date month="June" day="25" year="2020"/> <abstract> <t indent="0">The Concise Binary Object Representation (CBOR, RFC 7049) 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. In CBOR, one point of extensibility is the definition of CBOR tags. RFC 7049 and its revision 7049bis define a basic set of tags as well as a registry that can be used to contribute additional tag definitions [IANA.cbor-tags]. Since RFC 7049 was published, some 80 tag definitions have been added to that registry. The present document provides a roadmap to a large subset of these tag definitions. Where applicable, it points to a IETF standards or standard development document that specifies the tag. Where no such document exists, the intention is to collect specification information from the sources of the registrations. After some more development, the present document is intended to be useful as a reference document for the IANA registrations of the CBOR tags the definitions of which have been collected.</t> </abstract> </front> <seriesInfo name="Internet-Draft" value="draft-bormann-cbor-notable-tags-02"/> <format type="TXT" target="http://www.ietf.org/internet-drafts/draft-bormann-cbor-notable-tags-02.txt"/> <refcontent>Work in Progress</refcontent> </reference> <reference anchor="ECMA262" target="https://www.ecma-international.org/publications/standards/Ecma-262.htm" quoteTitle="true" derivedAnchor="ECMA262"> <front> <title>ECMAScript 2020 Language Specification</title> <author> <organization showOnFrontPage="true">Ecma International</organization> </author> <date year="2020" month="June"/> </front> <refcontent>Standard ECMA-262, 11th Edition</refcontent> </reference> <reference anchor="Err3764" target="https://www.rfc-editor.org/errata/eid3764" quoteTitle="false" derivedAnchor="Err3764"> <front> <title>Erratum ID 3764</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err3770" target="https://www.rfc-editor.org/errata/eid3770" quoteTitle="false" derivedAnchor="Err3770"> <front> <title>Erratum ID 3770</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err4294" target="https://www.rfc-editor.org/errata/eid4294" quoteTitle="false" derivedAnchor="Err4294"> <front> <title>Erratum ID 4294</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err4409" target="https://www.rfc-editor.org/errata/eid4409" quoteTitle="false" derivedAnchor="Err4409"> <front> <title>Erratum ID 4409</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err4963" target="https://www.rfc-editor.org/errata/eid4963" quoteTitle="false" derivedAnchor="Err4963"> <front> <title>Erratum ID 4963</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err4964" target="https://www.rfc-editor.org/errata/eid4964" quoteTitle="false" derivedAnchor="Err4964"> <front> <title>Erratum ID 4964</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err5434" target="https://www.rfc-editor.org/errata/eid5434" quoteTitle="false" derivedAnchor="Err5434"> <front> <title>Erratum ID 5434</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err5763" target="https://www.rfc-editor.org/errata/eid5763" quoteTitle="false" derivedAnchor="Err5763"> <front> <title>Erratum ID 5763</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="Err5917" target="https://www.rfc-editor.org/errata/eid5917" quoteTitle="false" derivedAnchor="Err5917"> <front> <title>Erratum ID 5917</title> <author> <organization showOnFrontPage="true">RFC Errata</organization> </author> </front> <refcontent>RFC 7049</refcontent> </reference> <reference anchor="IANA.cbor-simple-values" target="https://www.iana.org/assignments/cbor-simple-values" quoteTitle="true" derivedAnchor="IANA.cbor-simple-values"> <front> <title>Concise Binary Object Representation (CBOR) Simple Values</title> <author> <organization showOnFrontPage="true">IANA</organization> </author> </front> </reference> <reference anchor="IANA.cbor-tags" target="https://www.iana.org/assignments/cbor-tags" quoteTitle="true" derivedAnchor="IANA.cbor-tags"> <front> <title>Concise Binary Object Representation (CBOR) Tags</title> <author> <organization showOnFrontPage="true">IANA</organization> </author> </front> </reference> <reference anchor="IANA.core-parameters" target="https://www.iana.org/assignments/core-parameters" quoteTitle="true" derivedAnchor="IANA.core-parameters"> <front> <title>Constrained RESTful Environments (CoRE) Parameters</title> <author> <organization showOnFrontPage="true">IANA</organization> </author> </front> </reference> <reference anchor="IANA.media-types" target="https://www.iana.org/assignments/media-types" quoteTitle="true" derivedAnchor="IANA.media-types"> <front> <title>Media Types</title> <author> <organization showOnFrontPage="true">IANA</organization> </author> </front> </reference> <reference anchor="IANA.structured-suffix" target="https://www.iana.org/assignments/media-type-structured-suffix" quoteTitle="true" derivedAnchor="IANA.structured-suffix"> <front> <title>Structured Syntax Suffixes</title> <author> <organization showOnFrontPage="true">IANA</organization> </author> </front> </reference> <reference anchor="MessagePack" target="https://msgpack.org/" quoteTitle="true" derivedAnchor="MessagePack"> <front> <title>MessagePack</title> <author initials="S." surname="Furuhashi" fullname="Sadayuki Furuhashi"> <organization showOnFrontPage="true"/> </author> </front> </reference> <reference anchor="PCRE" target="https://www.pcre.org/" quoteTitle="true" derivedAnchor="PCRE"> <front> <title>PCRE - Perl Compatible Regular Expressions</title> <author initials="P." surname="Hazel" fullname="Philip Hazel"> <organization showOnFrontPage="true"/> </author> </front> </reference> <reference anchor="RFC0713" target="https://www.rfc-editor.org/info/rfc713" quoteTitle="true" derivedAnchor="RFC0713"> <front> <title>MSDTP-Message Services Data Transmission Protocol</title> <author initials="J." surname="Haverty" fullname="J. Haverty"> <organization showOnFrontPage="true"/> </author> <date year="1976" month="April"/> </front> <seriesInfo name="RFC" value="713"/> <seriesInfo name="DOI" value="10.17487/RFC0713"/> </reference> <reference anchor="RFC6838" target="https://www.rfc-editor.org/info/rfc6838" quoteTitle="true" derivedAnchor="RFC6838"> <front> <title>Media Type Specifications and Registration Procedures</title> <author initials="N." surname="Freed" fullname="N. Freed"> <organization showOnFrontPage="true"/> </author> <author initials="J." surname="Klensin" fullname="J. Klensin"> <organization showOnFrontPage="true"/> </author> <author initials="T." surname="Hansen" fullname="T. Hansen"> <organization showOnFrontPage="true"/> </author> <date year="2013" month="January"/> <abstract> <t indent="0">This document defines procedures for the specification and registration of media types for use in HTTP, MIME, and other Internet protocols. This memo documents an Internet Best Current Practice.</t> </abstract> </front> <seriesInfo name="BCP" value="13"/> <seriesInfo name="RFC" value="6838"/> <seriesInfo name="DOI" value="10.17487/RFC6838"/> </reference> <reference anchor="RFC7049" target="https://www.rfc-editor.org/info/rfc7049" quoteTitle="true" derivedAnchor="RFC7049"> <front> <title>Concise Binary Object Representation (CBOR)</title> <author initials="C." surname="Bormann" fullname="C. Bormann"> <organization showOnFrontPage="true"/> </author> <author initials="P." surname="Hoffman" fullname="P. Hoffman"> <organization showOnFrontPage="true"/> </author> <date year="2013" month="October"/> <abstract> <t indent="0">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.</t> </abstract> </front> <seriesInfo name="RFC" value="7049"/> <seriesInfo name="DOI" value="10.17487/RFC7049"/> </reference> <reference anchor="RFC7228" target="https://www.rfc-editor.org/info/rfc7228" quoteTitle="true" derivedAnchor="RFC7228"> <front> <title>Terminology for Constrained-Node Networks</title> <author initials="C." surname="Bormann" fullname="C. Bormann"> <organization showOnFrontPage="true"/> </author> <author initials="M." surname="Ersue" fullname="M. Ersue"> <organization showOnFrontPage="true"/> </author> <author initials="A." surname="Keranen" fullname="A. Keranen"> <organization showOnFrontPage="true"/> </author> <date year="2014" month="May"/> <abstract> <t indent="0">The Internet Protocol Suite is increasingly used on small devices with severe constraints on power, memory, and processing resources, creating constrained-node networks. This document provides a number of basic terms that have been useful in the standardization work for constrained-node networks.</t> </abstract> </front> <seriesInfo name="RFC" value="7228"/> <seriesInfo name="DOI" value="10.17487/RFC7228"/> </reference> <reference anchor="RFC7493" target="https://www.rfc-editor.org/info/rfc7493" quoteTitle="true" derivedAnchor="RFC7493"> <front> <title>The I-JSON Message Format</title> <author initials="T." surname="Bray" fullname="T. Bray" role="editor"> <organization showOnFrontPage="true"/> </author> <date year="2015" month="March"/> <abstract> <t indent="0">I-JSON (short for "Internet JSON") is a restricted profile of JSON designed to maximize interoperability and increase confidence that software can process it successfully with predictable results.</t> </abstract> </front> <seriesInfo name="RFC" value="7493"/> <seriesInfo name="DOI" value="10.17487/RFC7493"/> </reference> <reference anchor="RFC7991" target="https://www.rfc-editor.org/info/rfc7991" quoteTitle="true" derivedAnchor="RFC7991"> <front> <title>The "xml2rfc" Version 3 Vocabulary</title> <author initials="P." surname="Hoffman" fullname="P. Hoffman"> <organization showOnFrontPage="true"/> </author> <date year="2016" month="December"/> <abstract> <t indent="0">This document defines the "xml2rfc" version 3 vocabulary: an XML-based language used for writing RFCs and Internet-Drafts. It is heavily derived from the version 2 vocabulary that is also under discussion. This document obsoletes the v2 grammar described in RFC 7749.</t> </abstract> </front> <seriesInfo name="RFC" value="7991"/> <seriesInfo name="DOI" value="10.17487/RFC7991"/> </reference> <reference anchor="RFC8259" target="https://www.rfc-editor.org/info/rfc8259" quoteTitle="true" derivedAnchor="RFC8259"> <front> <title>The JavaScript Object Notation (JSON) Data Interchange Format</title> <author initials="T." surname="Bray" fullname="T. Bray" role="editor"> <organization showOnFrontPage="true"/> </author> <date year="2017" month="December"/> <abstract> <t indent="0">JavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard. JSON defines a small set of formatting rules for the portable representation of structured data.</t> <t indent="0">This document removes inconsistencies with other specifications of JSON, repairs specification errors, and offers experience-based interoperability guidance.</t> </abstract> </front> <seriesInfo name="STD" value="90"/> <seriesInfo name="RFC" value="8259"/> <seriesInfo name="DOI" value="10.17487/RFC8259"/> </reference> <reference anchor="RFC8610" target="https://www.rfc-editor.org/info/rfc8610" quoteTitle="true" derivedAnchor="RFC8610"> <front> <title>Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures</title> <author initials="H." surname="Birkholz" fullname="H. Birkholz"> <organization showOnFrontPage="true"/> </author> <author initials="C." surname="Vigano" fullname="C. Vigano"> <organization showOnFrontPage="true"/> </author> <author initials="C." surname="Bormann" fullname="C. Bormann"> <organization showOnFrontPage="true"/> </author> <date year="2019" month="June"/> <abstract> <t indent="0">This document proposes a notational convention to express Concise Binary Object Representation (CBOR) data structures (RFC 7049). Its main goal is to provide an easy and unambiguous way to express structures for protocol messages and data formats that use CBOR or JSON.</t> </abstract> </front> <seriesInfo name="RFC" value="8610"/> <seriesInfo name="DOI" value="10.17487/RFC8610"/> </reference> <reference anchor="RFC8618" target="https://www.rfc-editor.org/info/rfc8618" quoteTitle="true" derivedAnchor="RFC8618"> <front> <title>Compacted-DNS (C-DNS): A Format for DNS Packet Capture</title> <author initials="J." surname="Dickinson" fullname="J. Dickinson"> <organization showOnFrontPage="true"/> </author> <author initials="J." surname="Hague" fullname="J. Hague"> <organization showOnFrontPage="true"/> </author> <author initials="S." surname="Dickinson" fullname="S. Dickinson"> <organization showOnFrontPage="true"/> </author> <author initials="T." surname="Manderson" fullname="T. Manderson"> <organization showOnFrontPage="true"/> </author> <author initials="J." surname="Bond" fullname="J. Bond"> <organization showOnFrontPage="true"/> </author> <date year="2019" month="September"/> <abstract> <t indent="0">This document describes a data representation for collections of DNS messages. The format is designed for efficient storage and transmission of large packet captures of DNS traffic; it attempts to minimize the size of such packet capture files but retain the full DNS message contents along with the most useful transport metadata. It is intended to assist with the development of DNS traffic- monitoring applications.</t> </abstract> </front> <seriesInfo name="RFC" value="8618"/> <seriesInfo name="DOI" value="10.17487/RFC8618"/> </reference> <reference anchor="RFC8742" target="https://www.rfc-editor.org/info/rfc8742" quoteTitle="true" derivedAnchor="RFC8742"> <front> <title>Concise Binary Object Representation (CBOR) Sequences</title> <author initials="C." surname="Bormann" fullname="C. Bormann"> <organization showOnFrontPage="true"/> </author> <date year="2020" month="February"/> <abstract> <t indent="0">This document describes the Concise Binary Object Representation (CBOR) Sequence format and associated media type "application/cbor-seq". A CBOR Sequence consists of any number of encoded CBOR data items, simply concatenated in sequence.</t> <t indent="0">Structured syntax suffixes for media types allow other media types to build on them and make it explicit that they are built on an existing media type as their foundation. This specification defines and registers "+cbor-seq" as a structured syntax suffix for CBOR Sequences.</t> </abstract> </front> <seriesInfo name="RFC" value="8742"/> <seriesInfo name="DOI" value="10.17487/RFC8742"/> </reference> <reference anchor="RFC8746" target="https://www.rfc-editor.org/info/rfc8746" quoteTitle="true" derivedAnchor="RFC8746"> <front> <title>Concise Binary Object Representation (CBOR) Tags for Typed Arrays</title> <author initials="C." surname="Bormann" fullname="C. Bormann" role="editor"> <organization showOnFrontPage="true"/> </author> <date year="2020" month="February"/> <abstract> <t indent="0">The Concise Binary Object Representation (CBOR), as defined in RFC 7049, 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.</t> <t indent="0">This document makes use of this extensibility to define a number of CBOR tags for typed arrays of numeric data, as well as additional tags for multi-dimensional and homogeneous arrays. It is intended as the reference document for the IANA registration of the CBOR tags defined.</t> </abstract> </front> <seriesInfo name="RFC" value="8746"/> <seriesInfo name="DOI" value="10.17487/RFC8746"/> </reference> <reference anchor="SIPHASH_LNCS" quoteTitle="true" target="https://doi.org/10.1007/978-3-642-34931-7_28" derivedAnchor="SIPHASH_LNCS"> <front> <title>SipHash: A Fast Short-Input PRF</title> <author initials="J." surname="Aumasson" fullname="Jean-Philippe Aumasson"> <organization showOnFrontPage="true"/> </author> <author initials="D." surname="Bernstein" fullname="Daniel J. Bernstein"> <organization showOnFrontPage="true"/> </author> <date year="2012"/> </front> <seriesInfo name="DOI" value="10.1007/978-3-642-34931-7_28"/> <refcontent>Progress in Cryptology - INDOCRYPT 2012, pp. 489-508</refcontent> </reference> <reference anchor="SIPHASH_OPEN" target="https://www.aumasson.jp/siphash/siphash.pdf" quoteTitle="true" derivedAnchor="SIPHASH_OPEN"> <front> <title>SipHash: a fast short-input PRF</title> <author initials="J." surname="Aumasson" fullname="Jean-Philippe Aumasson"> <organization showOnFrontPage="true"/> </author> <author initials="D.J." surname="Bernstein" fullname="Daniel J. Bernstein"> <organization showOnFrontPage="true"/> </author> <date/> </front> </reference> <reference anchor="YAML" target="https://www.yaml.org/spec/1.2/spec.html" quoteTitle="true" derivedAnchor="YAML"> <front> <title>YAML Ain't Markup Language (YAML[TM]) Version 1.2</title> <author initials="O." surname="Ben-Kiki" fullname="Oren Ben-Kiki"> <organization showOnFrontPage="true"/> </author> <author initials="C." surname="Evans" fullname="Clark Evans"> <organization showOnFrontPage="true"/> </author> <author initials="I.d." surname="Net" fullname="Ingy döt Net"> <organization showOnFrontPage="true"/> </author> <date year="2009" month="October"/> </front> <refcontent>3rd Edition</refcontent> </reference> </references> </references> <section anchor="examples" toc="include" numbered="true" removeInRFC="false" pn="section-appendix.a"> <name slugifiedName="name-examples-of-encoded-cbor-da">Examples of Encoded CBOR Data Items</name> <t indent="0" pn="section-appendix.a-1">The following table provides some CBOR-encoded values in hexadecimal (right column), together with diagnostic notation for these values (left column). Note that the string "\u00fc" is one form of diagnostic notation for a UTF-8 string containing the single Unicode character <u format="num-name-lit" pn="u-1">ü</u>. Similarly, "\u6c34" is a UTF-8 string in diagnostic notation with a single character <u format="num-name-lit" pn="u-2">水</u>, often representing "water", and "\ud800\udd51" is a UTF-8 string in diagnostic notation with a single character <u format="num-name-lit" pn="u-3">𐅑</u>. (Note that all these single-character strings could also be represented in native UTF-8 in diagnostic notation, just not if an ASCII-only specification is required.) In the diagnostic notation provided for bignums, their intended numeric value is shown as a decimal number (such as 18446744073709551616) instead of a tagged byte string (such as 2(h'010000000000000000')).</t> <table anchor="table_examples" align="center" pn="table-6"> <name slugifiedName="name-examples-of-encoded-cbor-dat">Examples of Encoded CBOR Data Items</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">Diagnostic</th> <th align="left" colspan="1" rowspan="1">Encoded</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">0</td> <td align="left" colspan="1" rowspan="1">0x00</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1</td> <td align="left" colspan="1" rowspan="1">0x01</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">10</td> <td align="left" colspan="1" rowspan="1">0x0a</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">23</td> <td align="left" colspan="1" rowspan="1">0x17</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">24</td> <td align="left" colspan="1" rowspan="1">0x1818</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">25</td> <td align="left" colspan="1" rowspan="1">0x1819</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">100</td> <td align="left" colspan="1" rowspan="1">0x1864</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1000</td> <td align="left" colspan="1" rowspan="1">0x1903e8</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1000000</td> <td align="left" colspan="1" rowspan="1">0x1a000f4240</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1000000000000</td> <td align="left" colspan="1" rowspan="1">0x1b000000e8d4a51000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">18446744073709551615</td> <td align="left" colspan="1" rowspan="1">0x1bffffffffffffffff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">18446744073709551616</td> <td align="left" colspan="1" rowspan="1">0xc249010000000000000000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-18446744073709551616</td> <td align="left" colspan="1" rowspan="1">0x3bffffffffffffffff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-18446744073709551617</td> <td align="left" colspan="1" rowspan="1">0xc349010000000000000000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-1</td> <td align="left" colspan="1" rowspan="1">0x20</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-10</td> <td align="left" colspan="1" rowspan="1">0x29</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-100</td> <td align="left" colspan="1" rowspan="1">0x3863</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-1000</td> <td align="left" colspan="1" rowspan="1">0x3903e7</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0.0</td> <td align="left" colspan="1" rowspan="1">0xf90000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-0.0</td> <td align="left" colspan="1" rowspan="1">0xf98000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1.0</td> <td align="left" colspan="1" rowspan="1">0xf93c00</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1.1</td> <td align="left" colspan="1" rowspan="1">0xfb3ff199999999999a</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1.5</td> <td align="left" colspan="1" rowspan="1">0xf93e00</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">65504.0</td> <td align="left" colspan="1" rowspan="1">0xf97bff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">100000.0</td> <td align="left" colspan="1" rowspan="1">0xfa47c35000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">3.4028234663852886e+38</td> <td align="left" colspan="1" rowspan="1">0xfa7f7fffff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1.0e+300</td> <td align="left" colspan="1" rowspan="1">0xfb7e37e43c8800759c</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">5.960464477539063e-8</td> <td align="left" colspan="1" rowspan="1">0xf90001</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0.00006103515625</td> <td align="left" colspan="1" rowspan="1">0xf90400</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-4.0</td> <td align="left" colspan="1" rowspan="1">0xf9c400</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-4.1</td> <td align="left" colspan="1" rowspan="1">0xfbc010666666666666</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">Infinity</td> <td align="left" colspan="1" rowspan="1">0xf97c00</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">NaN</td> <td align="left" colspan="1" rowspan="1">0xf97e00</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-Infinity</td> <td align="left" colspan="1" rowspan="1">0xf9fc00</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">Infinity</td> <td align="left" colspan="1" rowspan="1">0xfa7f800000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">NaN</td> <td align="left" colspan="1" rowspan="1">0xfa7fc00000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-Infinity</td> <td align="left" colspan="1" rowspan="1">0xfaff800000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">Infinity</td> <td align="left" colspan="1" rowspan="1">0xfb7ff0000000000000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">NaN</td> <td align="left" colspan="1" rowspan="1">0xfb7ff8000000000000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">-Infinity</td> <td align="left" colspan="1" rowspan="1">0xfbfff0000000000000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">false</td> <td align="left" colspan="1" rowspan="1">0xf4</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">true</td> <td align="left" colspan="1" rowspan="1">0xf5</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">null</td> <td align="left" colspan="1" rowspan="1">0xf6</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">undefined</td> <td align="left" colspan="1" rowspan="1">0xf7</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">simple(16)</td> <td align="left" colspan="1" rowspan="1">0xf0</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">simple(255)</td> <td align="left" colspan="1" rowspan="1">0xf8ff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0("2013-03-21T20:04:00Z")</td> <td align="left" colspan="1" rowspan="1">0xc074323031332d30332d32315432303a 30343a30305a</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1(1363896240)</td> <td align="left" colspan="1" rowspan="1">0xc11a514b67b0</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">1(1363896240.5)</td> <td align="left" colspan="1" rowspan="1">0xc1fb41d452d9ec200000</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">23(h'01020304')</td> <td align="left" colspan="1" rowspan="1">0xd74401020304</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">24(h'6449455446')</td> <td align="left" colspan="1" rowspan="1">0xd818456449455446</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">32("http://www.example.com")</td> <td align="left" colspan="1" rowspan="1">0xd82076687474703a2f2f7777772e6578 616d706c652e636f6d</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">h''</td> <td align="left" colspan="1" rowspan="1">0x40</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">h'01020304'</td> <td align="left" colspan="1" rowspan="1">0x4401020304</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">""</td> <td align="left" colspan="1" rowspan="1">0x60</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">"a"</td> <td align="left" colspan="1" rowspan="1">0x6161</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">"IETF"</td> <td align="left" colspan="1" rowspan="1">0x6449455446</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">"\"\\"</td> <td align="left" colspan="1" rowspan="1">0x62225c</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">"\u00fc"</td> <td align="left" colspan="1" rowspan="1">0x62c3bc</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">"\u6c34"</td> <td align="left" colspan="1" rowspan="1">0x63e6b0b4</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">"\ud800\udd51"</td> <td align="left" colspan="1" rowspan="1">0x64f0908591</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[]</td> <td align="left" colspan="1" rowspan="1">0x80</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[1, 2, 3]</td> <td align="left" colspan="1" rowspan="1">0x83010203</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[1, [2, 3], [4, 5]]</td> <td align="left" colspan="1" rowspan="1">0x8301820203820405</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]</td> <td align="left" colspan="1" rowspan="1">0x98190102030405060708090a0b0c0d0e 0f101112131415161718181819</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">{}</td> <td align="left" colspan="1" rowspan="1">0xa0</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">{1: 2, 3: 4}</td> <td align="left" colspan="1" rowspan="1">0xa201020304</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">{"a": 1, "b": [2, 3]}</td> <td align="left" colspan="1" rowspan="1">0xa26161016162820203</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">["a", {"b": "c"}]</td> <td align="left" colspan="1" rowspan="1">0x826161a161626163</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">{"a": "A", "b": "B", "c": "C", "d": "D", "e": "E"}</td> <td align="left" colspan="1" rowspan="1">0xa5616161416162614261636143616461 4461656145</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">(_ h'0102', h'030405')</td> <td align="left" colspan="1" rowspan="1">0x5f42010243030405ff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">(_ "strea", "ming")</td> <td align="left" colspan="1" rowspan="1">0x7f657374726561646d696e67ff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[_ ]</td> <td align="left" colspan="1" rowspan="1">0x9fff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[_ 1, [2, 3], [_ 4, 5]]</td> <td align="left" colspan="1" rowspan="1">0x9f018202039f0405ffff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[_ 1, [2, 3], [4, 5]]</td> <td align="left" colspan="1" rowspan="1">0x9f01820203820405ff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[1, [2, 3], [_ 4, 5]]</td> <td align="left" colspan="1" rowspan="1">0x83018202039f0405ff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[1, [_ 2, 3], [4, 5]]</td> <td align="left" colspan="1" rowspan="1">0x83019f0203ff820405</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">[_ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]</td> <td align="left" colspan="1" rowspan="1">0x9f0102030405060708090a0b0c0d0e0f 101112131415161718181819ff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">{_ "a": 1, "b": [_ 2, 3]}</td> <td align="left" colspan="1" rowspan="1">0xbf61610161629f0203ffff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">["a", {_ "b": "c"}]</td> <td align="left" colspan="1" rowspan="1">0x826161bf61626163ff</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">{_ "Fun": true, "Amt": -2}</td> <td align="left" colspan="1" rowspan="1">0xbf6346756ef563416d7421ff</td> </tr> </tbody> </table> </section> <section anchor="jump-table" toc="include" numbered="true" removeInRFC="false" pn="section-appendix.b"> <name slugifiedName="name-jump-table-for-initial-byte">Jump Table for Initial Byte</name> <t indent="0" pn="section-appendix.b-1">For brevity, this jump table does not show initial bytes that are reserved for future extension. It also only shows a selection of the initial bytes that can be used for optional features. (All unsigned integers are in network byte order.)</t> <table anchor="jumptable" align="center" pn="table-7"> <name slugifiedName="name-jump-table-for-initial-byte-2">Jump Table for Initial Byte</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">Byte</th> <th align="left" colspan="1" rowspan="1">Structure/Semantics</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">0x00..0x17</td> <td align="left" colspan="1" rowspan="1">unsigned integer 0x00..0x17 (0..23)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x18</td> <td align="left" colspan="1" rowspan="1">unsigned integer (one-byte uint8_t follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x19</td> <td align="left" colspan="1" rowspan="1">unsigned integer (two-byte uint16_t follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x1a</td> <td align="left" colspan="1" rowspan="1">unsigned integer (four-byte uint32_t follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x1b</td> <td align="left" colspan="1" rowspan="1">unsigned integer (eight-byte uint64_t follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x20..0x37</td> <td align="left" colspan="1" rowspan="1">negative integer -1-0x00..-1-0x17 (-1..-24)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x38</td> <td align="left" colspan="1" rowspan="1">negative integer -1-n (one-byte uint8_t for n follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x39</td> <td align="left" colspan="1" rowspan="1">negative integer -1-n (two-byte uint16_t for n follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x3a</td> <td align="left" colspan="1" rowspan="1">negative integer -1-n (four-byte uint32_t for n follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x3b</td> <td align="left" colspan="1" rowspan="1">negative integer -1-n (eight-byte uint64_t for n follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x40..0x57</td> <td align="left" colspan="1" rowspan="1">byte string (0x00..0x17 bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x58</td> <td align="left" colspan="1" rowspan="1">byte string (one-byte uint8_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x59</td> <td align="left" colspan="1" rowspan="1">byte string (two-byte uint16_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x5a</td> <td align="left" colspan="1" rowspan="1">byte string (four-byte uint32_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x5b</td> <td align="left" colspan="1" rowspan="1">byte string (eight-byte uint64_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x5f</td> <td align="left" colspan="1" rowspan="1">byte string, byte strings follow, terminated by "break"</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x60..0x77</td> <td align="left" colspan="1" rowspan="1">UTF-8 string (0x00..0x17 bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x78</td> <td align="left" colspan="1" rowspan="1">UTF-8 string (one-byte uint8_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x79</td> <td align="left" colspan="1" rowspan="1">UTF-8 string (two-byte uint16_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x7a</td> <td align="left" colspan="1" rowspan="1">UTF-8 string (four-byte uint32_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x7b</td> <td align="left" colspan="1" rowspan="1">UTF-8 string (eight-byte uint64_t for n, and then n bytes follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x7f</td> <td align="left" colspan="1" rowspan="1">UTF-8 string, UTF-8 strings follow, terminated by "break"</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x80..0x97</td> <td align="left" colspan="1" rowspan="1">array (0x00..0x17 data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x98</td> <td align="left" colspan="1" rowspan="1">array (one-byte uint8_t for n, and then n data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x99</td> <td align="left" colspan="1" rowspan="1">array (two-byte uint16_t for n, and then n data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x9a</td> <td align="left" colspan="1" rowspan="1">array (four-byte uint32_t for n, and then n data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x9b</td> <td align="left" colspan="1" rowspan="1">array (eight-byte uint64_t for n, and then n data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0x9f</td> <td align="left" colspan="1" rowspan="1">array, data items follow, terminated by "break"</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xa0..0xb7</td> <td align="left" colspan="1" rowspan="1">map (0x00..0x17 pairs of data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xb8</td> <td align="left" colspan="1" rowspan="1">map (one-byte uint8_t for n, and then n pairs of data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xb9</td> <td align="left" colspan="1" rowspan="1">map (two-byte uint16_t for n, and then n pairs of data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xba</td> <td align="left" colspan="1" rowspan="1">map (four-byte uint32_t for n, and then n pairs of data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xbb</td> <td align="left" colspan="1" rowspan="1">map (eight-byte uint64_t for n, and then n pairs of data items follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xbf</td> <td align="left" colspan="1" rowspan="1">map, pairs of data items follow, terminated by "break"</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xc0</td> <td align="left" colspan="1" rowspan="1">text-based date/time (data item follows; see <xref target="stringdatetimesect" format="default" sectionFormat="of" derivedContent="Section 3.4.1"/>)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xc1</td> <td align="left" colspan="1" rowspan="1">epoch-based date/time (data item follows; see <xref target="epochdatetimesect" format="default" sectionFormat="of" derivedContent="Section 3.4.2"/>)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xc2</td> <td align="left" colspan="1" rowspan="1">unsigned bignum (data item "byte string" follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xc3</td> <td align="left" colspan="1" rowspan="1">negative bignum (data item "byte string" follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xc4</td> <td align="left" colspan="1" rowspan="1">decimal Fraction (data item "array" follows; see <xref target="fractions" format="default" sectionFormat="of" derivedContent="Section 3.4.4"/>)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xc5</td> <td align="left" colspan="1" rowspan="1">bigfloat (data item "array" follows; see <xref target="fractions" format="default" sectionFormat="of" derivedContent="Section 3.4.4"/>)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xc6..0xd4</td> <td align="left" colspan="1" rowspan="1">(tag)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xd5..0xd7</td> <td align="left" colspan="1" rowspan="1">expected conversion (data item follows; see <xref target="convexpect" format="default" sectionFormat="of" derivedContent="Section 3.4.5.2"/>)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xd8..0xdb</td> <td align="left" colspan="1" rowspan="1">(more tags; 1/2/4/8 bytes of tag number and then a data item follow)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xe0..0xf3</td> <td align="left" colspan="1" rowspan="1">(simple value)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xf4</td> <td align="left" colspan="1" rowspan="1">false</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xf5</td> <td align="left" colspan="1" rowspan="1">true</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xf6</td> <td align="left" colspan="1" rowspan="1">null</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xf7</td> <td align="left" colspan="1" rowspan="1">undefined</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xf8</td> <td align="left" colspan="1" rowspan="1">(simple value, one byte follows)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xf9</td> <td align="left" colspan="1" rowspan="1">half-precision float (two-byte IEEE 754)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xfa</td> <td align="left" colspan="1" rowspan="1">single-precision float (four-byte IEEE 754)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xfb</td> <td align="left" colspan="1" rowspan="1">double-precision float (eight-byte IEEE 754)</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">0xff</td> <td align="left" colspan="1" rowspan="1">"break" stop code</td> </tr> </tbody> </table> </section> <section anchor="pseudocode" toc="include" numbered="true" removeInRFC="false" pn="section-appendix.c"> <name slugifiedName="name-pseudocode">Pseudocode</name> <t indent="0" pn="section-appendix.c-1">The well-formedness of a CBOR item can be checked by the pseudocode in <xref target="pseudo" format="default" sectionFormat="of" derivedContent="Figure 1"/>. The data is well-formed if and only if:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-appendix.c-2"> <li pn="section-appendix.c-2.1">the pseudocode does not "fail";</li> <li pn="section-appendix.c-2.2">after execution of the pseudocode, no bytes are left in the input (except in streaming applications).</li> </ul> <t indent="0" pn="section-appendix.c-3">The pseudocode has the following prerequisites:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-appendix.c-4"> <li pn="section-appendix.c-4.1">take(n) reads n bytes from the input data and returns them as a byte string. If n bytes are no longer available, take(n) fails.</li> <li pn="section-appendix.c-4.2">uint() converts a byte string into an unsigned integer by interpreting the byte string in network byte order.</li> <li pn="section-appendix.c-4.3">Arithmetic works as in C.</li> <li pn="section-appendix.c-4.4">All variables are unsigned integers of sufficient range.</li> </ul> <t indent="0" pn="section-appendix.c-5">Note that <tt>well_formed</tt> returns the major type for well-formed definite-length items, but 99 for an indefinite-length item (or -1 for a "break" stop code, only if <tt>breakable</tt> is set). This is used in <tt>well_formed_indefinite</tt> to ascertain that indefinite-length strings only contain definite-length strings as chunks.</t> <figure anchor="pseudo" align="left" suppress-title="false" pn="figure-1"> <name slugifiedName="name-pseudocode-for-well-formedn">Pseudocode for Well-Formedness Check</name> <sourcecode type="pseudocode" markers="false" pn="section-appendix.c-6.1"> well_formed(breakable = false) { // process initial bytes ib = uint(take(1)); mt = ib >> 5; val = ai = ib & 0x1f; switch (ai) { case 24: val = uint(take(1)); break; case 25: val = uint(take(2)); break; case 26: val = uint(take(4)); break; case 27: val = uint(take(8)); break; case 28: case 29: case 30: fail(); case 31: return well_formed_indefinite(mt, breakable); } // process content switch (mt) { // case 0, 1, 7 do not have content; just use val case 2: case 3: take(val); break; // bytes/UTF-8 case 4: for (i = 0; i < val; i++) well_formed(); break; case 5: for (i = 0; i < val*2; i++) well_formed(); break; case 6: well_formed(); break; // 1 embedded data item case 7: if (ai == 24 && val < 32) fail(); // bad simple } return mt; // definite-length data item } well_formed_indefinite(mt, breakable) { switch (mt) { case 2: case 3: while ((it = well_formed(true)) != -1) if (it != mt) // need definite-length chunk fail(); // of same type break; case 4: while (well_formed(true) != -1); break; case 5: while (well_formed(true) != -1) well_formed(); break; case 7: if (breakable) return -1; // signal break out else fail(); // no enclosing indefinite default: fail(); // wrong mt } return 99; // indefinite-length data item } </sourcecode> </figure> <t indent="0" pn="section-appendix.c-7">Note that the remaining complexity of a complete CBOR decoder is about presenting data that has been decoded to the application in an appropriate form.</t> <t indent="0" pn="section-appendix.c-8">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 (<xref target="branchless" format="default" sectionFormat="of" derivedContent="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 nonnegative. The sign of a number can be converted to -1 for negative and 0 for nonnegative (0 or positive) by arithmetic-shifting the number by one bit less than the bit length of the number (for example, by 63 for 64-bit numbers).</t> <figure anchor="branchless" align="left" suppress-title="false" pn="figure-2"> <name slugifiedName="name-pseudocode-for-encoding-a-s">Pseudocode for Encoding a Signed Integer</name> <sourcecode type="pseudocode" markers="false" pn="section-appendix.c-9.1"> void encode_sint(int64_t n) { uint64t ui = n >> 63; // extend sign to whole length unsigned mt = ui & 0x20; // extract (shifted) major type ui ^= n; // complement negatives if (ui < 24) *p++ = mt + ui; else if (ui < 256) { *p++ = mt + 24; *p++ = ui; } else ... </sourcecode> </figure> <t indent="0" pn="section-appendix.c-10">See <xref target="terminology" format="default" sectionFormat="of" derivedContent="Section 1.2"/> for some specific assumptions about the profile of the C language used in these pieces of code.</t> </section> <section anchor="half-precision" toc="include" numbered="true" removeInRFC="false" pn="section-appendix.d"> <name slugifiedName="name-half-precision">Half-Precision</name> <t indent="0" pn="section-appendix.d-1">As half-precision floating-point numbers were only added to IEEE 754 in 2008 <xref target="IEEE754" format="default" sectionFormat="of" derivedContent="IEEE754"/>, today's programming platforms often still only have limited support for them. It is very easy to include at least decoding support for them even without such support. An example of a small decoder for half-precision floating-point numbers in the C language is shown in <xref target="decode-half-c" format="default" sectionFormat="of" derivedContent="Figure 3"/>. A similar program for Python is in <xref target="decode-half-py" format="default" sectionFormat="of" derivedContent="Figure 4"/>; this code assumes that the 2-byte value has already been decoded as an (unsigned short) integer in network byte order (as would be done by the pseudocode in <xref target="pseudocode" format="default" sectionFormat="of" derivedContent="Appendix C"/>).</t> <figure anchor="decode-half-c" align="left" suppress-title="false" pn="figure-3"> <name slugifiedName="name-c-code-for-a-half-precision">C Code for a Half-Precision Decoder</name> <sourcecode type="c" markers="false" pn="section-appendix.d-2.1"> #include <math.h> double decode_half(unsigned char *halfp) { unsigned half = (halfp[0] << 8) + halfp[1]; unsigned exp = (half >> 10) & 0x1f; unsigned mant = half & 0x3ff; double val; if (exp == 0) val = ldexp(mant, -24); else if (exp != 31) val = ldexp(mant + 1024, exp - 25); else val = mant == 0 ? INFINITY : NAN; return half & 0x8000 ? -val : val; } </sourcecode> </figure> <figure anchor="decode-half-py" align="left" suppress-title="false" pn="figure-4"> <name slugifiedName="name-python-code-for-a-half-prec">Python Code for a Half-Precision Decoder</name> <sourcecode type="python" markers="false" pn="section-appendix.d-3.1"> import struct from math import ldexp def decode_single(single): return struct.unpack("!f", struct.pack("!I", single))[0] def decode_half(half): valu = (half & 0x7fff) << 13 | (half & 0x8000) << 16 if ((half & 0x7c00) != 0x7c00): return ldexp(decode_single(valu), 112) return decode_single(valu | 0x7f800000) </sourcecode> </figure> </section> <section anchor="comparison-app" toc="include" numbered="true" removeInRFC="false" pn="section-appendix.e"> <name slugifiedName="name-comparison-of-other-binary-">Comparison of Other Binary Formats to CBOR's Design Objectives</name> <t indent="0" pn="section-appendix.e-1">The proposal for CBOR follows a history of binary formats that is as long as the history of computers themselves. Different formats have had different objectives. In most cases, the objectives of the format were never stated, although they can sometimes be implied by the context where the format was first used. Some formats were meant to be universally usable, although history has proven that no binary format meets the needs of all protocols and applications.</t> <t indent="0" pn="section-appendix.e-2">CBOR differs from many of these formats due to it starting with a set of objectives and attempting to meet just those. This section compares a few of the dozens of formats with CBOR's objectives in order to help the reader decide if they want to use CBOR or a different format for a particular protocol or application.</t> <t indent="0" pn="section-appendix.e-3">Note that the discussion here is not meant to be a criticism of any format: to the best of our knowledge, no format before CBOR was meant to cover CBOR's objectives in the priority we have assigned them. A brief recap of the objectives from <xref target="objectives" format="default" sectionFormat="of" derivedContent="Section 1.1"/> is:</t> <ol spacing="normal" type="1" indent="adaptive" start="1" pn="section-appendix.e-4"><li pn="section-appendix.e-4.1" derivedCounter="1.">unambiguous encoding of most common data formats from Internet standards</li> <li pn="section-appendix.e-4.2" derivedCounter="2.">code compactness for encoder or decoder</li> <li pn="section-appendix.e-4.3" derivedCounter="3.">no schema description needed</li> <li pn="section-appendix.e-4.4" derivedCounter="4.">reasonably compact serialization</li> <li pn="section-appendix.e-4.5" derivedCounter="5.">applicability to constrained and unconstrained applications</li> <li pn="section-appendix.e-4.6" derivedCounter="6.">good JSON conversion</li> <li pn="section-appendix.e-4.7" derivedCounter="7.">extensibility</li> </ol> <t indent="0" pn="section-appendix.e-5">A discussion of CBOR and other formats with respect to a different set of design objectives is provided in Section <xref target="RFC8618" section="5" sectionFormat="bare" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8618#section-5" derivedContent="RFC8618"/> and Appendix <xref target="RFC8618" section="C" sectionFormat="bare" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8618#appendix-C" derivedContent="RFC8618"/> of <xref target="RFC8618" format="default" sectionFormat="of" derivedContent="RFC8618"/>.</t> <section anchor="asn1-der-ber-and-per" toc="include" numbered="true" removeInRFC="false" pn="section-e.1"> <name slugifiedName="name-asn1-der-ber-and-per">ASN.1 DER, BER, and PER</name> <t indent="0" pn="section-e.1-1"><xref target="ASN.1" format="default" sectionFormat="of" derivedContent="ASN.1"/> has many serializations. In the IETF, DER and BER are the most common. The serialized output is not particularly compact for many items, and the code needed to decode numeric items can be complex on a constrained device.</t> <t indent="0" pn="section-e.1-2">Few (if any) IETF protocols have adopted one of the several variants of Packed Encoding Rules (PER). There could be many reasons for this, but one that is commonly stated is that PER makes use of the schema even for parsing the surface structure of the data item, requiring significant tool support. There are different versions of the ASN.1 schema language in use, which has also hampered adoption.</t> </section> <section anchor="messagepack" toc="include" numbered="true" removeInRFC="false" pn="section-e.2"> <name slugifiedName="name-messagepack">MessagePack</name> <t indent="0" pn="section-e.2-1"><xref target="MessagePack" format="default" sectionFormat="of" derivedContent="MessagePack"/> is a concise, widely implemented counted binary serialization format, similar in many properties to CBOR, although somewhat less regular. While the data model can be used to represent JSON data, MessagePack has also been used in many remote procedure call (RPC) applications and for long-term storage of data.</t> <t indent="0" pn="section-e.2-2">MessagePack has been essentially stable since it was first published around 2011; it has not yet had a transition. The evolution of MessagePack is impeded by an imperative to maintain complete backwards compatibility with existing stored data, while only few bytecodes are still available for extension. Repeated requests over the years from the MessagePack user community to separate out binary and text strings in the encoding recently have led to an extension proposal that would leave MessagePack's "raw" data ambiguous between its usages for binary and text data. The extension mechanism for MessagePack remains unclear.</t> </section> <section anchor="bson" toc="include" numbered="true" removeInRFC="false" pn="section-e.3"> <name slugifiedName="name-bson">BSON</name> <t indent="0" pn="section-e.3-1"><xref target="BSON" format="default" sectionFormat="of" derivedContent="BSON"/> is a data format that was developed for the storage of JSON-like maps (JSON objects) in the MongoDB database. Its major distinguishing feature is the capability for in-place update, which prevents a compact representation. BSON uses a counted representation except for map keys, which are null-byte terminated. While BSON can be used for the representation of JSON-like objects on the wire, its specification is dominated by the requirements of the database application and has become somewhat baroque. The status of how BSON extensions will be implemented remains unclear.</t> </section> <section anchor="msdtp-rfc-713" toc="include" numbered="true" removeInRFC="false" pn="section-e.4"> <name slugifiedName="name-msdtp-rfc-713">MSDTP: RFC 713</name> <t indent="0" pn="section-e.4-1">Message Services Data Transmission (MSDTP) is a very early example of a compact message format; it is described in <xref target="RFC0713" format="default" sectionFormat="of" derivedContent="RFC0713"/>, written in 1976. It is included here for its historical value, not because it was ever widely used.</t> </section> <section anchor="conciseness-on-the-wire" toc="include" numbered="true" removeInRFC="false" pn="section-e.5"> <name slugifiedName="name-conciseness-on-the-wire">Conciseness on the Wire</name> <t indent="0" pn="section-e.5-1">While CBOR's design objective of code compactness for encoders and decoders is a higher priority than its objective of conciseness on the wire, many people focus on the wire size. <xref target="concise" format="default" sectionFormat="of" derivedContent="Table 8"/> shows some encoding examples for the simple nested array [1, [2, 3]]; where some form of indefinite-length encoding is supported by the encoding, [_ 1, [2, 3]] (indefinite length on the outer array) is also shown.</t> <table anchor="concise" align="center" pn="table-8"> <name slugifiedName="name-examples-for-different-leve">Examples for Different Levels of Conciseness</name> <thead> <tr> <th align="left" colspan="1" rowspan="1">Format</th> <th align="left" colspan="1" rowspan="1">[1, [2, 3]]</th> <th align="left" colspan="1" rowspan="1">[_ 1, [2, 3]]</th> </tr> </thead> <tbody> <tr> <td align="left" colspan="1" rowspan="1">RFC 713</td> <td align="left" colspan="1" rowspan="1">c2 05 81 c2 02 82 83</td> <td align="left" colspan="1" rowspan="1"> </td> </tr> <tr> <td align="left" colspan="1" rowspan="1">ASN.1 BER</td> <td align="left" colspan="1" rowspan="1">30 0b 02 01 01 30 06 02 01 02 02 01 03</td> <td align="left" colspan="1" rowspan="1">30 80 02 01 01 30 06 02 01 02 02 01 03 00 00</td> </tr> <tr> <td align="left" colspan="1" rowspan="1">MessagePack</td> <td align="left" colspan="1" rowspan="1">92 01 92 02 03</td> <td align="left" colspan="1" rowspan="1"> </td> </tr> <tr> <td align="left" colspan="1" rowspan="1">BSON</td> <td align="left" colspan="1" rowspan="1">22 00 00 00 10 30 00 01 00 00 00 04 31 00 13 00 00 00 10 30 00 02 00 00 00 10 31 00 03 00 00 00 00 00</td> <td align="left" colspan="1" rowspan="1"> </td> </tr> <tr> <td align="left" colspan="1" rowspan="1">CBOR</td> <td align="left" colspan="1" rowspan="1">82 01 82 02 03</td> <td align="left" colspan="1" rowspan="1">9f 01 82 02 03 ff</td> </tr> </tbody> </table> </section> </section> <section anchor="errors" toc="include" numbered="true" removeInRFC="false" pn="section-appendix.f"> <name slugifiedName="name-well-formedness-errors-and-">Well-Formedness Errors and Examples</name> <t indent="0" pn="section-appendix.f-1">There are three basic kinds of well-formedness errors that can occur in decoding a CBOR data item:</t> <dl spacing="normal" indent="3" newline="false" pn="section-appendix.f-2"> <dt pn="section-appendix.f-2.1">Too much data:</dt> <dd pn="section-appendix.f-2.2">There are input bytes left that were not consumed. This is only an error if the application assumed that the input bytes would span exactly one data item. Where the application uses the self-delimiting nature of CBOR encoding to permit additional data after the data item, as is done in CBOR sequences <xref target="RFC8742" format="default" sectionFormat="of" derivedContent="RFC8742"/>, for example, the CBOR decoder can simply indicate which part of the input has not been consumed.</dd> <dt pn="section-appendix.f-2.3">Too little data:</dt> <dd pn="section-appendix.f-2.4">The input data available would need additional bytes added at their end for a complete CBOR data item. This may indicate the input is truncated; it is also a common error when trying to decode random data as CBOR. For some applications, however, this may not actually be an error, as the application may not be certain it has all the data yet and can obtain or wait for additional input bytes. Some of these applications may have an upper limit for how much additional data can appear; here the decoder may be able to indicate that the encoded CBOR data item cannot be completed within this limit.</dd> <dt pn="section-appendix.f-2.5">Syntax error:</dt> <dd pn="section-appendix.f-2.6">The input data are not consistent with the requirements of the CBOR encoding, and this cannot be remedied by adding (or removing) data at the end.</dd> </dl> <t indent="0" pn="section-appendix.f-3">In <xref target="pseudocode" format="default" sectionFormat="of" derivedContent="Appendix C"/>, errors of the first kind are addressed in the first paragraph and bullet list (requiring "no bytes are left"), and errors of the second kind are addressed in the second paragraph/bullet list (failing "if n bytes are no longer available"). Errors of the third kind are identified in the pseudocode by specific instances of calling fail(), in order:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-appendix.f-4"> <li pn="section-appendix.f-4.1">a reserved value is used for additional information (28, 29, 30)</li> <li pn="section-appendix.f-4.2">major type 7, additional information 24, value < 32 (incorrect)</li> <li pn="section-appendix.f-4.3">incorrect substructure of indefinite-length byte string or text string (may only contain definite-length strings of the same major type)</li> <li pn="section-appendix.f-4.4">"break" stop code (major type 7, additional information 31) occurs in a value position of a map or except at a position directly in an indefinite-length item where also another enclosed data item could occur</li> <li pn="section-appendix.f-4.5">additional information 31 used with major type 0, 1, or 6</li> </ul> <section anchor="examples-for-cbor-data-items-that-are-not-well-formed" toc="include" numbered="true" removeInRFC="false" pn="section-f.1"> <name slugifiedName="name-examples-of-cbor-data-items">Examples of CBOR Data Items That Are Not Well-Formed</name> <t indent="0" pn="section-f.1-1">This subsection shows a few examples for CBOR data items that are not well-formed. Each example is a sequence of bytes, each shown in hexadecimal; multiple examples in a list are separated by commas.</t> <t indent="0" pn="section-f.1-2">Examples for well-formedness error kind 1 (too much data) can easily be formed by adding data to a well-formed encoded CBOR data item.</t> <t indent="0" pn="section-f.1-3">Similarly, examples for well-formedness error kind 2 (too little data) can be formed by truncating a well-formed encoded CBOR data item. In test suites, it may be beneficial to specifically test with incomplete data items that would require large amounts of addition to be completed (for instance by starting the encoding of a string of a very large size).</t> <t indent="0" pn="section-f.1-4">A premature end of the input can occur in a head or within the enclosed data, which may be bare strings or enclosed data items that are either counted or should have been ended by a "break" stop code.</t> <dl spacing="normal" indent="3" newline="false" pn="section-f.1-5"> <dt pn="section-f.1-5.1">End of input in a head:</dt> <dd pn="section-f.1-5.2">18, 19, 1a, 1b, 19 01, 1a 01 02, 1b 01 02 03 04 05 06 07, 38, 58, 78, 98, 9a 01 ff 00, b8, d8, f8, f9 00, fa 00 00, fb 00 00 00</dd> <dt pn="section-f.1-5.3">Definite-length strings with short data:</dt> <dd pn="section-f.1-5.4">41, 61, 5a ff ff ff ff 00, 5b ff ff ff ff ff ff ff ff 01 02 03, 7a ff ff ff ff 00, 7b 7f ff ff ff ff ff ff ff 01 02 03</dd> <dt pn="section-f.1-5.5">Definite-length maps and arrays not closed with enough items:</dt> <dd pn="section-f.1-5.6">81, 81 81 81 81 81 81 81 81 81, 82 00, a1, a2 01 02, a1 00, a2 00 00 00</dd> <dt pn="section-f.1-5.7">Tag number not followed by tag content:</dt> <dd pn="section-f.1-5.8">c0</dd> <dt pn="section-f.1-5.9">Indefinite-length strings not closed by a "break" stop code:</dt> <dd pn="section-f.1-5.10">5f 41 00, 7f 61 00</dd> <dt pn="section-f.1-5.11">Indefinite-length maps and arrays not closed by a "break" stop code:</dt> <dd pn="section-f.1-5.12"> 9f, 9f 01 02, bf, bf 01 02 01 02, 81 9f, 9f 80 00, 9f 9f 9f 9f 9f ff ff ff ff, 9f 81 9f 81 9f 9f ff ff ff</dd> </dl> <t indent="0" pn="section-f.1-6">A few examples for the five subkinds of well-formedness error kind 3 (syntax error) are shown below.</t> <dl newline="true" spacing="normal" indent="3" pn="section-f.1-7"> <dt pn="section-f.1-7.1">Subkind 1:</dt> <dd pn="section-f.1-7.2"> <t indent="0" pn="section-f.1-7.2.1"/> <dl spacing="normal" indent="3" newline="false" pn="section-f.1-7.2.2"> <dt pn="section-f.1-7.2.2.1">Reserved additional information values:</dt> <dd pn="section-f.1-7.2.2.2">1c, 1d, 1e, 3c, 3d, 3e, 5c, 5d, 5e, 7c, 7d, 7e, 9c, 9d, 9e, bc, bd, be, dc, dd, de, fc, fd, fe,</dd> </dl> </dd> <dt pn="section-f.1-7.3">Subkind 2:</dt> <dd pn="section-f.1-7.4"> <t indent="0" pn="section-f.1-7.4.1"/> <dl spacing="normal" indent="3" newline="false" pn="section-f.1-7.4.2"> <dt pn="section-f.1-7.4.2.1">Reserved two-byte encodings of simple values:</dt> <dd pn="section-f.1-7.4.2.2">f8 00, f8 01, f8 18, f8 1f</dd> </dl> </dd> <dt pn="section-f.1-7.5">Subkind 3:</dt> <dd pn="section-f.1-7.6"> <t indent="0" pn="section-f.1-7.6.1"/> <dl spacing="normal" indent="3" newline="false" pn="section-f.1-7.6.2"> <dt pn="section-f.1-7.6.2.1">Indefinite-length string chunks not of the correct type:</dt> <dd pn="section-f.1-7.6.2.2">5f 00 ff, 5f 21 ff, 5f 61 00 ff, 5f 80 ff, 5f a0 ff, 5f c0 00 ff, 5f e0 ff, 7f 41 00 ff</dd> <dt pn="section-f.1-7.6.2.3">Indefinite-length string chunks not definite length:</dt> <dd pn="section-f.1-7.6.2.4"> 5f 5f 41 00 ff ff, 7f 7f 61 00 ff ff</dd> </dl> </dd> <dt pn="section-f.1-7.7">Subkind 4:</dt> <dd pn="section-f.1-7.8"> <t indent="0" pn="section-f.1-7.8.1"/> <dl spacing="normal" indent="3" newline="false" pn="section-f.1-7.8.2"> <dt pn="section-f.1-7.8.2.1">Break occurring on its own outside of an indefinite-length item:</dt> <dd pn="section-f.1-7.8.2.2"> ff</dd> <dt pn="section-f.1-7.8.2.3">Break occurring in a definite-length array or map or a tag:</dt> <dd pn="section-f.1-7.8.2.4">81 ff, 82 00 ff, a1 ff, a1 ff 00, a1 00 ff, a2 00 00 ff, 9f 81 ff, 9f 82 9f 81 9f 9f ff ff ff ff</dd> <dt pn="section-f.1-7.8.2.5">Break in an indefinite-length map that would lead to an odd number of items (break in a value position):</dt> <dd pn="section-f.1-7.8.2.6">bf 00 ff, bf 00 00 00 ff</dd> </dl> </dd> <dt pn="section-f.1-7.9">Subkind 5:</dt> <dd pn="section-f.1-7.10"> <t indent="0" pn="section-f.1-7.10.1"/> <dl spacing="normal" indent="3" newline="false" pn="section-f.1-7.10.2"> <dt pn="section-f.1-7.10.2.1">Major type 0, 1, 6 with additional information 31:</dt> <dd pn="section-f.1-7.10.2.2">1f, 3f, df</dd> </dl> </dd> </dl> </section> </section> <section anchor="changes-from-rfc-7049" toc="include" numbered="true" removeInRFC="false" pn="section-appendix.g"> <name slugifiedName="name-changes-from-rfc-7049">Changes from RFC 7049</name> <t indent="0" pn="section-appendix.g-1">As discussed in the introduction, this document formally obsoletes RFC 7049 while keeping full compatibility with the interchange format from RFC 7049. This document provides editorial improvements, added detail, and fixed errata. This document does not create a new version of the format.</t> <section anchor="errata-processing-clerical-changes" toc="include" numbered="true" removeInRFC="false" pn="section-g.1"> <name slugifiedName="name-errata-processing-and-cleri">Errata Processing and Clerical Changes</name> <t indent="0" pn="section-g.1-1">The two verified errata on RFC 7049, <xref target="Err3764" format="default" sectionFormat="of" derivedContent="Err3764"/> and <xref target="Err3770" format="default" sectionFormat="of" derivedContent="Err3770"/>, concerned two encoding examples in the text that have been corrected (<xref target="bignums" format="default" sectionFormat="of" derivedContent="Section 3.4.3"/>: "29" -> "49", <xref target="numbers" format="default" sectionFormat="of" derivedContent="Section 5.5"/>: "0b000_11101" -> "0b000_11001"). Also, RFC 7049 contained an example using the numeric value 24 for a simple value <xref target="Err5917" format="default" sectionFormat="of" derivedContent="Err5917"/>, which is not well-formed; this example has been removed. Errata report 5763 <xref target="Err5763" format="default" sectionFormat="of" derivedContent="Err5763"/> pointed to an error in the wording of the definition of tags; this was resolved during a rewrite of <xref target="tags" format="default" sectionFormat="of" derivedContent="Section 3.4"/>. Errata report 5434 <xref target="Err5434" format="default" sectionFormat="of" derivedContent="Err5434"/> pointed out that the Universal Binary JSON (UBJSON) example in <xref target="comparison-app" format="default" sectionFormat="of" derivedContent="Appendix E"/> no longer complied with the version of UBJSON current at the time of the errata report submission. It turned out that the UBJSON specification had completely changed since 2013; this example therefore was removed. Other errata reports <xref target="Err4409" format="default" sectionFormat="of" derivedContent="Err4409"/> <xref target="Err4963" format="default" sectionFormat="of" derivedContent="Err4963"/> <xref target="Err4964" format="default" sectionFormat="of" derivedContent="Err4964"/> complained that the map key sorting rules for canonical encoding were onerous; these led to a reconsideration of the canonical encoding suggestions and replacement by the deterministic encoding suggestions (described below). An editorial suggestion in errata report 4294 <xref target="Err4294" format="default" sectionFormat="of" derivedContent="Err4294"/> was also implemented (improved symmetry by adding "Second value" to a comment to the last example in <xref target="indef" format="default" sectionFormat="of" derivedContent="Section 3.2.2"/>).</t> <t indent="0" pn="section-g.1-2">Other clerical changes include:</t> <ul spacing="normal" bare="false" empty="false" indent="3" pn="section-g.1-3"> <li pn="section-g.1-3.1">the use of new xml2rfc functionality <xref target="RFC7991" format="default" sectionFormat="of" derivedContent="RFC7991"/>;</li> <li pn="section-g.1-3.2">more explanation of the notation used;</li> <li pn="section-g.1-3.3">the update of references, e.g., from RFC 4627 to <xref target="RFC8259" format="default" sectionFormat="of" derivedContent="RFC8259"/>, from CNN-TERMS to <xref target="RFC7228" format="default" sectionFormat="of" derivedContent="RFC7228"/>, and from the 5.1 edition to the 11th edition of <xref target="ECMA262" format="default" sectionFormat="of" derivedContent="ECMA262"/>; the addition of a reference to <xref target="IEEE754" format="default" sectionFormat="of" derivedContent="IEEE754"/> and importation of required definitions; the addition of references to <xref target="C" format="default" sectionFormat="of" derivedContent="C"/> and <xref target="Cplusplus20" format="default" sectionFormat="of" derivedContent="Cplusplus20"/>; and the addition of a reference to <xref target="RFC8618" format="default" sectionFormat="of" derivedContent="RFC8618"/> that further illustrates the discussion in <xref target="comparison-app" format="default" sectionFormat="of" derivedContent="Appendix E"/>;</li> <li pn="section-g.1-3.4">in the discussion of diagnostic notation (<xref target="diagnostic-notation" format="default" sectionFormat="of" derivedContent="Section 8"/>), the "Extended Diagnostic Notation" (EDN) defined in <xref target="RFC8610" format="default" sectionFormat="of" derivedContent="RFC8610"/> is now mentioned, the gap in representing NaN payloads is now highlighted, and an explanation of representing indefinite-length strings with no chunks has been added (<xref target="encoding-indicators" format="default" sectionFormat="of" derivedContent="Section 8.1"/>); </li> <li pn="section-g.1-3.5">the addition of this appendix.</li> </ul> </section> <section anchor="changes-in-iana-considerations" toc="include" numbered="true" removeInRFC="false" pn="section-g.2"> <name slugifiedName="name-changes-in-iana-considerati">Changes in IANA Considerations</name> <t indent="0" pn="section-g.2-1">The IANA considerations were generally updated (clerical changes, e.g., now pointing to the CBOR Working Group as the author of the specification). References to the respective IANA registries were added to the informative references.</t> <t indent="0" pn="section-g.2-2">In the "Concise Binary Object Representation (CBOR) Tags" registry <xref target="IANA.cbor-tags" format="default" sectionFormat="of" derivedContent="IANA.cbor-tags"/>, tags in the space from 256 to 32767 (lower half of "1+2") are no longer assigned by First Come First Served; this range is now Specification Required.</t> </section> <section anchor="changes-in-suggestions-and-other-informational-components" toc="include" numbered="true" removeInRFC="false" pn="section-g.3"> <name slugifiedName="name-changes-in-suggestions-and-">Changes in Suggestions and Other Informational Components</name> <t indent="0" pn="section-g.3-1">While revising the document, beyond the addressing of the errata reports, the working group drew upon nearly seven years of experience with CBOR in a diverse set of applications. This led to a number of editorial changes, including adding tables for illustration, but also emphasizing some aspects and de-emphasizing others.</t> <t indent="0" pn="section-g.3-2">A significant addition is <xref target="cbor-data-models" format="default" sectionFormat="of" derivedContent="Section 2"/>, which discusses the CBOR data model and its small variations involved in the processing of CBOR. The introduction of terms for those variations (basic generic, extended generic, specific) enables more concise language in other places of the document and also helps to clarify expectations of implementations and of the extensibility features of the format.</t> <t indent="0" pn="section-g.3-3">As a format derived from the JSON ecosystem, RFC 7049 was influenced by the JSON number system that was in turn inherited from JavaScript at the time. JSON does not provide distinct integers and floating-point values (and the latter are decimal in the format). CBOR provides binary representations of numbers, which do differ between integers and floating-point values. Experience from implementation and use suggested that the separation between these two number domains should be more clearly drawn in the document; language that suggested an integer could seamlessly stand in for a floating-point value was removed. Also, a suggestion (based on I-JSON <xref target="RFC7493" format="default" sectionFormat="of" derivedContent="RFC7493"/>) was added for handling these types when converting JSON to CBOR, and the use of a specific rounding mechanism has been recommended.</t> <t indent="0" pn="section-g.3-4">For a single value in the data model, CBOR often provides multiple encoding options. A new section (<xref target="serialization-considerations" format="default" sectionFormat="of" derivedContent="Section 4"/>) introduces the term "preferred serialization" (<xref target="preferred" format="default" sectionFormat="of" derivedContent="Section 4.1"/>) and defines it for various kinds of data items. On the basis of this terminology, the section then discusses how a CBOR-based protocol can define "deterministic encoding" (<xref target="det-enc" format="default" sectionFormat="of" derivedContent="Section 4.2"/>), which avoids terms "canonical" and "canonicalization" from RFC 7049. The suggestion of "Core Deterministic Encoding Requirements" (<xref target="core-det" format="default" sectionFormat="of" derivedContent="Section 4.2.1"/>) enables generic support for such protocol-defined encoding requirements. This document further eases the implementation of deterministic encoding by simplifying the map ordering suggested in RFC 7049 to a simple lexicographic ordering of encoded keys. A description of the older suggestion is kept as an alternative, now termed "length-first map key ordering" (<xref target="length-first" format="default" sectionFormat="of" derivedContent="Section 4.2.3"/>).</t> <t indent="0" pn="section-g.3-5">The terminology for well-formed and valid data was sharpened and more stringently used, avoiding less well-defined alternative terms such as "syntax error", "decoding error", and "strict mode" outside of examples. Also, a third level of requirements that an application has on its input data beyond CBOR-level validity is now explicitly called out. Well-formed (processable at all), valid (checked by a validity-checking generic decoder), and expected input (as checked by the application) are treated as a hierarchy of layers of acceptability.</t> <t indent="0" pn="section-g.3-6">The handling of non-well-formed simple values was clarified in text and pseudocode. <xref target="errors" format="default" sectionFormat="of" derivedContent="Appendix F"/> was added to discuss well-formedness errors and provide examples for them. The pseudocode was updated to be more portable, and some portability considerations were added.</t> <t indent="0" pn="section-g.3-7">The discussion of validity has been sharpened in two areas. Map validity (handling of duplicate keys) was clarified, and the domain of applicability of certain implementation choices explained. Also, while streamlining the terminology for tags, tag numbers, and tag content, discussion was added on tag validity, and the restrictions were clarified on tag content, in general and specifically for tag 1.</t> <t indent="0" pn="section-g.3-8">An implementation note (and note for future tag definitions) was added to <xref target="tags" format="default" sectionFormat="of" derivedContent="Section 3.4"/> about defining tags with semantics that depend on serialization order.</t> <t indent="0" pn="section-g.3-9">Tag 35 is not defined by this document; the registration based on the definition in RFC 7049 remains in place.</t> <t indent="0" pn="section-g.3-10">Terminology was introduced in <xref target="encoding" format="default" sectionFormat="of" derivedContent="Section 3"/> for "argument" and "head", simplifying further discussion.</t> <t indent="0" pn="section-g.3-11">The security considerations (<xref target="securitycons" format="default" sectionFormat="of" derivedContent="Section 10"/>) were mostly rewritten and significantly expanded; in multiple other places, the document is now more explicit that a decoder cannot simply condone well-formedness errors.</t> </section> </section> <section numbered="false" anchor="acknowledgements" toc="include" removeInRFC="false" pn="section-appendix.h"> <name slugifiedName="name-acknowledgements">Acknowledgements</name> <t indent="0" pn="section-appendix.h-1">CBOR was inspired by MessagePack. MessagePack was developed and promoted by <contact fullname="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.</t> <t indent="0" pn="section-appendix.h-2">The need for functionality beyond the original MessagePack specification became obvious to many people at about the same time around the year 2012. BinaryPack is a minor derivation of MessagePack that was developed by <contact fullname="Eric Zhang"/> for the binaryjs project. A similar, but different, extension was made by <contact fullname="Tim Caswell"/> for his msgpack-js and msgpack-js-browser projects. Many people have contributed to the discussion about extending MessagePack to separate text string representation from byte string representation.</t> <t indent="0" pn="section-appendix.h-3">The encoding of the additional information in CBOR was inspired by the encoding of length information designed by <contact fullname="Klaus Hartke"/> for CoAP.</t> <t indent="0" pn="section-appendix.h-4">This document also incorporates suggestions made by many people, notably <contact fullname="Dan Frost"/>, <contact fullname="James Manger"/>, <contact fullname="Jeffrey Yasskin"/>, <contact fullname="Joe Hildebrand"/>, <contact fullname="Keith Moore"/>, <contact fullname="Laurence Lundblade"/>, <contact fullname="Matthew Lepinski"/>, <contact fullname="Michael Richardson"/>, <contact fullname="Nico Williams"/>, <contact fullname="Peter Occil"/>, <contact fullname="Phillip Hallam-Baker"/>, <contact fullname="Ray Polk"/>, <contact fullname="Stuart Cheshire"/>, <contact fullname="Tim Bray"/>, <contact fullname="Tony Finch"/>, <contact fullname="Tony Hansen"/>, and <contact fullname="Yaron Sheffer"/>. <contact fullname="Benjamin Kaduk"/> provided an extensive review during IESG processing. <contact fullname="Éric Vyncke"/>, <contact fullname="Erik Kline"/>, <contact fullname="Robert Wilton"/>, and <contact fullname="Roman Danyliw"/> provided further IESG comments, which included an IoT directorate review by <contact fullname="Eve Schooler"/>.</t> </section> <section anchor="authors-addresses" numbered="false" removeInRFC="false" toc="include" pn="section-appendix.i"> <name slugifiedName="name-authors-addresses">Authors' Addresses</name> <author initials="C." surname="Bormann" fullname="Carsten Bormann"> <organization showOnFrontPage="true">Universität Bremen TZI</organization> <address> <postal> <street>Postfach 330440</street> <city>Bremen</city> <code>D-28359</code> <country>Germany</country> </postal> <phone>+49-421-218-63921</phone> <email>cabo@tzi.org</email> </address> </author> <author initials="P." surname="Hoffman" fullname="Paul Hoffman"> <organization showOnFrontPage="true">ICANN</organization> <address> <email>paul.hoffman@icann.org</email> </address> </author> </section> </back> </rfc>