<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.7.18 (Ruby 2.6.10) -->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-lundblade-cbor-cie-00" category="std" consensus="true" submissionType="IETF" tocInclude="true" sortRefs="true" symRefs="true" version="3">
  <!-- xml2rfc v2v3 conversion 3.22.0 -->
  <front>
    <title abbrev="CBOR CIE">Common Interoperable Encoding (CIE)</title>
    <seriesInfo name="Internet-Draft" value="draft-lundblade-cbor-cie-00"/>
    <author initials="L." surname="Lundblade" fullname="Laurence Lundblade">
      <organization>Security Theory LLC</organization>
      <address>
        <email>lgl@securitytheory.com</email>
      </address>
    </author>
    <date year="2024" month="July" day="23"/>
    <area>Applications and Real-Time</area>
    <workgroup>CBOR</workgroup>
    <keyword>cbor</keyword>
    <abstract>
      <?line 27?>

<t>CBOR allows variable serialization to accommodate varying use cases in constrained environments, but leaves it without a default interoperable serialization.
Here a base interoperability serialization is defined that should usable for a majority of CBOR based protocols.</t>
    </abstract>
  </front>
  <middle>
    <?line 32?>

<section anchor="introduction">
      <name>Introduction</name>
      <t>Partial implementation of IETF protocols is quite common.
For example, not all CWT implementations will implement all the defined claims.
For another example, COSE use cases that don't need encryption won't implement it.
In these, it is clear by use case what parts to implement and why.</t>
      <t>The issue with CBOR serialization is that there are multiple non-interoperable serializations for exactly the same thing.
For example, there are multiple ways to encode an integer, a string, an array or a map.</t>
      <t>Because CBOR is targeted at constrained environments, it is common to minimize what is implemented.
It can't be assumed that a decoder will implement every serialization varient for the data types it chooses to support.
In particular, indefinite-length strings are less likely to be supported universally.
They are the only thing where data can't be take directly out of the encoded message.
Because of this they usually require dynamic memory allocation where usually nothing else does.</t>
      <t>This draft establishes a single way to serialize the data types defined in <xref target="RFC8949"/> that will work well for a large number of CBOR protocols.
CBOR protocols can still of course choose from any of serialization variants in <xref target="RFC8949"/> should it be necessary for their use case.
The purpose of this draft is to provide an easy clear choice when there is not any special serialization need.</t>
      <section anchor="relation-to-preferred-serialization">
        <name>Relation to Preferred Serialization</name>
        <t>This is nearly the same as preferred serialization from <xref target="RFC8949"/>.</t>
        <t>The principle difference is that this unconditionally requires definite length encoding and prohibits indefinite length encoding.
Preferred serialization only makes conditional recommendation for the use of definite-length encoding.</t>
        <t>Another difference is that this establishes the serialization requirements as a standard using normative language.
While this is intended to be as close to and consistent with preferred serialization as possible, this document is the authoritative description of CBOR Interoperable Encoding.</t>
      </section>
      <section anchor="relation-to-cde">
        <name>Relation to CDE</name>
        <t>CIE is essentially the same as CDE without the map sorting requirement.
While CDE has all the characteristics necessary to provide gauranteed interoperability, map sorting can be burdensome to implement in some constrained environments.</t>
      </section>
    </section>
    <section anchor="common-interoperable-encoding">
      <name>Common Interoperable Encoding</name>
      <section anchor="encoder-requirements">
        <name>Encoder Requirements</name>
        <ol spacing="normal" type="1"><li>
            <t>Shortest-form encoding of the argument MUST be used for all major
types.
Major type 7 is used for floating-point and simple values; floating
point values have its specific rules for how the shortest form is
derived for the argument.
The shortest form encoding for any argument that is not a floating
point value is:  </t>
            <ul spacing="normal">
              <li>
                <t>0 to 23 and -1 to -24 MUST be encoded in the same byte as the
major type.</t>
              </li>
              <li>
                <t>24 to 255 and -25 to -256 MUST be encoded only with an additional
byte (ai = 0x18).</t>
              </li>
              <li>
                <t>256 to 65535 and -257 to -65536 MUST be encoded only with an
additional two bytes (ai = 0x19).</t>
              </li>
              <li>
                <t>65536 to 4294967295 and -65537 to -4294967296 MUST be encoded
only with an additional four bytes (ai = 0x1a).</t>
              </li>
            </ul>
          </li>
          <li>
            <t>If maps or arrays are emitted, they MUST use definite-length
encoding (never indefinite-length).</t>
          </li>
          <li>
            <t>If text or byte strings are emitted, they MUST use definite-length
encoding (never indefinite-length).</t>
          </li>
          <li>
            <t>If floating-point numbers are emitted, the following apply:  </t>
            <ul spacing="normal">
              <li>
                <t>The length of the argument indicates half (binary16, ai = 0x19),
single (binary32, ai = 0x1a) and double (binary64, ai = 0x1b)
precision encoding.
If multiple of these encodings preserve the precision of the
value to be encoded, only the shortest form of these MUST be
emitted.
That is, encoders MUST support half-precision and
single-precision floating point.
Positive and negative infinity and zero MUST be represented in
half-precision floating point.</t>
              </li>
              <li>
                <t>NaNs, and thus NaN payloads MUST be supported.      </t>
                <t>
As with all floating point numbers, NaNs with payloads MUST be
reduced to the shortest of double, single or half precision that
preserves the NaN payload.
The reduction is performed by removing the rightmost N bits of the
payload, where N is the difference in the number of bits in the
significand (mantissa) between the original format and the
reduced format.
The reduction is performed only (preserves the value only) if all the
rightmost bits removed are zero.</t>
              </li>
            </ul>
          </li>
          <li>
            <t>If big numbers (tags 2 and 3) are supported, the following apply:  </t>
            <ul spacing="normal">
              <li>
                <t>Positive values from 0 to 2^63 - 1 MUST be encoded as a type 0 integer.</t>
              </li>
              <li>
                <t>Negative values from -1 to -(2^64) MUST be encoded as a type 1 integer.</t>
              </li>
              <li>
                <t>Leading zeros MUST not be present in the byte string content of tag 2 and 3.</t>
              </li>
            </ul>
          </li>
          <li>
            <t>If big floats or decimal fractions with a big number mantissa are supported, the
big number serialization must conform to the above requirements for big numbers.</t>
          </li>
        </ol>
      </section>
      <section anchor="decoder-requirements">
        <name>Decoder Requirements</name>
        <ol spacing="normal" type="1"><li>
            <t>Decoders MUST accept shortest-form encoded arguments.</t>
          </li>
          <li>
            <t>If arrays or maps are supported, definite-length arrays or maps MUST be accepted.</t>
          </li>
          <li>
            <t>If text or byte strings are supported, definite-length text or byte
strings MUST be accepted.</t>
          </li>
          <li>
            <t>If floating-point numbers are supported, the following apply:  </t>
            <ul spacing="normal">
              <li>
                <t>Half-precision values MUST be accepted.</t>
              </li>
              <li>
                <t>Double- and single-precision values SHOULD be accepted; leaving these out
is only foreseen for decoders that need to work in exceptionally
constrained environments.</t>
              </li>
              <li>
                <t>If double-precision values are accepted, single-precision values
MUST be accepted.</t>
              </li>
              <li>
                <t>NaNs, and thus NaN payloads, MUST be accepted.</t>
              </li>
            </ul>
          </li>
          <li>
            <t>If big numbers (tags 2 and 3) are supported, type 0 and type 1 integers MUST
be accepted in place of a byte string big number. Leading zeros in a big number
byte string must be ignored.</t>
          </li>
          <li>
            <t>If big floats or decimal fractions with a big number mantissa are supported,
type 0 and type 1 integers must be accepted for the big number mantissa.</t>
          </li>
        </ol>
      </section>
    </section>
  </middle>
  <back>
    <references anchor="sec-normative-references">
      <name>Normative References</name>
      <reference anchor="RFC8949">
        <front>
          <title>Concise Binary Object Representation (CBOR)</title>
          <author fullname="C. Bormann" initials="C." surname="Bormann"/>
          <author fullname="P. Hoffman" initials="P." surname="Hoffman"/>
          <date month="December" year="2020"/>
          <abstract>
            <t>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>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>
        </front>
        <seriesInfo name="STD" value="94"/>
        <seriesInfo name="RFC" value="8949"/>
        <seriesInfo name="DOI" value="10.17487/RFC8949"/>
      </reference>
    </references>
    <?line 162?>



  </back>
  <!-- ##markdown-source:
H4sIAP7kn2YAA7VY227bSBJ951c0Jg9rL0TB94w1WGAzjoMY8CRB7MG8DdAk
W1JvSDa3u2lFGcy/76nq5kWU5cwCu4ANSGSzLqdOnSoqTdPkaSHOk8RrX6qF
uDFVZWpxV3tlTaOszEolbuvcFLpeiaObu9vjRGaZVXjq5uePnwWuJIXJa1nh
6cLKpU/Lti6yUhYqzTNj01yrtJReOZ/k0i+E80WSFLiwSHJTO1W71i2Et61K
nLdKVgtxd/v4LtGN5cvOn52cXJ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