Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CBOR Overview

658c29959d8a9fd352afa440a5813137?s=47 ritou
March 19, 2018

CBOR Overview

658c29959d8a9fd352afa440a5813137?s=128

ritou

March 19, 2018
Tweet

Transcript

  1. CBOR Overview @ritou 2018/3

  2. Road to CWT 1. Concise Binary Object Representation (CBOR) 2.

    CBOR Object Signing and Encryption (COSE) 3. CBOR Web Token (CWT) 2
  3. What is CBOR? 3

  4. RFC 7049 The Concise Binary Object Representation (CBOR) is a

    data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. 4
  5. The objectives of CBOR 1. Unambiguous encoding of most common

    data formats 2. Code compactness for encoder or decoder 3. No schema description needed 4. Reasonably compact serialization 5. Applicability to constrained and unconstrained applications 6. Good JSON conversion 7. Extensibility 5
  6. Major Types • 0. Unsigned Integer • 1. Negative Integer

    • 2. Byte String • 3. Text String • 4. Array • 5. Map 6. Optional Tagging of Items 7. Floating-Point Numbers and Simple Values 6
  7. 0. Unsigned Integer 7 uint8 0:<<0>>, 23:<<23>>, 24:<<24, 24>>, 255:<<24,

    255>> uint16 256:<<25, 1, 0>>, 65535:<<25, 255, 255>> uint32 65536:<<26, 0, 1, 0, 0>>, 4294967295:<<26, 255, 255, 255, 255>> uint64 4294967296:<<27, 0, 0, 0, 1, 0, 0, 0, 0>> 18446744073709551615:<<27, 255, 255, 255, 255, 255, 255, 255, 255>>
  8. 1. Negative Integer 8 uint8 -1:<<32>>, -24:<<55>>, -25:<<56, 24>>, -256:<<56,

    255>> uint16 -257:<<57, 1, 0>>, -65536:<<57, 255, 255>> uint32 -65537:<<58, 0, 1, 0, 0>>, -4294967296:<<58, 255, 255, 255, 255>> uint64 -4294967297:<<59, 0, 0, 0, 1, 0, 0, 0, 0>> -18446744073709551616:<<59, 255, 255, 255, 255, 255, 255, 255, 255>>
  9. 2. Byte String 9 <<>>:<<64>>, <<255>>:<<65, 255>>, <<1, 0>>:<<66, 1,

    0>>, bytes(23):<<87>> <> bytes bytes(24):<<88, 24>> <> bytes, bytes(255):<<88, 255>> <> bytes bytes(256):<<89, 1, 0>> <> bytes, bytes(65535):<<89, 255, 255>> <> bytes
  10. 3. Text String 10 “”:<<96>>, bytes(23):<<119>> <> bytes bytes(24):<<120, 24>>

    <> bytes, bytes(255):<<120, 255>> <> bytes bytes(256):<<121, 1, 0>> <> bytes, bytes(65535):<<121, 255, 255>> <> bytes
  11. 4. Array 11 []:<<128>>, [0]:<<129, 0>>, [1, 2, 3 …

    23]:<<151, 1, 2, 3, … 23>> [1 … 24]:<<152, 24, 1 … 24, 24>>, [1 … 255]:<<152, 255, 1 … 24, 255>> [1 … 256]:<<153, 1, 0, 1 … 25, 1, 0>>, [1 … 65535]:<<153, 255, 255, 1 … 25, 255, 255>>
  12. 5. Map 12 %{}:<<160>>, %{0 => 0}:<<161, 0, 0>>, %{1

    => 1 … 23 => 23}:<<183, 1, 1 … 23, 23>> %{1 => 1 … 24 => 24}:<<184, 24, 1, 1 … 24, 24, 24, 24>> %{1 => 1 … 255 => 255}:<<184, 255, 1, 1 … 24, 255, 24, 255>>
  13. 6. Optional semantic tagging 13 timetext 0("2013-03-21T20:04:00Z"):<<192, 84, 50, 48,

    49, 51, 45, 48, 51, 45, 50, 49, 84, 50, 48, 58, 48, 52, 58, 48, 48, 90>> timeepoch 1(1363896240):<<193, 26, 81, 75, 103, 176>> Bignums 18446744073709551616:<<194, 73, 1, 0, 0, 0, 0, 0, 0, 0, 0>> -18446744073709551617:<<195, 73, 1, 0, 0, 0, 0, 0, 0, 0, 0>>
  14. 7. Floating-Point Numbers and Simple Values 14 Simple simple(0):<<224>>, simple(19):<<243>>,

    simple(255):<<248, 255>> Boolean false:<<244>>, true:<<245>>, Null Null:<<246>> Undefined Undefined:<<247>> Floating- point 0.0:<<249, 0, 0>>, -0.0:<<249, 128, 0>>, 1.0:<<249, 60, 0>> 100000.0:<<250, 71, 195, 80, 0>>, 3.4028234663852886e+38:<<250, 127, 127, 255, 255>>
  15. CBOR playground • http://cbor.me/ ◦ Object -> Base16 encoded binary

    ◦ Base16 encoded binary -> Object 15
  16. 16

  17. 17

  18. Libraries • http://cbor.io/impls.html 18

  19. CBOR vs JSON 19

  20. Size Comparison value CBOR(bytes) JSON(bytes) 0 1 1 23 1

    2 18446744073709551615 9 20 18446744073709551616 11 20 "12345678901234567890123" 24 25 "123456789012345678901234" 26 26 20
  21. Size Comparison value CBOR(bytes) JSON(bytes) [] 1 2 [1, 2,

    3, 4] 5 9 [“a”, “b”, “c”, “d”] 9 17 {} 1 2 {1:2, 3:4} 5 13 {“a”:”b”, “c”:”d”} 9 17 21
  22. Size Comparison value CBOR(bytes) JSON(bytes) h’01020304’ (hexed) 5 10(Base64 Encoded)

    32bytes binary 34 46(Base64 Encoded) 22
  23. Next CBOR Object Signing and Encryption(COSE) Overview 23