Re: [Cbor] Using cddl-control to dissect byte strings

Christian Amsüss <christian@amsuess.com> Fri, 30 July 2021 12:43 UTC

Return-Path: <christian@amsuess.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 0BDCF3A28EE; Fri, 30 Jul 2021 05:43:41 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.9
X-Spam-Level:
X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pG3VxQcYCzS9; Fri, 30 Jul 2021 05:43:36 -0700 (PDT)
Received: from prometheus.amsuess.com (alt.prometheus.amsuess.com [IPv6:2a01:4f8:190:3064::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id AB6053A28ED; Fri, 30 Jul 2021 05:43:35 -0700 (PDT)
Received: from poseidon-mailhub.amsuess.com (095129206250.cust.akis.net [95.129.206.250]) by prometheus.amsuess.com (Postfix) with ESMTPS id 45CC74013C; Fri, 30 Jul 2021 14:43:30 +0200 (CEST)
Received: from poseidon-mailbox.amsuess.com (hermes.amsuess.com [10.13.13.254]) by poseidon-mailhub.amsuess.com (Postfix) with ESMTP id 474BED0; Fri, 30 Jul 2021 14:43:29 +0200 (CEST)
Received: from hephaistos.amsuess.com (unknown [188.20.219.122]) by poseidon-mailbox.amsuess.com (Postfix) with ESMTPSA id D842A101; Fri, 30 Jul 2021 14:43:28 +0200 (CEST)
Received: (nullmailer pid 3255193 invoked by uid 1000); Fri, 30 Jul 2021 12:43:28 -0000
Date: Fri, 30 Jul 2021 14:43:28 +0200
From: Christian Amsüss <christian@amsuess.com>
To: Carsten Bormann <cabo@tzi.org>
Cc: cbor@ietf.org, draft-ietf-lake-edhoc@ietf.org
Message-ID: <YQPz8H8WCUDXk/5/@hephaistos.amsuess.com>
References: <YQPkJEnTlT1ndXEf@hephaistos.amsuess.com> <E1CB86D0-20DA-40DB-899E-23A10BD56B71@tzi.org>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="2k3Mpn7dY443WO52"
Content-Disposition: inline
In-Reply-To: <E1CB86D0-20DA-40DB-899E-23A10BD56B71@tzi.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/8_UMx_rXf9RpJhSHF94AvhUDpJY>
Subject: Re: [Cbor] Using cddl-control to dissect byte strings
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
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: Fri, 30 Jul 2021 12:43:41 -0000

> ## Using cddl-control to make CBOR even less schema-less

An action from this very fitting observation could be to decorate any
use of such a construction with text like:

| This concatenation touches the fringes of CBOR applicability: We
| sacrifice discernible CBOR structure to save off single bytes, which
| runs counter to CBOR's priorization of being schemaless over
| serialization compactness {{Section E of RFC8949}}. This approach is
| not recommended for general use without clear size boundaries that
| need to be met.

> I’d probably use .abnfb for many of these; at least if (like in this
> example) you don't need to go back to CDDL names (which is a
> shortcoming I have a plan for, but that will happen later this year).

I'm curious to see that.

(For this particular case, ABNF might not easily cut it, for the string
length will only be known at runtime, and the steps to get the generic
length into the ABNF processor will make this exercise look tame in
comparison).

> You mentioned the cddl tool generator — does the validator choke on this?

    $ cat minhoc.cddl
    message_alg42 = [message<4>]
    message<L> = (number: uint, key<L> .cat data)
    key<L> = bstr .size L
    data = bstr
    $ cddl minhoc.cddl generate | tee minhoc.diag
    [1146, h'B3BFE8437065727369737473']
    $ diag2cbor.rb minhoc.diag > minhoc.cbor
    $ cddl minhoc.cddl validate minhoc.cbor
    CDDL validation failure
    [ full output at the end of the mail ]

> (I don’t want to think about .det here.)

For purposes of parser building (which is even stricter than validation,
for validation probably doesn't need to find a *unique* assignment),
there are reversible and irreversible controls; det is just
irreversible, as is `bstr .cat bstr` without further constraints.

> (BTW^2: Why the [()]?  It does look very important, but maybe not
> necessary?)

Just an effect of me editing around; needless, and fixed in current
example.

BR
c

---

CDDL validation failure (nil for [1146, "\xB3\xBF\xE8Cpersists"]):
["\xB3\xBF\xE8Cpersists",
 [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]],
 "\n" +
 "occur 0 < 1, not reached at 1 in array [1146, \"\\xB3\\xBF\\xE8Cpersists\"] for [:array, [:member, 1, 1, [:text, \"number\"], [:prim, 0]], [:member, 1, 1, nil, [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]]]][\"\\xB3\\xBF\\xE8Cpersists\", [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]], \"\\noccur 0 < 1, not reached at 1 in array [1146, \\\"\\\\xB3\\\\xBF\\\\xE8Cpersists\\\"] for [:array, [:member, 1, 1, [:text, \\\"number\\\"], [:prim, 0]], [:member, 1, 1, nil, [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]]]]\"] -- cannot complete (false, 2) array [1146, \"\\xB3\\xBF\\xE8Cpersists\"] for [:array, [:member, 1, 1, [:text, \"number\"], [:prim, 0]], [:member, 1, 1, nil, [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]]]]"]
[h'B3BFE8437065727369737473', [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]], "\noccur 0 < 1, not reached at 1 in array [1146, \"\\xB3\\xBF\\xE8Cpersists\"] for [:array, [:member, 1, 1, [:text, \"number\"], [:prim, 0]], [:member, 1, 1, nil, [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]]]][\"\\xB3\\xBF\\xE8Cpersists\", [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]], \"\\noccur 0 < 1, not reached at 1 in array [1146, \\\"\\\\xB3\\\\xBF\\\\xE8Cpersists\\\"] for [:array, [:member, 1, 1, [:text, \\\"number\\\"], [:prim, 0]], [:member, 1, 1, nil, [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]]]]\"] -- cannot complete (false, 2) array [1146, \"\\xB3\\xBF\\xE8Cpersists\"] for [:array, [:member, 1, 1, [:text, \"number\"], [:prim, 0]], [:member, 1, 1, nil, [:anno, :cat, [:anno, :size, [:prim, 2], [:int, 4]], [:prim, 2]]]]"]


-- 
To use raw power is to make yourself infinitely vulnerable to greater powers.
  -- Bene Gesserit axiom