[Cbor] Getting diagnostic notation examples in drafts under control

Carsten Bormann <cabo@tzi.org> Mon, 26 February 2024 20:31 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 019B5C151092 for <cbor@ietfa.amsl.com>; Mon, 26 Feb 2024 12:31:14 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.909
X-Spam-Level:
X-Spam-Status: No, score=-6.909 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01] 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 PAccWWXOYO_N for <cbor@ietfa.amsl.com>; Mon, 26 Feb 2024 12:31:09 -0800 (PST)
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 7CC42C14CF15 for <cbor@ietf.org>; Mon, 26 Feb 2024 12:31:07 -0800 (PST)
Received: from eduroam-pool10-028.wlan.uni-bremen.de (eduroam-pool10-028.wlan.uni-bremen.de [134.102.90.27]) (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 4TkC1h2lVkzDCcZ; Mon, 26 Feb 2024 21:31:04 +0100 (CET)
From: Carsten Bormann <cabo@tzi.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-Mao-Original-Outgoing-Id: 730672263.781759-0c426f64dd37a9dc8e303fc714a83d20
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\))
Date: Mon, 26 Feb 2024 21:31:03 +0100
Message-Id: <FD64709D-2B97-4DED-9915-331FE7188EE8@tzi.org>
To: cbor@ietf.org
X-Mailer: Apple Mail (2.3608.120.23.2.7)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/D8h_0Egog89GaRLFNwb1VfKlHI4>
Subject: [Cbor] Getting diagnostic notation examples in drafts under control
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: Mon, 26 Feb 2024 20:31:14 -0000

In diagnostic notation examples used during development of a draft,
authors often use text strings for the constants they need, even
though they actually mean a placeholder for a later, to-be-registered
integer.

I just reviewed draft-ietf-ace-oscore-gm-admin, where this is rampant:

      {
          "group_mode" : true,
          "gp_enc_alg" : 10,
                "hkdf" : 5
      }

All the map keys shown here that look like text strings are actually
intended to be integers (which at this point still need to be
assigned).
(There are also integers, without explanation what they mean.)

This is a problem, as the examples are not machine-readable (well,
they are, but they mean the wrong thing in half of the places without
any warning that this is so).

At IETF 118, I gave a brief concept presentation for an application
extension to CBOR diagnostic mode that I called e’’.
(The name `e` could stand for enum value, or external constant, etc.
You choose :-)

I have implemented this now in the cbor-diag tools.

First, you need a CDDL file (we’ll call gmadmin.cddl in our example)
that gives the actual values for the constants, as in:

   group_mode = 33
   gp_enc_alg = 34
   hkdf = 31
   HMAC-256-256 = 5
   AES-CCM-16-64-128 = 10

This can be a complete CDDL file, no need to limit it to constants.
You can set this up with your TBD values of the constants to be
assigned, and once they are, you only need to update them in one place.

Then, you can write the diagnostic notation example in the draft like
this (let’s call this gmadmin.diag):

      {
          e'group_mode' : true,
          e'gp_enc_alg' : e'HMAC-256-256',
                e'hkdf' : e'AES-CCM-16-64-128'
      }

The diag2x.rb tools can correctly read and interpret this; so for example
after setting

   export CBOR_DIAG_CDDL=gmadmin.cddl

applying diag2diag.rb to gmadmin.diag spits out:

$ diag2diag.rb -ae gmadmin.diag
{33: true, 34: 10, 31: 5}

You need to enable the application extension `e` (-ae), which you can
install via:

  gem install cbor-diag-e cddlc

(cbor-diag-e uses cddlc internally, so it must be in PATH.)

The details of this little tool are certainly up for discussion, but it
really does work for me already.

In the long run, this works best if edn-literal is approved (hint,
hint), and the `e''` extension is registered.

Until then, each document using this scheme can simply use boilerplate
such as:

In the CBOR diagnostic notation used in this document, constructs of
the form `e’somename'` are replaced by the value assigned to
`somename` in CDDL in figure 0815.
E.g., `{e'group_mode': "bar"}` stands for `{33: "bar"}`.
[Choose 0815, group_mode and 33 along the lines of the figure with the
CDDL included.]

Should I write an Internet-Draft for this?

Grüße, Carsten