cbor-canonical 0.1.0

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
+ SHA1:
3
+ metadata.gz: 6373c6f0c54a80637fe4ad443a4a59fed8c26eb3
4
+ data.tar.gz: 930c8fe482a53f761603af7ecb7153377ecdc07a
5
+ SHA512:
6
+ metadata.gz: 08242d8d1c8d57c1ef12470e41cd08ad359567fd529a8fe16488bbae540d898d0fc5b3bed58de8b34cd406e0701d9393254accb48821586e0a60150e1277d9ad
7
+ data.tar.gz: 8ac5a29219b1624e059cfadcafcfda7b2179a3dbbb1e99247764b7859a7704b6aadc5d284ee527decec61cc49a81ad5aee8be87d0ea4f49df228be146172ecd9
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cbor-canonical"
3
+ s.version = "0.1.0"
4
+ s.summary = "CBOR (Concise Binary Object Representation) canonical encoding"
5
+ s.description = %q{cbor-canonical implements canonical encoding for CBOR, RFC 7049 Section 3.9}
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-canonical.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,41 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "cbor" unless defined? CBOR
4
+
5
+ module CBOR
6
+ module Canonical
7
+
8
+ module Object_Canonical_CBOR
9
+ def cbor_pre_canonicalize
10
+ self
11
+ end
12
+ def to_canonical_cbor
13
+ cbor_pre_canonicalize.to_cbor
14
+ end
15
+ end
16
+ Object.send(:include, Object_Canonical_CBOR)
17
+
18
+ module Array_Canonical_CBOR
19
+ def cbor_pre_canonicalize
20
+ map(&:cbor_pre_canonicalize)
21
+ end
22
+ end
23
+ Array.send(:include, Array_Canonical_CBOR)
24
+
25
+ module Hash_Canonical_CBOR
26
+ def cbor_pre_canonicalize
27
+ Hash[map {|k, v| cc = k.to_canonical_cbor
28
+ [cc.size, cc, k, v]}.
29
+ sort.map{|s, cc, k, v| [k, v]}]
30
+ end
31
+ end
32
+ Hash.send(:include, Hash_Canonical_CBOR)
33
+
34
+ module Tagged_Canonical_CBOR
35
+ def cbor_pre_canonicalize
36
+ CBOR::Tagged.new(tag, value.cbor_pre_canonicalize)
37
+ end
38
+ end
39
+ CBOR::Tagged.send(:include, Tagged_Canonical_CBOR)
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ require 'cbor-canonical'
2
+
3
+ [[1], [false], [10.3], [10.5], [Float::NAN],
4
+ [{a: 1, b: [1, 2]}],
5
+ [{aa: 1, b: 2}, {b: 2, aa: 1}],
6
+ [CBOR::Tagged.new(4711, {aa: 1, b: 2}),
7
+ CBOR::Tagged.new(4711, {b: 2, aa: 1})],
8
+ ].each do |ex1, ex2, ex3|
9
+ c1 = ex1.to_cbor
10
+ cc1 = ex1.to_canonical_cbor
11
+ # p cc1
12
+ if ex2.nil?
13
+ raise [:eq1, c1, cc1].inspect unless c1 == cc1
14
+ else
15
+ raise [:ne1, c1, cc1].inspect if c1 == cc1
16
+ c2 = ex2.to_cbor
17
+ raise [:eq2, cc1, c2].inspect unless cc1 == c2
18
+ cc2 = ex2.to_canonical_cbor
19
+ raise [:eq3, cc1, cc2].inspect unless cc1 == cc2
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cbor-canonical
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carsten Bormann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: cbor-canonical implements canonical encoding for CBOR, RFC 7049 Section
14
+ 3.9
15
+ email: cabo@tzi.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - cbor-canonical.gemspec
21
+ - lib/cbor-canonical.rb
22
+ - test/test-canonical.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
+ rubyforge_project:
43
+ rubygems_version: 2.6.7
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: CBOR (Concise Binary Object Representation) canonical encoding
47
+ test_files:
48
+ - test/test-canonical.rb