diff --git a/src/cbor/lexer.cr b/src/cbor/lexer.cr index 591f62c..60ea3c4 100644 --- a/src/cbor/lexer.cr +++ b/src/cbor/lexer.cr @@ -79,6 +79,8 @@ class CBOR::Lexer map_start(read_size(byte - 0xa0)) when 0xbf Token::MapT.new + when 0xc0..0xdb + consume_tag(read_size(byte - 0xc0)) ################## when 0xf4 Token::BoolT.new(value: false) @@ -170,6 +172,11 @@ class CBOR::Lexer Token::MapT.new(size: size.to_i32) end + private def consume_tag(size) : Token::TagT + raise ParseError.new("Maximum size for tag exceeded") if size > UInt32::MAX + Token::TagT.new(id: size.to_u32) + end + # Creates a method overloaded for each UInt sizes to convert the UInt into # the respective Int capable of containing the value diff --git a/src/cbor/tag.cr b/src/cbor/tag.cr new file mode 100644 index 0000000..9e27977 --- /dev/null +++ b/src/cbor/tag.cr @@ -0,0 +1,21 @@ +module CBOR::Tag + enum Kind + Unassigned + RFC3339Time + EpochTime + PositiveBigNum + NegativeBigNum + DecimalFraction + BigFloat + ExpectBase64URLConversion + ExpectBase64Conversion + ExpectBase16Conversion + EncodedCBOR + URI + Base64URL + Base64 + RegularExpresion + MIME + SelfDescribeCBOR + end +end diff --git a/src/cbor/token.cr b/src/cbor/token.cr index 6c7bf29..5846e16 100644 --- a/src/cbor/token.cr +++ b/src/cbor/token.cr @@ -7,6 +7,7 @@ module CBOR::Token record StringT, value : String, chunks : Array(Int32)? = nil record ArrayT, size : Int32? = nil record MapT, size : Int32? = nil + record TagT, id : UInt32 alias T = NullT | BoolT | @@ -15,5 +16,6 @@ module CBOR::Token BytesT | StringT | ArrayT | - MapT + MapT | + TagT end