<?xml version='1.0' encoding='UTF-8'?>


<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">

<rfc number="8742" xmlns:xi="http://www.w3.org/2001/XInclude"
     ipr="trust200902" docName="draft-ietf-cbor-sequence-02" category="std"
     obsoletes="" consensus="true" updates="" submissionType="IETF" xml:lang="en" sortRefs="true" symRefs="true" tocInclude="true" version="3">

  <front>
    <title abbrev="CBOR Sequences">Concise Binary Object Representation (CBOR) Sequences</title>
    <seriesInfo name="RFC" value="8742"/>
    <author initials="C." surname="Bormann" fullname="Carsten Bormann">
      <organization ascii="Universitaet Bremen TZI">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>
    <date year="2020" month="February"/>

<keyword>binary format</keyword>
<keyword>data interchange format</keyword>
<keyword>JSON</keyword>

    <abstract>
      <t>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>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>
  <middle>
    <section anchor="introduction" numbered="true" toc="default">
      <name>Introduction</name>
      <t>The Concise Binary Object Representation (CBOR) <xref
      target="RFC7049" format="default"/> can be used for serialization of
      data in the JSON <xref target="RFC8259" format="default"/> data model or
      in its own, somewhat expanded, data model.  When serializing a sequence of
      such values, it is sometimes convenient to have a format where these
      sequences can simply be concatenated to obtain a serialization of the
      concatenated sequence of values or to encode a sequence of values that
      might grow at the end by just appending further CBOR data items.</t>
      <t>This document describes the concept and format of "CBOR Sequences",
      which are composed of zero or more encoded CBOR data items.  CBOR
      Sequences can be consumed (and produced) incrementally without requiring
      a streaming CBOR parser that is able to deliver substructures of a data
      item incrementally (or a streaming encoder able to encode from
      substructures incrementally).</t>
      <t>This document defines and registers the "application/cbor-seq" media
      type in the "Media Types" registry along with a Constrained Application
      Protocol (CoAP) Content-Format identifier.  Media type structured syntax
      suffixes <xref target="RFC6838" format="default"/> were introduced as a
      way for a media type to signal that it is based on another media type as
      its foundation.  CBOR <xref target="RFC7049" format="default"/> defines
      the "+cbor" structured syntax suffix.  This document defines and
      registers the "+cbor-seq" structured syntax suffix in the "Structured
      Syntax Suffix Registry".</t>
      <section anchor="conventions-used-in-this-document" numbered="true" toc="default">
        <name>Conventions Used in This Document</name>

        <t>
    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&nbsp;14 <xref target="RFC2119"/> <xref target="RFC8174"/> 
    when, and only when, they appear in all capitals, as shown here.
        </t>



        <t>In this specification, the term "byte" is used in its now-customary
sense as a synonym for "octet".</t>

      </section>
    </section>
    <section anchor="cbor-sequence-format" numbered="true" toc="default">
      <name>CBOR Sequence Format</name>
      <t>Formally, a CBOR Sequence is a sequence of bytes that is recursively
defined as either of the following:</t>
      <ul spacing="normal">
        <li>an empty (zero-length) sequence of bytes</li>
        <li>the sequence of bytes making up an encoded CBOR data item <xref target="RFC7049" format="default"/>
followed by a CBOR Sequence.</li>
      </ul>




      <t>In short, concatenating zero or more encoded CBOR data items generates
a CBOR Sequence.  (Consequently, concatenating zero or more CBOR
Sequences also results in a CBOR Sequence.)</t>
      <t>There is no end-of-sequence indicator.  (If one is desired, CBOR
      encoding an array of the CBOR data model values being encoded, employing
      either a definite or an indefinite length encoding, as a single CBOR
      data item may actually be the more appropriate representation.)</t>
      <t>CBOR Sequences, unlike JSON Text Sequences <xref target="RFC7464" format="default"/>, do not use a
marker between items.  This is possible because CBOR-encoded data
items are self delimiting and the end can always be calculated.  (Note
that, while the early object/array-only form of JSON was
self delimiting as well, this stopped being the case when simple
values such as single numbers were made valid JSON documents.)</t>
      <t>Decoding a CBOR Sequence works as follows:</t>
      <ul spacing="normal">
        <li>If the CBOR Sequence is an empty sequence of bytes, the result is an
empty sequence of CBOR data model values.</li>

        <li>Otherwise, one must decode a single CBOR data item from the bytes
        of the CBOR Sequence and insert the resulting CBOR data model value at
        the start of the result of repeating this decoding process recursively
        with the remaining bytes.  (A streaming decoder would therefore simply
        deliver zero or more CBOR data model values, each as soon as the bytes
        making it up are available.)</li>
      </ul>
      <t>This means that if any data item in the sequence is not well formed,
it is not possible to reliably decode the rest of the sequence.  (An
implementation may be able to recover from some errors in a sequence
of bytes that is almost, but not entirely, a well-formed encoded CBOR
data item.  Handling malformed data is outside the scope of this
specification.)</t>
      <t>This also means that the CBOR Sequence format can reliably detect
      truncation of the bytes making up the last CBOR data item in the
      sequence, but it cannot detect entirely missing CBOR data items at the end.  A
      CBOR Sequence decoder that is used for consuming streaming CBOR Sequence
      data may simply pause for more data (e.g., by suspending and later
      resuming decoding) in case a truncated final item is being received.</t>
    </section>
    <section anchor="the-cbor-seq-structured-syntax-suffix" numbered="true" toc="default">
      <name>The "+cbor-seq" Structured Syntax Suffix</name>


      <t>The use case for the "+cbor-seq" structured syntax suffix is
      analogous to that for "+cbor": it <bcp14>SHOULD</bcp14> be used by a
      media type when the result of parsing the bytes of the media type
      object as a CBOR Sequence is meaningful and is at least
      sometimes not just a single CBOR data item.  (Without the qualification
      at the end, this sentence is trivially true for any +cbor media type,
      which of course should continue to use the "+cbor" structured syntax
      suffix.)</t>
      <t>Applications encountering a "+cbor-seq" media type can then either simply
use generic processing if all they need is a generic view of the CBOR
Sequence or use generic CBOR Sequence tools for
initial parsing and then implement their own specific processing on
top of that generic parsing tool.</t>
    </section>
    <section anchor="practical-considerations" numbered="true" toc="default">
      <name>Practical Considerations</name>
      <section anchor="specifying-cbor-sequences-in-cddl" numbered="true" toc="default">
        <name>Specifying CBOR Sequences in Concise Data Definition Language (CDDL)</name>
        <t>In Concise Data Definition Language (CDDL) <xref target="RFC8610"
        format="default"/>, CBOR Sequences are already supported as contents
        of byte strings using the <tt>.cborseq</tt> control operator (<xref
	target="RFC8610" sectionFormat="of" section="3.8.4"/>) by employing an
        array as the controller type:</t>

<sourcecode type="cddl">my-embedded-cbor-seq = bytes .cborseq my-array
my-array = [* my-element]
my-element = my-foo / my-bar
</sourcecode>

        <t>Currently, CDDL does not provide for unadorned CBOR Sequences as a
        top-level subject of a specification.

 For now, the suggestion is to use an array for the top-level rule, as is used
 for the <tt>.cborseq</tt> control operator, and add English text that
 explains that the specification is really about a CBOR Sequence with the
 elements of the array:</t>

<sourcecode type="cddl">; This defines an array, the elements of which are to be used
; in a CBOR Sequence:
my-sequence = [* my-element]
my-element = my-foo / my-bar
</sourcecode>
        <t>(Future versions of CDDL may provide a notation for top-level CBOR
Sequences, e.g., by using a group as the top-level rule in a CDDL
specification.)</t>
      </section>
      <section anchor="diagnostic-notation" numbered="true" toc="default">
        <name>Diagnostic Notation</name>
        <t>CBOR diagnostic notation (see <xref target="RFC7049" sectionFormat="of" section="6"/>) or extended
diagnostic notation (<xref target="RFC8610" sectionFormat="of" section="G"/>) also does not provide
for unadorned CBOR Sequences at this time (the latter does provide for
CBOR Sequences embedded in a byte string as per <xref target="RFC8610" sectionFormat="of" section="G.3"/>).</t>

        <t>In a similar spirit to the recommendation for CDDL above, this
specification recommends enclosing the CBOR data items in an array.
In a more informal setting, where the boundaries within which the
notation is used are obvious, it is also possible to leave off the
outer brackets for this array, as shown in these two examples:</t>
        <artwork type="CBORdiag" name="" align="left" alt=""><![CDATA[
[1, 2, 3]

1, 2, 3
]]></artwork>
        <t>Note that it is somewhat difficult to discuss zero-length CBOR
Sequences in the latter form.</t>
      </section>
      <section anchor="optimizing-cbor-sequences-for-skipping-elements" numbered="true" toc="default">
        <name>Optimizing CBOR Sequences for Skipping Elements</name>
        <t>In certain applications, being able to efficiently skip an element
without the need for decoding its substructure, or efficiently fanning
out elements to multi-threaded decoding processes, is of the utmost
importance.  For these applications, byte strings
(which carry length information in bytes) containing embedded CBOR can
be used as the elements of a CBOR Sequence:</t>

<sourcecode type="cddl">; This defines an array of CBOR byte strings, the elements of which
; are to be used in a CBOR Sequence:
my-sequence = [* my-element]
my-element = bytes .cbor my-element-structure
my-element-structure = my-foo / my-bar
</sourcecode>
        <t>Within limits, this may also enable recovering from elements that
internally are not well formed; the limitation is that the sequence
of byte strings does need to be well formed as such.</t>
      </section>
    </section>
    <section anchor="security-considerations" numbered="true" toc="default">
      <name>Security Considerations</name>
      <t>The security considerations of CBOR <xref target="RFC7049" format="default"/> apply.  This format
provides no cryptographic integrity protection of any kind but can be
combined with security specifications such as CBOR Object Signing and
Encryption (COSE) <xref target="RFC8152" format="default"/> to do so.
(COSE protections can be applied to an entire CBOR Sequence or to each
of the elements of the sequence independently; in the latter case,
additional effort may be required if there is a need to protect the
relationship of the elements in the sequence.)</t>
      <t>As usual, decoders must operate on input that is assumed to be
untrusted.  This means that decoders <bcp14>MUST</bcp14> fail gracefully in the face
of malicious inputs.</t>
    </section>
    <section anchor="iana-considerations" numbered="true" toc="default">
      <name>IANA Considerations</name>
      <section anchor="media-type" numbered="true" toc="default">
        <name>Media Type</name>


        <t>Media types are registered in the "Media Types" registry
	<xref target="IANA-MEDIA-TYPES" format="default"/>.
	
IANA has registered the media type for CBOR Sequence,
application/cbor-seq, as follows:</t>
        <t>Type name: application</t>
        <t>Subtype name: cbor-seq</t>
        <t>Required parameters: N/A</t>
        <t>Optional parameters: N/A</t>
        <t>Encoding considerations: binary</t>
        <t>Security considerations: See RFC 8742, <xref target="security-considerations" format="default"/>.</t>
        <t>Interoperability considerations: Described herein.</t>
        <t>Published specification: RFC 8742.</t>
        <t>Applications that use this media type: Data serialization and deserialization.</t>
        <t>Fragment identifier considerations: N/A</t>
        <t>Additional information:</t>
        <ul spacing="normal">
          <li>Deprecated alias names for this type: N/A</li>
          <li>Magic number(s): N/A</li>
          <li>File extension(s): N/A</li>
          <li>Macintosh file type code(s): N/A</li>
        </ul>
        <dl newline="false" spacing="normal">
          <dt>Person &amp; email address to contact for further information:</dt>
          <dd>
  cbor@ietf.org</dd>
        </dl>
        <t>Intended usage: COMMON</t>
        <t>Author: Carsten Bormann (cabo@tzi.org)</t>
        <t>Change controller: IETF</t>
      </section>
      <section anchor="coap-content-format-registration" numbered="true" toc="default">
        <name>CoAP Content-Format Registration</name>
        <t>IANA has assigned a CoAP Content-Format ID for the media
type "application/cbor-seq", within the "CoAP Content-Formats" subregistry
of the "Constrained RESTful Environments (CoRE) Parameters" registry
<xref target="IANA-CORE-PARAMETERS" format="default"/>, from the "Expert Review" (0-255)
range (<xref target="RFC8126"/>).  The assigned ID is shown in <xref target="tbl-coap-content-formats" format="default"/>.</t>
        <table anchor="tbl-coap-content-formats" align="center">
          <name>CoAP Content-Format ID</name>
          <thead>
            <tr>
              <th align="left">Media type</th>
              <th align="left">Encoding</th>
              <th align="left">ID</th>
              <th align="left">Reference</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td align="left">application/cbor-seq</td>
              <td align="left">-</td>
              <td align="left">63</td>
              <td align="left">RFC 8742</td>
            </tr>
          </tbody>
        </table>

      </section>
      
      <section anchor="structured-syntax-suffix" numbered="true" toc="default">
        <name>Structured Syntax Suffix</name>
        <t>Structured Syntax Suffixes are registered within the "Structured
Syntax Suffix Registry" maintained at <xref target="IANA-STRUCTURED-SYNTAX-SUFFIX" format="default"/>.  IANA has
registered the "+cbor-seq" structured syntax suffix in accordance with
<xref target="RFC6838" format="default"/> as follows:</t>
        <ul empty="true" spacing="normal">
          <li>Name: CBOR Sequence</li>
        </ul>
        <ul empty="true" spacing="normal">
          <li>+suffix: +cbor-seq</li>
        </ul>
        <ul empty="true" spacing="normal">
          <li>References: RFC 8742</li>
        </ul>
        <ul empty="true" spacing="normal">
          <li>Encoding considerations: binary</li>
        </ul>
        <ul empty="true" spacing="normal">
         
 <li>Fragment identifier considerations: The syntax and semantics of
fragment identifiers specified for +cbor-seq <bcp14>SHOULD</bcp14> be the same
as that specified for "application/cbor-seq".  (At the time  of publication of this
document, there is no fragment identification syntax defined for
 "application/cbor-seq".)</li>
 
        </ul>
        <ul empty="true" spacing="normal">
          <li>
            <ul empty="true" spacing="normal">
              <li>The syntax and semantics for fragment identifiers for a
specific "xxx/yyy+cbor-seq" <bcp14>SHOULD</bcp14> be processed as follows:</li>
   
              <li>
               

 <ul  spacing="normal">
                  <li>For cases defined in +cbor-seq, if the fragment
identifier resolves per the +cbor-seq rules, then process as
specified in +cbor-seq.</li>
                  <li>For cases defined in +cbor-seq, if the fragment
identifier does not resolve per the +cbor-seq rules, then
process as specified in "xxx/yyy+cbor-seq".</li>
                  <li>For cases not defined in +cbor-seq, process as
specified in "xxx/yyy+cbor-seq".</li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>
        <ul empty="true" spacing="normal">
          <li>Interoperability considerations: n/a</li>
        </ul>
        <ul empty="true" spacing="normal">
          <li>Security considerations: See RFC 8742, <xref target="security-considerations" format="default"/></li>
        </ul>
        <ul empty="true" spacing="normal">
          <li>Contact: CBOR WG mailing list (cbor@ietf.org), or any IESG-designated successor.</li>
        </ul>
        <ul empty="true" spacing="normal">
          <li>Author/Change controller: IETF</li>
        </ul>

      </section>
    </section>
  </middle>
  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>

        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7049.xml"/>
    
    <reference anchor="IANA-STRUCTURED-SYNTAX-SUFFIX" target="https://www.iana.org/assignments/media-type-structured-suffix">
          <front>
            <title>Structured Syntax Suffix Registry</title>
            <author>
              <organization>IANA</organization>
            </author>
          </front>
        </reference>

        <reference anchor="IANA-CORE-PARAMETERS" target="https://www.iana.org/assignments/core-parameters">
          <front>
            <title>Constrained RESTful Environments (CoRE) Parameters</title>
            <author>
              <organization>IANA</organization>
            </author>
          </front>
        </reference>

        <reference anchor="IANA-MEDIA-TYPES" target="https://www.iana.org/assignments/media-types">
          <front>
            <title>Media Types</title>
            <author>
              <organization>IANA</organization>
            </author>
          </front>
        </reference>

        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
      </references>
      <references>
        <name>Informative References</name>
	<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8126.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6838.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7464.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8259.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8091.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8152.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8610.xml"/>
      </references>
    </references>
    <section numbered="false" anchor="acknowledgements" toc="default">
      <name>Acknowledgements</name>
      <t>This document has mostly been generated from <xref
      target="RFC7464" format="default"/> by <contact fullname="Nico Williams"/>
and <xref target="RFC8091" format="default"/> by <contact fullname="Erik Wilde"/>, which do a similar but slightly more
complicated exercise for JSON <xref target="RFC8259"
format="default"/>.  <contact fullname="Laurence Lundblade"/> raised an
issue on the CBOR mailing list that pointed out the need for this
document.  <contact fullname="Jim Schaad"/> and <contact fullname="John Mattsson"/> provided helpful comments.</t>
    </section>
  </back>

</rfc>
