Compare commits
No commits in common. "b8ebc57bb7a7a26955c9204cac8031f93a4e5403" and "2d6fedf74978cf15069f8e674139a47697cc4729" have entirely different histories.
b8ebc57bb7
...
2d6fedf749
15 changed files with 46 additions and 148 deletions
22
CHANGELOG.md
22
CHANGELOG.md
|
|
@ -1,5 +1,4 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
|
@ -7,24 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [0.2.1] - 2020-09-29
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Bug when passing an `IO` to `to_cbor`
|
|
||||||
|
|
||||||
## [0.2.0] - 2020-06-18
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Upgraded to Crystal 0.35.0
|
|
||||||
|
|
||||||
## [0.1.1] - 2020-06-02
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Fix encoding of CBOR tags and as a consequence, the encoding of `Time`
|
|
||||||
|
|
||||||
## [0.1.0] - 2020-06-01
|
## [0.1.0] - 2020-06-01
|
||||||
|
|
||||||
- Initial Release
|
* Initial Release
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
name: cbor
|
name: cbor
|
||||||
version: 0.2.1
|
version: 0.1.0
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Alberto Restifo <alberto@restifo.dev>
|
- Alberto Restifo <alberto@restifo.dev>
|
||||||
|
|
||||||
description: "A CBOR library in pure Crystal, implementing RFC7049"
|
description: "A CBOR library in pure Crystal, impleming RFC7049"
|
||||||
|
|
||||||
crystal: 0.35.0
|
crystal: 0.34.0
|
||||||
|
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
||||||
repository: https://git.sr.ht/~arestifo/crystal-cbor
|
repository: https://git.sr.ht/~arestifo/crystal-cbor
|
||||||
homepage: https://sr.ht/~arestifo/crystal-cbor/
|
homepage: https://git.sr.ht/~arestifo/crystal-cbor
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ describe CBOR::Encoder do
|
||||||
bytes_arr = hex_string.split.map(&.to_u8(16))
|
bytes_arr = hex_string.split.map(&.to_u8(16))
|
||||||
want_bytes = Bytes.new(bytes_arr.to_unsafe, bytes_arr.size)
|
want_bytes = Bytes.new(bytes_arr.to_unsafe, bytes_arr.size)
|
||||||
|
|
||||||
it "encodes #{value} to #{want_bytes.hexstring}" do
|
it "econdes #{value.to_s} to #{want_bytes.hexstring}" do
|
||||||
res = IO::Memory.new
|
res = IO::Memory.new
|
||||||
|
|
||||||
encoder = CBOR::Encoder.new(res)
|
encoder = CBOR::Encoder.new(res)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ describe CBOR::Lexer do
|
||||||
]
|
]
|
||||||
|
|
||||||
tests.each do |tt|
|
tests.each do |tt|
|
||||||
it "reads #{tt[:bytes].hexstring} as #{tt[:value]}" do
|
it "reads #{tt[:bytes].hexstring} as #{tt[:value].to_s}" do
|
||||||
lexer = CBOR::Lexer.new(tt[:bytes])
|
lexer = CBOR::Lexer.new(tt[:bytes])
|
||||||
|
|
||||||
token = lexer.next_token
|
token = lexer.next_token
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ end
|
||||||
|
|
||||||
describe CBOR::Serializable do
|
describe CBOR::Serializable do
|
||||||
describe "rfc examples" do
|
describe "rfc examples" do
|
||||||
describe %(example {"a": 1, "b": [2, 3]}) do
|
describe %(example {_ "a": 1, "b": [_ 2, 3]}) do
|
||||||
it "decodes from cbor" do
|
it "decodes from cbor" do
|
||||||
result = ExampleA.from_cbor(Bytes[0xbf, 0x61, 0x61, 0x01, 0x61, 0x62, 0x9f, 0x02, 0x03, 0xff, 0xff])
|
result = ExampleA.from_cbor(Bytes[0xbf, 0x61, 0x61, 0x01, 0x61, 0x62, 0x9f, 0x02, 0x03, 0xff, 0xff])
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ describe CBOR::Serializable do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe %(example {"Fun": true, "Amt": -2}) do
|
describe %(example {_ "Fun": true, "Amt": -2}) do
|
||||||
it "decodes from cbor" do
|
it "decodes from cbor" do
|
||||||
result = ExampleB.from_cbor(Bytes[0xbf, 0x63, 0x46, 0x75, 0x6e, 0xf5, 0x63, 0x41, 0x6d, 0x74, 0x21, 0xff])
|
result = ExampleB.from_cbor(Bytes[0xbf, 0x63, 0x46, 0x75, 0x6e, 0xf5, 0x63, 0x41, 0x6d, 0x74, 0x21, 0xff])
|
||||||
|
|
||||||
|
|
@ -84,7 +84,7 @@ describe CBOR::Serializable do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe %(example ["a", {"b": "c"}]) do
|
describe %(example ["a", {_ "b": "c"}]) do
|
||||||
it "decodes from cbor" do
|
it "decodes from cbor" do
|
||||||
result = Array(String | ExampleC).from_cbor(Bytes[0x82, 0x61, 0x61, 0xbf, 0x61, 0x62, 0x61, 0x63, 0xff])
|
result = Array(String | ExampleC).from_cbor(Bytes[0x82, 0x61, 0x61, 0xbf, 0x61, 0x62, 0x61, 0x63, 0xff])
|
||||||
|
|
||||||
|
|
@ -137,7 +137,7 @@ describe CBOR::Serializable do
|
||||||
|
|
||||||
it "encodes to CBOR" do
|
it "encodes to CBOR" do
|
||||||
cbor = House.from_cbor(bytes).to_cbor
|
cbor = House.from_cbor(bytes).to_cbor
|
||||||
CBOR::Diagnostic.to_s(cbor).should eq(%({"address": "Crystal Road 1234", "location": {"lat": 12.3, "lng": 34.5}}))
|
CBOR::Diagnostic.to_s(cbor).should eq(%({_ "address": "Crystal Road 1234", "location": {_ "lat": 12.3, "lng": 34.5}}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -168,7 +168,7 @@ describe CBOR::Serializable do
|
||||||
it "encodes to CBOR" do
|
it "encodes to CBOR" do
|
||||||
cbor = Array(House).from_cbor(bytes).to_cbor
|
cbor = Array(House).from_cbor(bytes).to_cbor
|
||||||
|
|
||||||
CBOR::Diagnostic.to_s(cbor).should eq(%([{"address": "Crystal Road 1234", "location": {"lat": 12.3, "lng": 34.5}}]))
|
CBOR::Diagnostic.to_s(cbor).should eq(%([{_ "address": "Crystal Road 1234", "location": {_ "lat": 12.3, "lng": 34.5}}]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -185,7 +185,7 @@ describe CBOR::Serializable do
|
||||||
res.a.should eq(1)
|
res.a.should eq(1)
|
||||||
res.cbor_unmapped.should eq({"b" => 2})
|
res.cbor_unmapped.should eq({"b" => 2})
|
||||||
|
|
||||||
CBOR::Diagnostic.to_s(res.to_cbor).should eq(%({"a": 1, "b": 2}))
|
CBOR::Diagnostic.to_s(res.to_cbor).should eq(%({_ "a": 1, "b": 2}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ describe "to_cbor" do
|
||||||
tests.each do |tt|
|
tests.each do |tt|
|
||||||
type, bytes, value = tt
|
type, bytes, value = tt
|
||||||
|
|
||||||
it "encodes #{value.inspect} of type #{type}" do
|
it "encodes #{value.inspect} of type #{type.to_s}" do
|
||||||
res = value.to_cbor
|
res = value.to_cbor
|
||||||
res.hexdump.should eq(bytes.hexdump)
|
res.hexdump.should eq(bytes.hexdump)
|
||||||
end
|
end
|
||||||
|
|
@ -58,13 +58,4 @@ describe "to_cbor" do
|
||||||
encoder.to_slice.hexdump.should eq(Bytes[0xc1, 0x1a, 0x51, 0x4b, 0x67, 0xb0].hexdump)
|
encoder.to_slice.hexdump.should eq(Bytes[0xc1, 0x1a, 0x51, 0x4b, 0x67, 0xb0].hexdump)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "encodes to an IO" do
|
|
||||||
it "encodes a string" do
|
|
||||||
io = IO::Memory.new
|
|
||||||
"a".to_cbor(io)
|
|
||||||
|
|
||||||
io.to_slice.should eq(Bytes[0x61, 0x61])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,6 @@ class CBOR::Decoder
|
||||||
@lexer : Lexer
|
@lexer : Lexer
|
||||||
getter current_token : Token::T?
|
getter current_token : Token::T?
|
||||||
|
|
||||||
def reset
|
|
||||||
@lexer.reset
|
|
||||||
@current_token = @lexer.next_token
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
@lexer = Lexer.new(input)
|
@lexer = Lexer.new(input)
|
||||||
@current_token = @lexer.next_token
|
@current_token = @lexer.next_token
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# Reads a CBOR input into a diagnostic string.
|
# Reads a CBOR input into a diagnostic string.
|
||||||
# This consumes the IO and is mostly useful to tests again the example
|
# This consumes the IO and is mostly usedful to tests again the example
|
||||||
# provided in the RFC and ensuring a correct functioning of the `CBOR::Lexer`.
|
# provided in the RFC and ensuring a correct functioning of the `CBOR::Lexer`.
|
||||||
class CBOR::Diagnostic
|
class CBOR::Diagnostic
|
||||||
@lexer : Lexer
|
@lexer : Lexer
|
||||||
|
|
@ -63,7 +63,7 @@ class CBOR::Diagnostic
|
||||||
when Tag::NegativeBigNum
|
when Tag::NegativeBigNum
|
||||||
read_big_int(negative: true)
|
read_big_int(negative: true)
|
||||||
else
|
else
|
||||||
"#{token.value.value}(#{next_value})"
|
"#{token.value.value.to_s}(#{next_value})"
|
||||||
end
|
end
|
||||||
when Token::FloatT
|
when Token::FloatT
|
||||||
return "NaN" if token.value.nan?
|
return "NaN" if token.value.nan?
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class CBOR::Encoder
|
||||||
return write(value.to_u64) if value >= 0
|
return write(value.to_u64) if value >= 0
|
||||||
|
|
||||||
# When it's negative, transform it into a positive value and write the
|
# When it's negative, transform it into a positive value and write the
|
||||||
# resulting unsigned int with an offset
|
# resulting unsigled int with an offset
|
||||||
positive_value = -(value + 1)
|
positive_value = -(value + 1)
|
||||||
write(positive_value.to_u64, 0x20)
|
write(positive_value.to_u64, 0x20)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,6 @@ def Object.from_cbor(string_or_io)
|
||||||
new(parser)
|
new(parser)
|
||||||
end
|
end
|
||||||
|
|
||||||
def Object.from_cbor(parser : CBOR::Decoder)
|
|
||||||
new(parser)
|
|
||||||
end
|
|
||||||
|
|
||||||
def String.new(decoder : CBOR::Decoder)
|
def String.new(decoder : CBOR::Decoder)
|
||||||
decoder.read_string
|
decoder.read_string
|
||||||
end
|
end
|
||||||
|
|
@ -184,7 +180,7 @@ def BigInt.new(decoder : CBOR::Decoder)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reads the CBOR value as a BigDecimal.
|
# Reads the CBOR value as a BigDecimal.
|
||||||
# If the next token is a float, then it'll be transformed to a BigDecimal,
|
# If the next token is a flaot, then it'll be transformed to a BigDecimal,
|
||||||
# otherwhise the value must be correctly tagged with value 4 (decimal fraction)
|
# otherwhise the value must be correctly tagged with value 4 (decimal fraction)
|
||||||
# or 5 (big float).
|
# or 5 (big float).
|
||||||
def BigDecimal.new(decoder : CBOR::Decoder)
|
def BigDecimal.new(decoder : CBOR::Decoder)
|
||||||
|
|
@ -235,7 +231,7 @@ def Union.new(decoder : CBOR::Decoder)
|
||||||
return {{type}}.new(decoder)
|
return {{type}}.new(decoder)
|
||||||
{% end %}
|
{% end %}
|
||||||
else
|
else
|
||||||
# This case check is non-exhaustive on purpose
|
# This case check is non-exaustive on purpose
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,6 @@ class CBOR::Lexer
|
||||||
def initialize(@io : IO)
|
def initialize(@io : IO)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset
|
|
||||||
@io.seek 0
|
|
||||||
@eof = false
|
|
||||||
end
|
|
||||||
|
|
||||||
def next_token : Token::T?
|
def next_token : Token::T?
|
||||||
return nil if @eof
|
return nil if @eof
|
||||||
|
|
||||||
|
|
@ -169,7 +164,7 @@ class CBOR::Lexer
|
||||||
end
|
end
|
||||||
|
|
||||||
private def consume_simple_value(id) : Token::SimpleValueT
|
private def consume_simple_value(id) : Token::SimpleValueT
|
||||||
raise ParseError.new("Invalid simple value #{id}") if id > 255
|
raise ParseError.new("Invalid simple value #{id.to_s}") if id > 255
|
||||||
Token::SimpleValueT.new(value: SimpleValue.new(id.to_u8))
|
Token::SimpleValueT.new(value: SimpleValue.new(id.to_u8))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -181,7 +176,7 @@ class CBOR::Lexer
|
||||||
{% conv = %w(to_i8 to_i16 to_i32 to_i64 to_i128) %}
|
{% conv = %w(to_i8 to_i16 to_i32 to_i64 to_i128) %}
|
||||||
|
|
||||||
{% for uint, index in uints %}
|
{% for uint, index in uints %}
|
||||||
# Reads the `{{uint.id}}` as a negative integer, returning the smallest
|
# Reads the `{{uint.id}}` as a negative integer, returning the samllest
|
||||||
# integer capable of containing the value.
|
# integer capable of containing the value.
|
||||||
def to_negative_int(value : {{uint.id}})
|
def to_negative_int(value : {{uint.id}})
|
||||||
int = begin
|
int = begin
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ module CBOR
|
||||||
end
|
end
|
||||||
|
|
||||||
private def self.new_from_cbor_decoder(decoder : ::CBOR::Decoder)
|
private def self.new_from_cbor_decoder(decoder : ::CBOR::Decoder)
|
||||||
# puts "self.new_from_cbor_decoder"
|
|
||||||
instance = allocate
|
instance = allocate
|
||||||
instance.initialize(__decoder_for_cbor_serializable: decoder)
|
instance.initialize(__decoder_for_cbor_serializable: decoder)
|
||||||
GC.add_finalizer(instance) if instance.responds_to?(:finalize)
|
GC.add_finalizer(instance) if instance.responds_to?(:finalize)
|
||||||
|
|
@ -144,7 +143,7 @@ module CBOR
|
||||||
end
|
end
|
||||||
|
|
||||||
# When the type is inherited, carry over the `new`
|
# When the type is inherited, carry over the `new`
|
||||||
# so it can compete with other possible initializes
|
# so it can compete with other possible intializes
|
||||||
|
|
||||||
macro inherited
|
macro inherited
|
||||||
def self.new(decoder : ::CBOR::Decoder)
|
def self.new(decoder : ::CBOR::Decoder)
|
||||||
|
|
@ -244,10 +243,6 @@ module CBOR
|
||||||
raise ::CBOR::SerializationError.new("Unknown CBOR attribute: #{key}", self.class.to_s, nil)
|
raise ::CBOR::SerializationError.new("Unknown CBOR attribute: #{key}", self.class.to_s, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected def get_cbor_unmapped
|
|
||||||
{} of String => ::CBOR::Type
|
|
||||||
end
|
|
||||||
|
|
||||||
protected def on_to_cbor(cbor : ::CBOR::Encoder)
|
protected def on_to_cbor(cbor : ::CBOR::Encoder)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -273,28 +268,9 @@ module CBOR
|
||||||
{% end %}
|
{% end %}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
# Compute the size of the final list of properties to serialize.
|
cbor.object do
|
||||||
# This allows a more compact encoding, and a faster decoding.
|
|
||||||
nb_properties_to_serialize = 0
|
|
||||||
{% for name, value in properties %}
|
|
||||||
_{{name}} = @{{name}}
|
|
||||||
{% unless value[:emit_null] %}
|
|
||||||
unless _{{name}}.nil?
|
|
||||||
nb_properties_to_serialize += 1
|
|
||||||
end
|
|
||||||
{% else %}
|
|
||||||
nb_properties_to_serialize += 1
|
|
||||||
{% end %} # macro unless value[:emit_null]
|
|
||||||
{% end %} # macro for properties
|
|
||||||
|
|
||||||
nb_properties_to_serialize += get_cbor_unmapped.size
|
|
||||||
|
|
||||||
|
|
||||||
{% if properties.size > 0 %}
|
|
||||||
cbor.write_object_start nb_properties_to_serialize
|
|
||||||
|
|
||||||
{% for name, value in properties %}
|
{% for name, value in properties %}
|
||||||
_{{name}} = @{{name}}
|
_{{name}} = @{{name}}
|
||||||
|
|
||||||
{% unless value[:emit_null] %}
|
{% unless value[:emit_null] %}
|
||||||
unless _{{name}}.nil?
|
unless _{{name}}.nil?
|
||||||
|
|
@ -303,23 +279,23 @@ module CBOR
|
||||||
# Write the key of the map
|
# Write the key of the map
|
||||||
cbor.write({{value[:key]}})
|
cbor.write({{value[:key]}})
|
||||||
|
|
||||||
{% if value[:converter] %}
|
{% if value[:converter] %}
|
||||||
if _{{name}}
|
if _{{name}}
|
||||||
{{ value[:converter] }}.to_cbor(_{{name}}, cbor)
|
{{ value[:converter] }}.to_cbor(_{{name}}, cbor)
|
||||||
else
|
else
|
||||||
cbor.write(nil, use_undefined: value[:nil_as_undefined])
|
cbor.write(nil, use_undefined: value[:nil_as_undefined])
|
||||||
end
|
end
|
||||||
{% else %} # macro if value[:converter]
|
{% else %}
|
||||||
_{{name}}.to_cbor(cbor)
|
_{{name}}.to_cbor(cbor)
|
||||||
{% end %} # macro if value[:converter]
|
{% end %}
|
||||||
|
|
||||||
{% unless value[:emit_null] %}
|
{% unless value[:emit_null] %}
|
||||||
end # unless _{{name}}.nil?
|
end
|
||||||
{% end %} # macro unless value[:emit_null]
|
{% end %}
|
||||||
{% end %} # macro for properties
|
{% end %}
|
||||||
on_to_cbor(cbor)
|
on_to_cbor(cbor)
|
||||||
{% end %} # macro if properties.size > 0
|
end
|
||||||
{% end %} # begin
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
module Unmapped
|
module Unmapped
|
||||||
|
|
@ -334,10 +310,6 @@ module CBOR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected def get_cbor_unmapped
|
|
||||||
cbor_unmapped
|
|
||||||
end
|
|
||||||
|
|
||||||
protected def on_to_cbor(cbor : ::CBOR::Encoder)
|
protected def on_to_cbor(cbor : ::CBOR::Encoder)
|
||||||
cbor_unmapped.each do |key, value|
|
cbor_unmapped.each do |key, value|
|
||||||
cbor.write(key)
|
cbor.write(key)
|
||||||
|
|
@ -346,35 +318,6 @@ module CBOR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
macro use_cbor_discriminator(field, mapping)
|
|
||||||
{% unless mapping.is_a?(HashLiteral) || mapping.is_a?(NamedTupleLiteral) %}
|
|
||||||
{% mapping.raise "mapping argument must be a HashLiteral or a NamedTupleLiteral, not #{mapping.class_name.id}" %}
|
|
||||||
{% end %}
|
|
||||||
|
|
||||||
# SLOW. Read everything, get the type, read everything again.
|
|
||||||
def self.new(decoder : ::CBOR::Decoder)
|
|
||||||
if v = decoder.read_value
|
|
||||||
decoder.reset
|
|
||||||
case v
|
|
||||||
when Hash(CBOR::Type, CBOR::Type)
|
|
||||||
discriminator_value = v[{{field.id.stringify}}]?
|
|
||||||
case discriminator_value
|
|
||||||
{% for key, value in mapping %}
|
|
||||||
when {{key.id.stringify}}
|
|
||||||
return {{value.id}}.from_cbor(decoder)
|
|
||||||
{% end %}
|
|
||||||
else
|
|
||||||
raise "Unknown '{{field.id}}' discriminator value: #{discriminator_value.inspect}"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
raise "cannot get cbor discriminator #{ {{ field.id.stringify }} }"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
raise "cannot decode cbor value"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Tells this class to decode CBOR by using a field as a discriminator.
|
# Tells this class to decode CBOR by using a field as a discriminator.
|
||||||
#
|
#
|
||||||
# - *field* must be the field name to use as a discriminator
|
# - *field* must be the field name to use as a discriminator
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ enum CBOR::SimpleValue : UInt8
|
||||||
when Undefined
|
when Undefined
|
||||||
"undefined"
|
"undefined"
|
||||||
else
|
else
|
||||||
"simple(#{self.value})"
|
"simple(#{self.value.to_s})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ enum CBOR::Tag : UInt32
|
||||||
Decimal
|
Decimal
|
||||||
BigFloat
|
BigFloat
|
||||||
|
|
||||||
COSE_Encrypt0 = 16 # COSE Single Recipient Encrypted Data Object
|
CSOEEnCrypt = 16
|
||||||
COSE_Mac0 = 17 # COSE Mac w/o Recipients Object
|
CSOEMac
|
||||||
COSE_Sign1 = 18 # COSE Single Signer Data Object
|
CSOESign
|
||||||
|
|
||||||
ExpectBase64URL = 21
|
ExpectBase64URL = 21
|
||||||
ExpectBase64
|
ExpectBase64
|
||||||
|
|
@ -26,9 +26,5 @@ enum CBOR::Tag : UInt32
|
||||||
|
|
||||||
CBORWebToken = 61
|
CBORWebToken = 61
|
||||||
|
|
||||||
COSE_Encrypt = 96 # COSE Encrypted Data Object
|
|
||||||
COSE_Mac = 97 # COSE MACed Data Object
|
|
||||||
COSE_Sign = 98 # COSE Signed Data Object
|
|
||||||
|
|
||||||
SelfDescribeCBOR = 55799
|
SelfDescribeCBOR = 55799
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class Object
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_cbor(io : IO)
|
def to_cbor(io : IO)
|
||||||
encoder = CBOR::Encoder.new(io)
|
encoder = CBOR::Encoder.new
|
||||||
to_cbor(encoder)
|
to_cbor(encoder)
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
@ -79,7 +79,7 @@ module Time::Format::RFC_3339
|
||||||
end
|
end
|
||||||
|
|
||||||
module Time::EpochConverter
|
module Time::EpochConverter
|
||||||
# Emits the time as a tagged unix timestamp, as specified by
|
# Emits the time as a tagged unix timestamp, asp specified by
|
||||||
# [RFC 7049 section 2.4.1](https://tools.ietf.org/html/rfc7049#section-2.4.1).
|
# [RFC 7049 section 2.4.1](https://tools.ietf.org/html/rfc7049#section-2.4.1).
|
||||||
#
|
#
|
||||||
def self.to_cbor(value : Time, encoder : CBOR::Encoder)
|
def self.to_cbor(value : Time, encoder : CBOR::Encoder)
|
||||||
|
|
@ -108,7 +108,7 @@ struct Time
|
||||||
end
|
end
|
||||||
|
|
||||||
# struct BigInt
|
# struct BigInt
|
||||||
# # Encodes the value a bytes array tagged with the CBOR tag 2 or 3, as specified
|
# # Encodes the value a bytes arrya tagged with the CBOR tag 2 or 3, as specified
|
||||||
# # in [RFC 7049 Section 2.4.2](https://tools.ietf.org/html/rfc7049#section-2.4.2).
|
# # in [RFC 7049 Section 2.4.2](https://tools.ietf.org/html/rfc7049#section-2.4.2).
|
||||||
# def to_cbor(encoder : CBOR::Encoder)
|
# def to_cbor(encoder : CBOR::Encoder)
|
||||||
# encoded_value = BigInt.new(self)
|
# encoded_value = BigInt.new(self)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue