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

From: Carsten Bormann <[email-masked]>
Date: Thu, 18 Jul 2019 13:36:47 +0200

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:

http://cbor.me/?bytes=43(010203)

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