Re: [Cbor] Interactions of packed CBOR and tags

Carsten Bormann <> Thu, 27 August 2020 21:32 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id 449223A138B; Thu, 27 Aug 2020 14:32:27 -0700 (PDT)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -1.897
X-Spam-Status: No, score=-1.897 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id ZnwfxzQCRAmc; Thu, 27 Aug 2020 14:32:24 -0700 (PDT)
Received: from ( []) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPS id 0F44F3A1389; Thu, 27 Aug 2020 14:32:23 -0700 (PDT)
Received: from ( []) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPSA id 4BcwtD23Krz100g; Thu, 27 Aug 2020 23:32:20 +0200 (CEST)
Content-Type: text/plain; charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.\))
From: Carsten Bormann <>
In-Reply-To: <00c101d67cb5$2588b790$709a26b0$>
Date: Thu, 27 Aug 2020 23:32:19 +0200
X-Mao-Original-Outgoing-Id: 620256739.813588-3ee99f684967157e218ac5249f0ecc41
Content-Transfer-Encoding: quoted-printable
Message-Id: <>
References: <00c101d67cb5$2588b790$709a26b0$>
To: Jim Schaad <>
X-Mailer: Apple Mail (2.3608.
Archived-At: <>
Subject: Re: [Cbor] Interactions of packed CBOR and tags
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <>
List-Unsubscribe: <>, <>
List-Archive: <>
List-Post: <>
List-Help: <>
List-Subscribe: <>, <>
X-List-Received-Date: Thu, 27 Aug 2020 21:32:27 -0000

> On 2020-08-27, at 23:00, Jim Schaad <> wrote:
> While building a test library of strings for evaluating my algorithm, I
> ended up with a question of how tags interact with the idea of CBOR packing.
> Specifically, if I use a standard date/time string with tag 0, should that
> text string be considered as a candidate for packing?
> 0("1970-01-01T00:00Z") could potentially be compressed to 0(simple(3))
> The problem is that this is no longer a valid CBOR encoding so it would not
> seem to be a legal thing to do.
> Question:  Must packed CBOR be valid CBOR or does that requirement only
> apply to unpacked CBOR?

Great question.

The cop-out could be: either.
Since CBOR-valid packed CBOR is a subset of (just well-formed) packed CBOR, it could be a parameter given to the compressor whether that is allowed to use compression opportunities like the above or not.

What are the benefits/drawbacks:

* (just well-formed) packed CBOR may lead to trouble with a generic decoder that cannot handle (present to the application) invalid constructs like 0(simple(3)).
The application can decide whether it wants to live with this limitation or not.

* the structural coherence of the packed structure (that this draft is about) will be expressed as a validity constraint.  It is a bit weird to then relax validity of what goes in there, but not entirely without precedent (e.g., tag 24, even though there is a more explicit firewall here).

* not using those compression opportunities can be wasteful, not just for the example given above (tag 0), but also for tags like 32.

I think I would emphasize the (just well-formed) packed CBOR, but still introduce CBOR-valid packed CBOR as a selectable additional constraint for applications that need to work with pre-packed (designed before packed was invented) generic decoders.

Do we need to encode this selection?  (E.g., via different top-level tags.)  Probably not.

Grüße, Carsten