cbor-deterministic 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8bab53925e925691a37509249a3119bb19b1b25fef664a69e307ab83e7a81c1
4
+ data.tar.gz: 9602e855db2ebafb94171595ad5c3108595723968f01d9c1a7a8bae4145ea2a4
5
+ SHA512:
6
+ metadata.gz: af750d061c49f527ba24f830e44cf300c18a2bf35ef2516bec3d87ed051dfebe5ca17b4a6adcad5b106c4f2e97ae7a357a6b8fc00fc335fea201ebde1d3cabf8
7
+ data.tar.gz: 6f2d971e10ff3b275d416f715e0c337c1a11c3a172f15e6f218a7fa41ba67b6d0cfe86431b75b45297ebfc8c3854bd7a957ff5581120409e65427bb78004817c
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cbor-deterministic"
3
+ s.version = "0.1.2"
4
+ s.summary = "CBOR (Concise Binary Object Representation) deterministic encoding"
5
+ s.description = %q{cbor-deterministic implements deterministic encoding for CBOR, RFC 8949 Section 4.2}
6
+ s.author = "Carsten Bormann"
7
+ s.email = "cabo@tzi.org"
8
+ s.license = "Apache-2.0"
9
+ s.homepage = "http://cbor.io/"
10
+ s.has_rdoc = false
11
+ s.test_files = Dir['test/**/*.rb']
12
+ s.files = Dir['lib/**/*.rb'] + %w(cbor-deterministic.gemspec) + Dir['bin/**/*.rb']
13
+ s.executables = Dir['bin/**/*.rb'].map {|x| File.basename(x)}
14
+ s.required_ruby_version = '>= 1.9.2'
15
+
16
+ s.require_paths = ["lib"]
17
+ end
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "cbor" unless defined? CBOR
4
+
5
+ module CBOR
6
+ module Deterministic
7
+
8
+ module Object_Deterministic_CBOR
9
+ def cbor_prepare_deterministic
10
+ self
11
+ end
12
+ def to_deterministic_cbor
13
+ cbor_prepare_deterministic.to_cbor
14
+ end
15
+ end
16
+ Object.send(:include, Object_Deterministic_CBOR)
17
+
18
+ module Array_Deterministic_CBOR
19
+ def cbor_prepare_deterministic
20
+ map(&:cbor_prepare_deterministic)
21
+ end
22
+ end
23
+ Array.send(:include, Array_Deterministic_CBOR)
24
+
25
+ module Hash_Deterministic_CBOR
26
+ def cbor_prepare_deterministic
27
+ Hash[map {|k, v|
28
+ k = k.cbor_prepare_deterministic
29
+ v = v.cbor_prepare_deterministic
30
+ cc = k.to_cbor # already prepared
31
+ [cc, k, v]}.
32
+ sort.map{|cc, k, v| [k, v]}]
33
+ end
34
+ end
35
+ Hash.send(:include, Hash_Deterministic_CBOR)
36
+
37
+ module Tagged_Deterministic_CBOR
38
+ def cbor_prepare_deterministic
39
+ CBOR::Tagged.new(tag, value.cbor_prepare_deterministic)
40
+ end
41
+ end
42
+ CBOR::Tagged.send(:include, Tagged_Deterministic_CBOR)
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ require 'cbor-deterministic'
2
+
3
+ [[1], [false], [10.3], [10.5], [Float::NAN],
4
+ [{a: 1, b: [1, 2]}],
5
+ [{[] => 1, bb: 2}, {bb: 2, [] => 1}],
6
+ [{b: {mm: 2, m: 3}, "b".b => 1}, {"b".b => 1, b: {m: 3, mm: 2}}],
7
+ [CBOR::Tagged.new(4711, {aa: 1, b: 2}),
8
+ CBOR::Tagged.new(4711, {b: 2, aa: 1})],
9
+ ].each do |ex1, ex2, ex3|
10
+ c1 = ex1.to_cbor
11
+ cc1 = ex1.to_deterministic_cbor
12
+ # p cc1
13
+ if ex2.nil?
14
+ raise [:eq1, c1, cc1].inspect unless c1 == cc1
15
+ else
16
+ raise [:ne1, c1, cc1].inspect if c1 == cc1
17
+ c2 = ex2.to_cbor
18
+ raise [:eq2, cc1, c2].inspect unless cc1 == c2
19
+ cc2 = ex2.to_deterministic_cbor
20
+ raise [:eq3, cc1, cc2].inspect unless cc1 == cc2
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cbor-deterministic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Carsten Bormann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: cbor-deterministic implements deterministic encoding for CBOR, RFC 8949
14
+ Section 4.2
15
+ email: cabo@tzi.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - cbor-deterministic.gemspec
21
+ - lib/cbor-deterministic.rb
22
+ - test/test-deterministic.rb
23
+ homepage: http://cbor.io/
24
+ licenses:
25
+ - Apache-2.0
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.9.2
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.2.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: CBOR (Concise Binary Object Representation) deterministic encoding
46
+ test_files:
47
+ - test/test-deterministic.rb