From f37c5c4d7bbd40c079eb00a2b0ab1e4d9ae65430 Mon Sep 17 00:00:00 2001 From: Eric Myhre Date: Sun, 15 Oct 2017 22:24:38 +0200 Subject: [PATCH] cbor: decode tags. (Partially) fixes #7. The tag info is currently not retained, but this simple fix to parsing means we can at least consume and decode the rest of a cbor object containing (single-at-a-time) tags. Signed-off-by: Eric Myhre --- cbor/cborDecoder.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cbor/cborDecoder.go b/cbor/cborDecoder.go index 494224f..7436b51 100644 --- a/cbor/cborDecoder.go +++ b/cbor/cborDecoder.go @@ -239,8 +239,24 @@ func (d *Decoder) stepHelper_acceptValue(majorByte byte, tokenSlot *Token) (done d.pushPhase(d.step_acceptMapKey) return false, err case majorByte >= cborMajorTag && majorByte < cborMajorSimple: - return true, fmt.Errorf("cbor tags not supported") - // but when we do, it'll be by saving it as another field of the Token, and recursing. + // CBOR tags are, frankly, bonkers, and should not be used. + // They break isomorphism to basic standards like JSON. + // We'll parse basic integer tag values -- SINGLE layer only. + // We will NOT parse the full gamut of recursive tags: doing so + // would mean allowing an unbounded number of allocs *during + // *processing of a single token*, which is _not reasonable_. + _, err = d.decodeLen(majorByte) + if err != nil { + return true, err + } + // Okay, we slurped a tag. + // And dropped it on the floor. Because screw tags. + // Read next value. + majorByte, err := d.r.Readn1() + if err != nil { + return true, err + } + return d.stepHelper_acceptValue(majorByte, tokenSlot) default: return true, fmt.Errorf("Invalid majorByte: 0x%x", majorByte) }