crc 0.3 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  #!ruby
2
2
 
3
3
  class CRC
4
- VERSION = "0.3"
4
+ VERSION = "0.4.2"
5
5
  end
@@ -0,0 +1,23 @@
1
+ #!ruby
2
+
3
+ require "test-unit"
4
+ require "crc"
5
+ require "optparse"
6
+
7
+ alltest = false
8
+ opt = OptionParser.new(nil, 12, " ")
9
+ opt.instance_eval do
10
+ on("--all", "test all crc models") { alltest = true }
11
+ order!
12
+ end
13
+
14
+ if alltest
15
+ $testmodels = CRC::MODEL_TABLE.values.uniq
16
+ else
17
+ $testmodels = %w(
18
+ CRC-32 CRC-32-POSIX CRC-64 CRC-64-ECMA
19
+ CRC-3-ROHC CRC-5-USB CRC-7-ROHC CRC-7-UMTS CRC-8-CCITT CRC-8-MAXIM
20
+ CRC-15 CRC-16 CRC-16-XMODEM CRC-24-OPENPGP CRC-24-BLE CRC-31-PHILIPS
21
+ ).map { |e| CRC[e] }
22
+ end
23
+
@@ -0,0 +1,31 @@
1
+ require "crc"
2
+
3
+ $stderr.puts "#{__FILE__}:#{__LINE__}: SELF CHECK for CRC models (#{File.basename($".grep(/_(?:byruby|turbo)/)[0]||"")})\n"
4
+
5
+ class CRC
6
+ MODEL_TABLE.values.uniq.each do |crc|
7
+ check = crc::CHECK
8
+ checked = crc.crc("123456789")
9
+ case check
10
+ when nil
11
+ $stderr.puts "| %20s(\"123456789\" * 1) = %16X (check only)\n" % [crc.name, checked]
12
+ when checked
13
+ ;
14
+ else
15
+ $stderr.puts "| %20s(\"123456789\" * 1) = %16X (expect to %X)\n" % [crc.name, checked, check]
16
+ end
17
+
18
+ check = 9.times.reduce(crc.new) { |a, x| a + crc.new(crc::CHECK, 9) }
19
+ checked = crc["123456789" * 9]
20
+ case check
21
+ when nil
22
+ $stderr.puts "| %20s(\"123456789\" * 9) = %16X (check only)\n" % [crc.name, checked]
23
+ when checked
24
+ ;
25
+ else
26
+ $stderr.puts "| %20s(\"123456789\" * 9) = %16X (expect to %X)\n" % [crc.name, checked, check]
27
+ end
28
+ end
29
+ end
30
+
31
+ $stderr.puts "#{__FILE__}:#{__LINE__}: DONE SELF CHECK\n"
@@ -0,0 +1,23 @@
1
+ #!ruby
2
+
3
+ require "test-unit"
4
+ require_relative "common"
5
+ require "crc"
6
+ require "crc/acrc"
7
+ require "securerandom"
8
+
9
+ class TestArcCRC < Test::Unit::TestCase
10
+ $testmodels.each do |crc|
11
+ class_eval(<<-"EOS", __FILE__, __LINE__ + 1)
12
+ def test_arc_#{crc.to_s.slice(/\w+$/)}
13
+ crc = #{crc}
14
+ [["", "", 12345],
15
+ ["123456789", nil, 1234567],
16
+ ["", "123456789", 123456789]].each do |a, b, t|
17
+ t &= crc.bitmask
18
+ assert_equal(t, crc.crc(a + crc.acrc(a, b, t) + (b || "")))
19
+ end
20
+ end
21
+ EOS
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ #!ruby
2
+
3
+ require "test-unit"
4
+ require "crc"
5
+ require_relative "common"
6
+
7
+ class TestCRC < Test::Unit::TestCase
8
+ $testmodels.each do |crc|
9
+ next unless crc.const_defined?(:CHECK) && crc::CHECK
10
+ class_eval(<<-"EOS", __FILE__, __LINE__ + 1)
11
+ def test_block_#{crc.to_s.slice(/\w+$/)}
12
+ assert_equal(#{crc}::CHECK, #{crc}.crc("123456789"))
13
+ end
14
+
15
+ def test_stream_#{crc.to_s.slice(/\w+$/)}
16
+ s = #{crc}.new
17
+ s << "123456789"
18
+ assert_equal(#{crc}::CHECK, s.crc)
19
+ end
20
+
21
+ def test_stream2_#{crc.to_s.slice(/\w+$/)}
22
+ s = #{crc}.new
23
+ "123456789".each_char { |ch| s << ch }
24
+ assert_equal(#{crc}::CHECK, s.crc)
25
+ end
26
+ EOS
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ #!ruby
2
+
3
+ require "test-unit"
4
+ require "crc"
5
+ require_relative "common"
6
+
7
+ class TestCRCMagic < Test::Unit::TestCase
8
+ $testmodels.each do |crc|
9
+ next unless crc.const_defined?(:CHECK) && crc::CHECK
10
+ name = crc.to_s.slice(/\w+$/)
11
+ class_eval(<<-"TESTCODE", __FILE__, __LINE__ + 1)
12
+ def test_magic_#{name}
13
+ assert_equal #{crc}.magic, #{crc}.hexdigest(#{crc}.magicdigest(""))
14
+ assert_equal #{crc}.magic, #{crc}.hexdigest("A" + #{crc}.magicdigest("A"))
15
+ assert_equal #{crc}.magic, #{crc}.hexdigest("A" * 100 + #{crc}.magicdigest("A" * 100))
16
+ end
17
+
18
+ def test_magicnumber_#{name}
19
+ assert_equal #{crc}.magicnumber, #{crc}.crc(#{crc}.magicdigest(""))
20
+ assert_equal #{crc}.magicnumber, #{crc}.crc("A" + #{crc}.magicdigest("A"))
21
+ assert_equal #{crc}.magicnumber, #{crc}.crc("A" * 100 + #{crc}.magicdigest("A" * 100))
22
+ end
23
+ TESTCODE
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crc
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dearblue
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-31 00:00:00.000000000 Z
11
+ date: 2020-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,54 +16,78 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '12'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '12'
27
27
  description: |
28
- This is a general CRC (Cyclic Redundancy Check) generator for ruby.
29
- It is written by pure ruby.
30
- Customization is posible for 1 to 64 bit width, any polynomial primitives, and with/without bit reflection input/output.
28
+ Pure ruby implemented generic CRC (Cyclic Redundancy Check) calculator.
29
+ Customization is posible for 1 to 64 bit width, any polynomials, and with/without bit reflection input/output.
31
30
  If you need more speed, please use crc-turbo.
32
- email: dearblue@users.osdn.me
33
- executables: []
31
+ email: dearblue@users.noreply.github.com
32
+ executables:
33
+ - rbcrc
34
+ - rbcrc.orig
34
35
  extensions: []
35
36
  extra_rdoc_files:
36
37
  - HISTORY.ja.md
37
38
  - LICENSE
39
+ - README.ja.md
38
40
  - README.md
39
41
  - lib/crc.rb
42
+ - lib/crc/_aux.rb
40
43
  - lib/crc/_byruby.rb
41
44
  - lib/crc/_combine.rb
42
- - lib/crc/_modules.rb
45
+ - lib/crc/_extensions.rb
46
+ - lib/crc/_file.rb
47
+ - lib/crc/_magic.rb
48
+ - lib/crc/_models.rb
49
+ - lib/crc/_shift.rb
50
+ - lib/crc/_utils.rb
43
51
  - lib/crc/acrc.rb
52
+ - lib/crc/codegen.rb
44
53
  - lib/crc/finder.rb
45
54
  - lib/crc/version.rb
46
55
  files:
47
56
  - HISTORY.ja.md
48
57
  - LICENSE
58
+ - README.ja.md
49
59
  - README.md
50
60
  - Rakefile
51
61
  - benchmark.rb
62
+ - bin/rbcrc
63
+ - bin/rbcrc.orig
52
64
  - gemstub.rb
53
65
  - lib/crc.rb
66
+ - lib/crc/_aux.rb
54
67
  - lib/crc/_byruby.rb
55
68
  - lib/crc/_combine.rb
56
- - lib/crc/_modules.rb
69
+ - lib/crc/_extensions.rb
70
+ - lib/crc/_file.rb
71
+ - lib/crc/_magic.rb
72
+ - lib/crc/_models.rb
73
+ - lib/crc/_shift.rb
74
+ - lib/crc/_utils.rb
57
75
  - lib/crc/acrc.rb
76
+ - lib/crc/codegen.rb
58
77
  - lib/crc/finder.rb
59
78
  - lib/crc/version.rb
60
- homepage: https://osdn.jp/projects/rutsubo/
79
+ - test/common.rb
80
+ - test/self_check.rb
81
+ - test/test_arc.rb
82
+ - test/test_block.rb
83
+ - test/test_magic.rb
84
+ homepage: https://github.com/dearblue/ruby-crc
61
85
  licenses:
62
86
  - BSD-2-Clause
63
87
  - Zlib
64
88
  - CC0-1.0
65
89
  metadata: {}
66
- post_install_message:
90
+ post_install_message:
67
91
  rdoc_options:
68
92
  - "--charset"
69
93
  - UTF-8
@@ -75,16 +99,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
99
  requirements:
76
100
  - - ">="
77
101
  - !ruby/object:Gem::Version
78
- version: '2.0'
102
+ version: '2.2'
79
103
  required_rubygems_version: !ruby/object:Gem::Requirement
80
104
  requirements:
81
105
  - - ">="
82
106
  - !ruby/object:Gem::Version
83
107
  version: '0'
84
108
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.6.4
87
- signing_key:
109
+ rubygems_version: 3.0.6
110
+ signing_key:
88
111
  specification_version: 4
89
- summary: general CRC generator
112
+ summary: generic CRC calculator
90
113
  test_files: []