Subject: [Cbor] Fwd: CDDL tool doesn't recognize h'hexstring'?

From: Carsten Bormann <[email-masked]>
Date: Mon, 27 Mar 2017 18:28:52 -0500

I just got this interesting feedback (and permission to forward it to the list).

Welcome to the CBOR WG, Jeffrey!

(Jeffrey also got me to finally support byte strings constants in the CDDL tool.
But there certainly still is a lot of work to do with the tool; see further below.)

Grüße, Carsten

> Begin forwarded message:
> 
> From: Jeffrey Yasskin <[email-masked] <mailto:[email-masked]>>
> Subject: Re: CDDL tool doesn't recognize h'hexstring'?
> Date: 27 March 2017 at 17:23:36 -0500
> To: Carsten Bormann <[email-masked] <mailto:[email-masked]>>
> 
> My CBOR patch is now in https://github.com/dimich-g/webpackage/pull/36 <https://github.com/dimich-g/webpackage/pull/36>. I noticed two extra things while completing the patch:
> 
> 5. Use of COSE_Sign could benefit from the generics you ponder in https://tools.ietf.org/html/draft-greevenbosch-appsawg-cbor-cddl-10#appendix-B.1 <https://tools.ietf.org/html/draft-greevenbosch-appsawg-cbor-cddl-10#appendix-B.1>. In particular, uses are likely to want to specify the bytes stored in the payload, and to extend the protected and unprotected maps. They may also want to constrain the use of Generic_Headers in the protected and unprotected maps, but it's less obvious how to accomplish that.
> 6. Some sort of namespacing might be helpful so that a reference to the 'Headers' type in the COSE spec isn't ambiguous with a local 'Headers' or a type of that name in some other spec.
> 
> Also, if you're collecting uses of CDDL, WebAuthn is also using it: https://w3c.github.io/webauthn/#sec-attestation-data <https://w3c.github.io/webauthn/#sec-attestation-data>
> 
> Jeffrey
> 
> […]
> 
> Other problems I've found so far are:
> The non-BMP emoji cause parse errors, in either comments or 'bytestrings'.
> json-generate tries to turn 0xF0 into a UTF-8 character and fails, instead of noticing that it's part of a larger sequence.
> generate can't handle .within. A simple fix might be to just ignore the right side of .within.
> It's odd that `{stuff} .within {otherstuff}` fails to parse, since the braces should provide as much grouping as parentheses, but I haven't checked the CDDL grammar to see if it's forbidden there too.
> I can reduce these if you need.
> 
> Thanks,
> Jeffrey

---

From: Michael Richardson <[email-masked]>
Date: Mon, 27 Mar 2017 23:30:43 -0400

I wrote this very small/stupid library:
  https://github.com/mcr/ChariWTs/blob/master/lib/c_hex.rb

you can feed it the output of cbor2pretty, (such as you might find in an
rfc...) to get binary back.  See examples at:
  https://github.com/mcr/ChariWTs/blob/master/spec/model/signature_spec.rb

I will extract it into a gem, I guess.
(but, plesae don't read any of the code, as it is probably wrong)

--
Michael Richardson <[email-masked]>, Sandelman Software Works
 -= IPv6 IoT consulting =-

---

From: Carsten Bormann <[email-masked]>
Date: Tue, 28 Mar 2017 07:30:04 -0500

Hi Michael,

This is so useful that I wrote it a while ago, too (full source code below).

I just realize it is not mentioned in the README.md, but it is part of the cbor-diag gem:

	gem install cbor-diag
	pretty2cbor.rb foo >bar

Grüße, Carsten

#!/usr/bin/env ruby
require 'cbor-pure'
require 'cbor-pretty'

def extractbytes(s)
  s.each_line.map {|ln| ln.sub(/#.*/, '')}.join.scan(/[0-9a-fA-F][0-9a-fA-F]/).map {|b| b.to_i(16).chr(Encoding::BINARY)}.join
end

print(extractbytes(ARGF))

> On 27 Mar 2017, at 22:30, Michael Richardson <[email-masked]> wrote:
> 
> 
> _______________________________________________
> CBOR mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/cbor

---

From: Michael Richardson <[email-masked]>
Date: Tue, 28 Mar 2017 11:58:31 -0400

Carsten Bormann <[email-masked]> wrote:
    > def extractbytes(s) s.each_line.map {|ln| ln.sub(/#.*/,
    > '')}.join.scan(/[0-9a-fA-F][0-9a-fA-F]/).map {|b|
    > b.to_i(16).chr(Encoding::BINARY)}.join end

    > print(extractbytes(ARGF))

It's too short :-)