digest-crc 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +16 -0
- data/ChangeLog.md +6 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +1 -1
- data/README.md +4 -2
- data/Rakefile +11 -30
- data/benchmarks.rb +45 -0
- data/gemspec.yml +4 -6
- data/lib/digest/crc.rb +11 -3
- data/lib/digest/crc16_ccitt.rb +1 -1
- data/lib/digest/crc16_qt.rb +10 -8
- data/lib/digest/crc32.rb +1 -1
- data/lib/digest/crc32_mpeg.rb +1 -0
- data/lib/digest/crc5.rb +13 -0
- data/lib/digest/crc8_1wire.rb +1 -1
- data/spec/crc_examples.rb +3 -3
- data/spec/crc_spec.rb +21 -13
- data/spec/spec_helper.rb +0 -1
- metadata +17 -43
- data/.gemtest +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 965bc1999bc4bdcb3ea1ffa8eab25d428fc2682357732bdd2b9c86b0d7363a9a
|
4
|
+
data.tar.gz: 6deaae2d1bb8cd247ae74f4feea6d0cef835996066a50e5f5d8f24efb3d87a62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 715571c3f3ac67ec6b69879b09ecdfb3bb57813bf5f5b0f2266ff8109cffa4a186fa4058c5bedee86a84fecce8296a0d0349c0dcba63fd1958816e823e8c5669
|
7
|
+
data.tar.gz: 56f85ea3dc41925c9a496066790f6b11c891ea85eabcff566177cefa537c16bb417503a39a9b4561d61d596e0865d837b06bbbc79839c3c6d1859e4aa52cceb8
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.4.2 / 2020-03-01
|
2
|
+
|
3
|
+
* Corrected the logic in {Digest::CRC32#update}.
|
4
|
+
* Added missing {Digest::CRC5.pack} method.
|
5
|
+
* Fixed a require in `digest/crc8_1wire.rb`.
|
6
|
+
|
1
7
|
### 0.4.1 / 2014-04-16
|
2
8
|
|
3
9
|
* Allow Digest CRC classes to be extended and their constants overriden.
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Digest CRC
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/postmodern/digest-crc.svg?branch=master)](https://travis-ci.org/postmodern/digest-crc)
|
4
|
+
|
3
5
|
* [Source](https://github.com/postmodern/digest-crc)
|
4
6
|
* [Issues](https://github.com/postmodern/digest-crc/issues)
|
5
7
|
* [Documentation](http://rubydoc.info/gems/digest-crc/frames)
|
@@ -112,6 +114,6 @@ including their CRC Tables.
|
|
112
114
|
|
113
115
|
## License
|
114
116
|
|
115
|
-
Copyright (c) 2010-
|
117
|
+
Copyright (c) 2010-2020 Hal Brodigan
|
116
118
|
|
117
|
-
See
|
119
|
+
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -1,40 +1,21 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'rake'
|
3
2
|
|
4
3
|
begin
|
5
|
-
|
6
|
-
require 'rubygems/tasks'
|
7
|
-
|
8
|
-
Gem::Tasks.new
|
4
|
+
require 'bundler/setup'
|
9
5
|
rescue LoadError => e
|
10
|
-
|
11
|
-
warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
|
6
|
+
abort e.message
|
12
7
|
end
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
require 'rake'
|
10
|
+
require 'rubygems/tasks'
|
11
|
+
Gem::Tasks.new
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
task :spec do
|
21
|
-
puts e.message
|
22
|
-
end
|
23
|
-
end
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new
|
24
15
|
task :test => :spec
|
25
16
|
task :default => :spec
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
require 'yard'
|
32
|
-
require 'redcarpet'
|
33
|
-
require 'github-markup'
|
34
|
-
|
35
|
-
YARD::Rake::YardocTask.new
|
36
|
-
rescue LoadError => e
|
37
|
-
task :yard do
|
38
|
-
puts e.message
|
39
|
-
end
|
40
|
-
end
|
18
|
+
require 'yard'
|
19
|
+
require 'redcarpet'
|
20
|
+
require 'github-markup'
|
21
|
+
YARD::Rake::YardocTask.new
|
data/benchmarks.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'benchmark'
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('lib'))
|
4
|
+
|
5
|
+
CRCs = {
|
6
|
+
'crc1' => 'CRC1',
|
7
|
+
'crc5' => 'CRC5',
|
8
|
+
'crc8' => 'CRC8',
|
9
|
+
'crc8_1wire' => 'CRC81Wire',
|
10
|
+
'crc16' => 'CRC16',
|
11
|
+
'crc16_ccitt' => 'CRC16CCITT',
|
12
|
+
'crc16_dnp' => 'CRC16DNP',
|
13
|
+
'crc16_modbus' => 'CRC16Modbus',
|
14
|
+
'crc16_qt' => 'CRC16QT',
|
15
|
+
'crc16_usb' => 'CRC16USB',
|
16
|
+
'crc16_xmodem' => 'CRC16XModem',
|
17
|
+
'crc16_zmodem' => 'CRC16ZModem',
|
18
|
+
'crc24' => 'CRC24',
|
19
|
+
'crc32' => 'CRC32',
|
20
|
+
'crc32c' => 'CRC32c',
|
21
|
+
'crc32_mpeg' => 'CRC32Mpeg',
|
22
|
+
'crc64' => 'CRC64',
|
23
|
+
}
|
24
|
+
|
25
|
+
puts "Loading Digest::CRC classes ..."
|
26
|
+
CRCs.each_key { |crc| require "digest/#{crc}" }
|
27
|
+
|
28
|
+
puts "Generating random lengthed strings ..."
|
29
|
+
SAMPLES = Array.new(100) do
|
30
|
+
Array.new(100 * rand(1024)) { rand(256).chr }.join
|
31
|
+
end
|
32
|
+
|
33
|
+
puts "Benchmarking Digest::CRC classes ..."
|
34
|
+
Benchmark.bm do |b|
|
35
|
+
CRCs.each_value do |crc|
|
36
|
+
crc_class = Digest.const_get(crc)
|
37
|
+
crc = crc_class.new
|
38
|
+
|
39
|
+
b.report("#{crc_class}#update") do
|
40
|
+
SAMPLES.each do |sample|
|
41
|
+
crc.update(sample)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/gemspec.yml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
name: digest-crc
|
2
|
-
version: 0.4.
|
2
|
+
version: 0.4.2
|
3
3
|
summary: A Cyclic Redundancy Check (CRC) library for Ruby.
|
4
4
|
description:
|
5
|
-
Adds support for calculating Cyclic Redundancy Check (CRC) to the
|
6
|
-
|
5
|
+
Adds support for calculating Cyclic Redundancy Check (CRC) to the Digest
|
6
|
+
module.
|
7
7
|
|
8
8
|
license: MIT
|
9
9
|
authors: Postmodern
|
@@ -12,6 +12,4 @@ homepage: https://github.com/postmodern/digest-crc#readme
|
|
12
12
|
has_yard: true
|
13
13
|
|
14
14
|
development_dependencies:
|
15
|
-
|
16
|
-
rspec: ~> 2.4
|
17
|
-
yard: ~> 0.8
|
15
|
+
bundler: ~> 1.0
|
data/lib/digest/crc.rb
CHANGED
@@ -39,11 +39,16 @@ module Digest
|
|
39
39
|
#
|
40
40
|
# Packs the given CRC checksum.
|
41
41
|
#
|
42
|
+
# @param [Integer] crc
|
43
|
+
# The raw CRC checksum.
|
44
|
+
#
|
42
45
|
# @return [String]
|
43
46
|
# The packed CRC checksum.
|
44
47
|
#
|
48
|
+
# @abstract
|
49
|
+
#
|
45
50
|
def self.pack(crc)
|
46
|
-
|
51
|
+
raise(NotImplementedError,"#{self.class}##{__method__} not implemented")
|
47
52
|
end
|
48
53
|
|
49
54
|
#
|
@@ -83,11 +88,14 @@ module Digest
|
|
83
88
|
# @param [String] data
|
84
89
|
# The data to update the CRC checksum with.
|
85
90
|
#
|
91
|
+
# @abstract
|
92
|
+
#
|
86
93
|
def update(data)
|
94
|
+
raise(NotImplementedError,"#{self.class}##{__method__} not implemented")
|
87
95
|
end
|
88
96
|
|
89
97
|
#
|
90
|
-
# @see
|
98
|
+
# @see #update
|
91
99
|
#
|
92
100
|
def <<(data)
|
93
101
|
update(data)
|
@@ -117,7 +125,7 @@ module Digest
|
|
117
125
|
#
|
118
126
|
# Finishes the CRC checksum calculation.
|
119
127
|
#
|
120
|
-
# @see
|
128
|
+
# @see pack
|
121
129
|
#
|
122
130
|
def finish
|
123
131
|
self.class.pack(checksum)
|
data/lib/digest/crc16_ccitt.rb
CHANGED
@@ -8,7 +8,7 @@ module Digest
|
|
8
8
|
|
9
9
|
INIT_CRC = 0xffff
|
10
10
|
|
11
|
-
# Generated by `./pycrc.py --algorithm=table-driven --model=ccitt --generate=c`
|
11
|
+
# Generated by `./pycrc.py --algorithm=table-driven --model=crc-16-ccitt --generate=c`
|
12
12
|
TABLE = [
|
13
13
|
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
14
14
|
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
data/lib/digest/crc16_qt.rb
CHANGED
@@ -10,10 +10,7 @@ module Digest
|
|
10
10
|
|
11
11
|
FINAL_XOR = 0xffff
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
REVERSE_DATA = true
|
16
|
-
|
13
|
+
#
|
17
14
|
# Updates the CRC16 checksum.
|
18
15
|
#
|
19
16
|
# @param [String] data
|
@@ -21,17 +18,22 @@ module Digest
|
|
21
18
|
#
|
22
19
|
def update(data)
|
23
20
|
data.each_byte do |b|
|
24
|
-
b = revert_byte(b)
|
21
|
+
b = revert_byte(b)
|
25
22
|
@crc = ((@table[((@crc >> 8) ^ b) & 0xff] ^ (@crc << 8)) & 0xffff)
|
26
23
|
end
|
27
24
|
|
28
25
|
return self
|
29
26
|
end
|
30
27
|
|
28
|
+
#
|
29
|
+
# Calculates the CRC checksum value.
|
30
|
+
#
|
31
|
+
# @return [Integer]
|
32
|
+
#
|
31
33
|
def checksum
|
32
|
-
crc =
|
33
|
-
crc ^= FINAL_XOR
|
34
|
-
crc = revert_bits
|
34
|
+
crc = super
|
35
|
+
crc ^= FINAL_XOR
|
36
|
+
crc = revert_bits(crc)
|
35
37
|
return crc
|
36
38
|
end
|
37
39
|
|
data/lib/digest/crc32.rb
CHANGED
data/lib/digest/crc32_mpeg.rb
CHANGED
data/lib/digest/crc5.rb
CHANGED
@@ -43,6 +43,19 @@ module Digest
|
|
43
43
|
super
|
44
44
|
end
|
45
45
|
|
46
|
+
#
|
47
|
+
# Packs the CRC8 checksum.
|
48
|
+
#
|
49
|
+
# @param [Integer] crc
|
50
|
+
# The checksum to pack.
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
# The packed checksum.
|
54
|
+
#
|
55
|
+
def self.pack(crc)
|
56
|
+
(crc & CRC_MASK).chr
|
57
|
+
end
|
58
|
+
|
46
59
|
#
|
47
60
|
# Updates the CRC5 checksum.
|
48
61
|
#
|
data/lib/digest/crc8_1wire.rb
CHANGED
data/spec/crc_examples.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples_for "CRC" do
|
4
4
|
it "should calculate a checksum for text" do
|
5
|
-
described_class.hexdigest(string).
|
5
|
+
expect(described_class.hexdigest(string)).to be == expected
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should calculate a checksum for multiple data" do
|
@@ -15,13 +15,13 @@ shared_examples_for "CRC" do
|
|
15
15
|
crc << chunk1
|
16
16
|
crc << chunk2
|
17
17
|
|
18
|
-
crc.hexdigest.
|
18
|
+
expect(crc.hexdigest).to be == expected
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should provide direct access to the checksum value" do
|
22
22
|
crc = subject
|
23
23
|
crc << string
|
24
24
|
|
25
|
-
crc.checksum.
|
25
|
+
expect(crc.checksum).to be == expected.to_i(16)
|
26
26
|
end
|
27
27
|
end
|
data/spec/crc_spec.rb
CHANGED
@@ -2,14 +2,22 @@ require 'spec_helper'
|
|
2
2
|
require 'digest/crc'
|
3
3
|
|
4
4
|
describe Digest::CRC do
|
5
|
-
|
6
|
-
|
5
|
+
describe "#block_length" do
|
6
|
+
it { expect(subject.block_length).to be 1 }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".pack" do
|
10
|
+
subject { described_class }
|
7
11
|
|
8
|
-
|
12
|
+
it do
|
13
|
+
expect { subject.pack(0) }.to raise_error(NotImplementedError)
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
describe "#update" do
|
18
|
+
it do
|
19
|
+
expect { subject.update('') }.to raise_error(NotImplementedError)
|
20
|
+
end
|
13
21
|
end
|
14
22
|
|
15
23
|
context "when inherited" do
|
@@ -26,38 +34,38 @@ describe Digest::CRC do
|
|
26
34
|
end
|
27
35
|
|
28
36
|
it "should override WIDTH" do
|
29
|
-
subject::WIDTH.
|
37
|
+
expect(subject::WIDTH).not_to be described_class::WIDTH
|
30
38
|
end
|
31
39
|
|
32
40
|
it "should override INIT_CRC" do
|
33
|
-
subject::INIT_CRC.
|
41
|
+
expect(subject::INIT_CRC).not_to be described_class::INIT_CRC
|
34
42
|
end
|
35
43
|
|
36
44
|
it "should override XOR_MASK" do
|
37
|
-
subject::XOR_MASK.
|
45
|
+
expect(subject::XOR_MASK).not_to be described_class::XOR_MASK
|
38
46
|
end
|
39
47
|
|
40
48
|
it "should override TABLE" do
|
41
|
-
subject::TABLE.
|
49
|
+
expect(subject::TABLE).not_to be described_class::TABLE
|
42
50
|
end
|
43
51
|
|
44
52
|
describe "#initialize" do
|
45
53
|
let(:instance) { subject.new }
|
46
54
|
|
47
55
|
it "should initialize @init_crc" do
|
48
|
-
instance.instance_variable_get("@init_crc").
|
56
|
+
expect(instance.instance_variable_get("@init_crc")).to be subject::INIT_CRC
|
49
57
|
end
|
50
58
|
|
51
59
|
it "should initialize @xor_mask" do
|
52
|
-
instance.instance_variable_get("@xor_mask").
|
60
|
+
expect(instance.instance_variable_get("@xor_mask")).to be subject::XOR_MASK
|
53
61
|
end
|
54
62
|
|
55
63
|
it "should initialize @width" do
|
56
|
-
instance.instance_variable_get("@width").
|
64
|
+
expect(instance.instance_variable_get("@width")).to be subject::WIDTH
|
57
65
|
end
|
58
66
|
|
59
67
|
it "should initialize @table" do
|
60
|
-
instance.instance_variable_get("@table").
|
68
|
+
expect(instance.instance_variable_get("@table")).to be subject::TABLE
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digest-crc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '1.0'
|
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
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '2.4'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '2.4'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: yard
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.8'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.8'
|
26
|
+
version: '1.0'
|
55
27
|
description: Adds support for calculating Cyclic Redundancy Check (CRC) to the Digest
|
56
28
|
module.
|
57
29
|
email: postmodern.mod3@gmail.com
|
@@ -62,14 +34,16 @@ extra_rdoc_files:
|
|
62
34
|
- LICENSE.txt
|
63
35
|
- README.md
|
64
36
|
files:
|
65
|
-
- .
|
66
|
-
- .
|
67
|
-
- .
|
68
|
-
- .yardopts
|
37
|
+
- ".gitignore"
|
38
|
+
- ".rspec"
|
39
|
+
- ".travis.yml"
|
40
|
+
- ".yardopts"
|
69
41
|
- ChangeLog.md
|
42
|
+
- Gemfile
|
70
43
|
- LICENSE.txt
|
71
44
|
- README.md
|
72
45
|
- Rakefile
|
46
|
+
- benchmarks.rb
|
73
47
|
- digest-crc.gemspec
|
74
48
|
- gemspec.yml
|
75
49
|
- lib/digest/crc.rb
|
@@ -116,20 +90,20 @@ metadata: {}
|
|
116
90
|
post_install_message:
|
117
91
|
rdoc_options: []
|
118
92
|
require_paths:
|
93
|
+
- ext
|
119
94
|
- lib
|
120
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
96
|
requirements:
|
122
|
-
- -
|
97
|
+
- - ">="
|
123
98
|
- !ruby/object:Gem::Version
|
124
99
|
version: '0'
|
125
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
101
|
requirements:
|
127
|
-
- -
|
102
|
+
- - ">="
|
128
103
|
- !ruby/object:Gem::Version
|
129
104
|
version: '0'
|
130
105
|
requirements: []
|
131
|
-
|
132
|
-
rubygems_version: 2.0.14
|
106
|
+
rubygems_version: 3.0.3
|
133
107
|
signing_key:
|
134
108
|
specification_version: 4
|
135
109
|
summary: A Cyclic Redundancy Check (CRC) library for Ruby.
|
data/.gemtest
DELETED
File without changes
|