Re: [Cbor] extensible enumerations, ignoring unknown values in CDDL

Carsten Bormann <cabo@tzi.org> Sun, 14 April 2024 08:23 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 80F0BC14F61E for <cbor@ietfa.amsl.com>; Sun, 14 Apr 2024 01:23:26 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -4.185
X-Spam-Level:
X-Spam-Status: No, score=-4.185 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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 nZmsClR1GtF4 for <cbor@ietfa.amsl.com>; Sun, 14 Apr 2024 01:23:21 -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 058B8C14F619 for <cbor@ietf.org>; Sun, 14 Apr 2024 01:23:18 -0700 (PDT)
Received: from eduroam-pool10-144.wlan.uni-bremen.de (eduroam-pool10-144.wlan.uni-bremen.de [134.102.90.143]) (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 4VHNbl6tH7zDCbx; Sun, 14 Apr 2024 10:23:15 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <CAKoiRua7YXqw4T2zOfoQG7LkaUZ6he1jTsniWC0EPFnunsSzkw@mail.gmail.com>
Date: Sun, 14 Apr 2024 10:23:15 +0200
Cc: cbor@ietf.org
X-Mao-Original-Outgoing-Id: 734775795.11178-8a26cf6c6765e7706065e7519ef56703
Content-Transfer-Encoding: quoted-printable
Message-Id: <0966BC9D-70A3-4C48-A719-81D2B3771EAB@tzi.org>
References: <CAKoiRua7YXqw4T2zOfoQG7LkaUZ6he1jTsniWC0EPFnunsSzkw@mail.gmail.com>
To: Rohan Mahy <rohan.mahy@gmail.com>
X-Mailer: Apple Mail (2.3608.120.23.2.7)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/4YfSjv13vhvA_2dXchSgMeipgAQ>
Subject: Re: [Cbor] extensible enumerations, ignoring unknown values in 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: Sun, 14 Apr 2024 08:23:26 -0000

Hi Rohan,

CDDL does have an enum-like feature [1].

[1]: https://www.rfc-editor.org/rfc/rfc8610.html#section-2.2.2.2

> One of the enums we are using, "Disposition" should have a valid range from 0 to 255, but only the values from 0 to 8 have known values. The intent is that new values between 9 and 255 inclusive will be valid, and if unknown they will be treated as if they had the default disposition (render).
> enum Disposition {
>     unspecified = 0,
>     render = 1,
>     reaction = 2,
>     profile = 3,
>     inline = 4,
>     icon = 5,
>     attachment = 6,
>     session = 7,
>     preview = 8
> };

[1] has this example (abbreviated)

              terminal-color = &basecolors
              basecolors = (
                black: 0,  red: 1,  green: 2,  yellow: 3,
                blue: 4,  magenta: 5,  cyan: 6,  white: 7,
              )

This could be extended to include 8..255:

              terminal-color = &basecolors
              basecolors = (
                black: 0,  red: 1,  green: 2,  yellow: 3,
                blue: 4,  magenta: 5,  cyan: 6,  white: 7,
                reserved: 8..255
              )

Using the .feature mechanism, the validator could show that an extension was used:

              terminal-color = &basecolors
              basecolors = (
                black: 0,  red: 1,  green: 2,  yellow: 3,
                blue: 4,  magenta: 5,  cyan: 6,  white: 7,
                reserved: (8..255) .feature "extension"
              )

(Use a better name than “extension”.)

This works great for a single document that is designed to be extensible.
(It can also be done without using »&« by creating a simple choice.)

Now, the question is, how to enable further documents to write their own CDDL about the extensions they define.

This can be done with a socket [2]:

[2]: https://www.rfc-editor.org/rfc/rfc8610.html#section-3.9

terminal-color = $terminal-color / (0..255) .feature “extension"
$terminal-color /= &basecolors
basecolors = (
                black: 0,  red: 1,  green: 2,  yellow: 3,
                blue: 4,  magenta: 5,  cyan: 6,  white: 7,
              )

The extending spec then says:

pastelcolors = ( pink: 9, mauve: 10, peach: 11, lavender: 12 )
$terminal-color /= &pastelcolors

Note how the prioritized choice semantics of CDDL [3] make sure that, with these rules added, lavender is always matched for 12 instead of any extension feature.  Prioritized choice is also the reason why the example puts its catch-all 0..255 not as part of the socket, but adds it as a choice with a lower priority than the socket.

[3]: https://www.rfc-editor.org/rfc/rfc8610.html#appendix-A

I should probably mention that another CDDL mechanism that can come in handy for structural extensibility is .within [4]; I don’t think we’d need it here.

[4]: https://www.rfc-editor.org/rfc/rfc8610.html#section-3.8.5

Grüße, Carsten