Slide 1

Slide 1 text

CBOR Overview @ritou 2018/3

Slide 2

Slide 2 text

Road to CWT 1. Concise Binary Object Representation (CBOR) 2. CBOR Object Signing and Encryption (COSE) 3. CBOR Web Token (CWT) 2

Slide 3

Slide 3 text

What is CBOR? 3

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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>>

Slide 8

Slide 8 text

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>>

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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>>

Slide 12

Slide 12 text

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>>

Slide 13

Slide 13 text

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>>

Slide 14

Slide 14 text

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>>

Slide 15

Slide 15 text

CBOR playground ● http://cbor.me/ ○ Object -> Base16 encoded binary ○ Base16 encoded binary -> Object 15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

CBOR vs JSON 19

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Size Comparison value CBOR(bytes) JSON(bytes) h’01020304’ (hexed) 5 10(Base64 Encoded) 32bytes binary 34 46(Base64 Encoded) 22

Slide 23

Slide 23 text

Next CBOR Object Signing and Encryption(COSE) Overview 23