[Cbor] CDDL optionality and choices and optionality in CBOR and CDDL

Rohan Mahy <rohan.mahy@gmail.com> Sat, 13 April 2024 00:50 UTC

Return-Path: <rohan.mahy@gmail.com>
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 8D216C14F721 for <cbor@ietfa.amsl.com>; Fri, 12 Apr 2024 17:50:10 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.097
X-Spam-Level:
X-Spam-Status: No, score=-2.097 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
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 vYVz9ClQB5Nb for <cbor@ietfa.amsl.com>; Fri, 12 Apr 2024 17:50:08 -0700 (PDT)
Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 AAFF4C14F703 for <cbor@ietf.org>; Fri, 12 Apr 2024 17:50:08 -0700 (PDT)
Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a51a7d4466bso163688266b.2 for <cbor@ietf.org>; Fri, 12 Apr 2024 17:50:08 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712969406; x=1713574206; darn=ietf.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=SNZDDqLIfuWWh8OxUURe5aY1AiucXY0eeRiLF57FEjo=; b=HMRu8vjetXWmzGiOdvp+EEaMZaWGkkE9d2bP8lXAtjxfsY+grsq7jwh46hiUIp/Xav gUXxOe5tVhXx7x/hFU/+5Cm5Ztf+To0+7zMprwiN/l36lbdiZW1XT9qGQAncDJez2X4L x73dkYG1fwSP+KVrXOsXi8goiMKOw1AeGeijd1R8reaeSM9WEtmlVxCOqAuFcmceCtRI IXh5DnpufM9ZkZ1bv56ckKXChgMhK33MPI6IgIxH1dbyDkTTOxNDY+i07xnBLGrv3XJj w3A6EO/iLq2HZWDKHW0x0cCb/SZzdTI/L6mBcEXVIkNwNOZMecc9ZNZjzrtMhPnOCD0g MrDA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712969406; x=1713574206; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SNZDDqLIfuWWh8OxUURe5aY1AiucXY0eeRiLF57FEjo=; b=AtJDKKT553FRanBHB+fOqVAmS+NUUBxAXnn/V3p4gSl7PVezwM2yQWDfsaXVlFHn4D u1WHz07asGRE7hwRuc7QtyA7YyTnYj4GZuFy/w5D6PoMblnf5E9ZpR2/Cm0UqNkEzF/Y ggbNb65T57O1KwxsbHQorbgIb0nskzef4RBpyC7S+/OEuGbJ4n2+EAdnr3GFST+NmUxe A/68E1l6zXrfRFJ57cv2pfS/Xqy/DdAoFl+Sjhr/qiYCqAVzHpU/v04lDhLdvljIlCzC QSYM1Vd/7tfLvtcF6u5istXx/xKJgmmiSxAWoy9r0FLuyoLnpS9Z2OGTn2mhXCmwMSSz nEcQ==
X-Gm-Message-State: AOJu0YwKxQZSTRNkAMXNW6tm6iVcNQHNsTrfE3vYTDhwL9UWLXptJcMW KUcobrPNB25pFrYzJ8C+DpIcEb0StDOrIQ55qZ6t48a3o5BWnl4ov4oB52UxOZZYznCSn6pFJuJ E/SktqAbW6cSMpKLkc3ySwmpsfv2JffoZ
X-Google-Smtp-Source: AGHT+IHF78GIRR/yfsgdw+A0fkUMjFwA2POMBuF/zqdCbM1BLFoa7Kv91bQk/1JLvecKz0ERJlB3yP/8fKifSpHjvlQ=
X-Received: by 2002:a17:907:9495:b0:a52:3efe:9208 with SMTP id dm21-20020a170907949500b00a523efe9208mr1764910ejc.55.1712969406114; Fri, 12 Apr 2024 17:50:06 -0700 (PDT)
MIME-Version: 1.0
From: Rohan Mahy <rohan.mahy@gmail.com>
Date: Fri, 12 Apr 2024 17:49:53 -0700
Message-ID: <CAKoiRubb4GMm1sTq_1XRZt3+-hy+Z8ZXD21DpK5voneXFRcW6A@mail.gmail.com>
To: cbor@ietf.org
Content-Type: multipart/alternative; boundary="000000000000f679100615efc4ee"
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/aUFgTmvqLkw__SG3SM2T6Su4kDw>
Subject: [Cbor] 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 00:50:10 -0000

Hi,

1) I read RFC 8610 and came up with the following CDDL document. The
cddl-rs tool says that the CDDL is confirmant:

Content = [
>   replaces: null / MessageId,
>   expires: uint .size 4,
> ]
>
> MessageId = bstr .size 32
>

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?

If I try to validate a CBOR document with
[ h'9936b46e7609af57e7f3d8528b6eabc7f52dbf6c01c94f7cff46333cd0b82a0c', 0 ]
this validates, but [ null, 0 ] fails with "error validating type choice at
cbor location /0: expected 32, got Null".

Is this a bug with the cddl-rs validation tool or did I misunderstand how
CDDL is interpreted?

2) In TLS Presentation Language, you can require different elements
depending on the value of a field that appeared previously. It appears that
I could do this in CDDL as well, but the spec is silent about that
application. For example, presumably this describes an array of 3 items,
the first is an array of food items, the second is either the simple value
true or false, the third value is an array of drink items if the second
value is true OR a boolean if the second item is false.

Order = [
  food = [ * food_items ],
  ( includes_alcohol: true, drinks = [ * drink_items ] ) / (
includes_alcohol: false, to_go: bool )
]
bool = true / false

Is this possible in CDDL?

Many Thanks,
-rohan