Skip to content

cbor-deterministic implements deterministic encoding for CBOR, RFC 8949 Section 4.2

Notifications You must be signed in to change notification settings

cabo/cbor-deterministic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cbor-deterministic gem

Use with the cbor gem (or with cbor-pure, which is a part of the cbor-diag gem) to add a to_deterministic_cbor method on objects. Requires to_cbor to already be mostly deterministic (as it is for the above two CBOR implementations), just adds deterministic ordering of maps for completeness.

Note that this implements deterministic encoding as in Section 4.2 of RFC 8949. An earlier variant of this, Length-First Map Key Ordering, was previously called "canonical encoding" (Section 3.9 of RFC 7049) and is still available as the analogously shaped cbor-canonical gem.

require 'cbor-deterministic'

ex1 = {[]=> 1, aa: 2}

p CBOR.decode(ex1.to_cbor)
# {[]=>1, "aa"=>2}

p CBOR.decode(ex1.to_deterministic_cbor)
# {"aa"=>2, []=>1}

About

cbor-deterministic implements deterministic encoding for CBOR, RFC 8949 Section 4.2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages