[Cbor] Decoding embedded CBOR with cbor-diag and on the playground

Carsten Bormann <cabo@tzi.org> Thu, 18 July 2019 11:36 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost []) by ietfa.amsl.com (Postfix) with ESMTP id DA2781201E2 for <cbor@ietfa.amsl.com>; Thu, 18 Jul 2019 04:36:27 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -4.197
X-Spam-Status: No, score=-4.197 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([]) by localhost (ietfa.amsl.com []) (amavisd-new, port 10024) with ESMTP id 5a94U_IrLmLF for <cbor@ietfa.amsl.com>; Thu, 18 Jul 2019 04:36:26 -0700 (PDT)
Received: from gabriel-vm-2.zfn.uni-bremen.de (gabriel-vm-2.zfn.uni-bremen.de []) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 3BB591201CA for <cbor@ietf.org>; Thu, 18 Jul 2019 04:36:26 -0700 (PDT)
Received: from [] (unknown []) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gabriel-vm-2.zfn.uni-bremen.de (Postfix) with ESMTPSA id 45qBt04CQCzyf9; Thu, 18 Jul 2019 13:36:24 +0200 (CEST)
From: Carsten Bormann <cabo@tzi.org>
Content-Type: text/plain; charset=utf-8
X-Mao-Original-Outgoing-Id: 585142604.2759579-78157b18eb785b45c725e7a9ef3a620f
Content-Transfer-Encoding: quoted-printable
Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\))
Date: Thu, 18 Jul 2019 13:36:47 +0200
Message-Id: <C14A8532-997D-4E8D-8B54-01A7308AF3CA@tzi.org>
To: cbor@ietf.org
X-Mailer: Apple Mail (2.3445.9.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/Z5VRaYtwfDIxCjFvMaqSZZo-2OY>
Subject: [Cbor] Decoding embedded CBOR with cbor-diag and on the playground
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: Thu, 18 Jul 2019 11:36:28 -0000

Peter Vanderstok was kind enough to push me into implementing a feature for the diagnostic tools I had wanted to do for a while:  Looking at each byte string and trying if that happens to decode as a (non-empty) CBOR sequence; if yes, show that as embedded CBOR instead of showing the byte string.

In some formats, this creates tons of false positives, so that behavior is an option.

* Programmatic: “gem update cbor-diag”, and then try:
set the option :try_decode_embedded to true, as in

puts "000”.b.cbor_diagnostic(try_decode_embedded: true)
<< -17, -17, -17 >>

puts "Bad".b.cbor_diagnostic(try_decode_embedded: true)
<< << “d” >> >>

puts “badBad".b.cbor_diagnostic(try_decode_embedded: true)
<< “ad", << "d" >> >>

puts "Eatbad".b.cbor_diagnostic(try_decode_embedded: true)
<< << “t", "ad" >> >>

puts "EatBad".b.cbor_diagnostic(try_decode_embedded: true)
<< << "t", << "d" >> >> >>

* Playground: Try:


Then set the “emb cbor” checkbox, and try decoding again.

(Or go straight to http://cbor.me/?bytes=43(010203)&embcbor=yes  .)

* To do: make that option available for the cbor diagnostic command line tools, too.

* Later to do: set this flag locally if a tag 24 is seen.

Grüße aus Amsterdam, Carsten