[Cbor] Serialization choices vs. CDDL (Re: CDDL optionality and choices and optionality in CBOR and CDDL)

Carsten Bormann <cabo@tzi.org> Sat, 13 April 2024 05:56 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 25B86C14F680 for <cbor@ietfa.amsl.com>; Fri, 12 Apr 2024 22:56:02 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.885
X-Spam-Level:
X-Spam-Status: No, score=-1.885 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fBMmIjYfqT_H for <cbor@ietfa.amsl.com>; Fri, 12 Apr 2024 22:55:55 -0700 (PDT)
Received: from smtp.zfn.uni-bremen.de (smtp.zfn.uni-bremen.de [134.102.50.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id B6515C14F6F1 for <cbor@ietf.org>; Fri, 12 Apr 2024 22:55:54 -0700 (PDT)
Received: from smtpclient.apple (p5089a211.dip0.t-ipconnect.de [80.137.162.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.zfn.uni-bremen.de (Postfix) with ESMTPSA id 4VGjN85VcVzDCbt; Sat, 13 Apr 2024 07:55:52 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <CAKoiRubb4GMm1sTq_1XRZt3+-hy+Z8ZXD21DpK5voneXFRcW6A@mail.gmail.com>
Date: Sat, 13 Apr 2024 07:55:42 +0200
Cc: cbor@ietf.org
Content-Transfer-Encoding: quoted-printable
Message-Id: <AFF12C56-CB02-43C8-9EFA-5656CAEF9E9A@tzi.org>
References: <CAKoiRubb4GMm1sTq_1XRZt3+-hy+Z8ZXD21DpK5voneXFRcW6A@mail.gmail.com>
To: Rohan Mahy <rohan.mahy@gmail.com>
X-Mailer: Apple Mail (2.3774.500.171.1.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/hOcSZQyp0qOu5Xcrt9bP9jKU9tk>
Subject: [Cbor] Serialization choices vs. CDDL (Re: CDDL optionality and choices and optionality in CBOR and CDDL)
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sat, 13 Apr 2024 05:56:02 -0000

On 13. Apr 2024, at 02:49, Rohan Mahy <rohan.mahy@gmail.com> wrote:
> 
> I interpret the CDDL spec to mean that the encoding of the first item in the array is either F6 (null);  or 58 20 followed by 32 octets. Did I interpret the CDDL spec correctly? 

CDDL operates on the data model level, not on the representation format level.

The .size control operator on an integer is a convenient way to limit the range of an integer based on what the maximum value for the minimum encoding size for that integer is, not the actual size in the representation format.
The latter is usually set by the encoder according to the rules for preferred serialization (Section 4.1 of RFC 8949 [1]), but it is allowed to choose other serialization variants (unless it actually intends to provide deterministic encoding, Section 4.2 of RFC 8949 [2] and draft-ietf-cbor-cde [3]).

I understand that you are looking at providing a fixed size header for a data format.
You may want to look at the fixed-size representations we have in the tagged array specification [4], where most of the tags defined give an interpretation to byte strings (here: as an array of numbers).

Grüße, Carsten

[1]: https://www.rfc-editor.org/rfc/rfc8949.html#name-preferred-serialization
[2]: https://www.rfc-editor.org/rfc/rfc8949.html#name-deterministically-encoded-c
[3]: https://www.ietf.org/archive/id/draft-ietf-cbor-cde-02.html
[4]: https://www.rfc-editor.org/rfc/rfc8746.html