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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5090c17bdfb58a94270e81bab8753095324379c5
4
- data.tar.gz: ec891e2886a61cd48e28f2a119ebb48bd01f68b7
2
+ SHA256:
3
+ metadata.gz: 965bc1999bc4bdcb3ea1ffa8eab25d428fc2682357732bdd2b9c86b0d7363a9a
4
+ data.tar.gz: 6deaae2d1bb8cd247ae74f4feea6d0cef835996066a50e5f5d8f24efb3d87a62
5
5
  SHA512:
6
- metadata.gz: 5539def533acad46a8a1ac25c602bee61832c9912598975884c25388e369658ce59245f6160ef1341b216a8b3e6aceb59c23f9b8b1e62dece990dad3ac3d2742
7
- data.tar.gz: bf09d57ef56303bd70d0df44fa20a1e2d2fd107bf052fa31ba6191a827cbaa81659eb7aa2fb795f694f0f036abd653b425cd60388106df30275aadb343eaeded
6
+ metadata.gz: 715571c3f3ac67ec6b69879b09ecdfb3bb57813bf5f5b0f2266ff8109cffa4a186fa4058c5bedee86a84fecce8296a0d0349c0dcba63fd1958816e823e8c5669
7
+ data.tar.gz: 56f85ea3dc41925c9a496066790f6b11c891ea85eabcff566177cefa537c16bb417503a39a9b4561d61d596e0865d837b06bbbc79839c3c6d1859e4aa52cceb8
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ Gemfile.lock
1
2
  doc
2
3
  pkg
3
4
  .bundle
@@ -0,0 +1,16 @@
1
+ ---
2
+ before_install:
3
+ - gem update --system
4
+ - gem install bundler -v "~> 2.0"
5
+ language: ruby
6
+ sudo: false
7
+ cache:
8
+ - bundler
9
+ rvm:
10
+ - 2.5
11
+ - 2.6
12
+ - jruby
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby
16
+ script: bundle exec rake spec
@@ -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
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+
9
+ gem 'rspec', '~> 3.0'
10
+
11
+ gem 'yard', '~> 0.9'
12
+ gem 'redcarpet', '~> 3.1'
13
+ gem 'github-markup', '~> 1.1'
14
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2014 Hal Brodigan
1
+ Copyright (c) 2010-2020 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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-2014 Hal Brodigan
117
+ Copyright (c) 2010-2020 Hal Brodigan
116
118
 
117
- See [LICENSE.txt](LICENSE.txt) for license information.
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
- gem 'rubygems-tasks', '~> 0.1'
6
- require 'rubygems/tasks'
7
-
8
- Gem::Tasks.new
4
+ require 'bundler/setup'
9
5
  rescue LoadError => e
10
- warn e.message
11
- warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
6
+ abort e.message
12
7
  end
13
8
 
14
- begin
15
- gem 'rspec', '~> 2.4'
16
- require 'rspec/core/rake_task'
9
+ require 'rake'
10
+ require 'rubygems/tasks'
11
+ Gem::Tasks.new
17
12
 
18
- RSpec::Core::RakeTask.new
19
- rescue LoadError => e
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
- begin
28
- gem 'yard', '~> 0.8'
29
- gem 'redcarpet'
30
- gem 'github-markup'
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
@@ -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
@@ -1,9 +1,9 @@
1
1
  name: digest-crc
2
- version: 0.4.1
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
- Digest module.
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
- rubygems-tasks: ~> 0.2
16
- rspec: ~> 2.4
17
- yard: ~> 0.8
15
+ bundler: ~> 1.0
@@ -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 {#update}
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 {pack}
128
+ # @see pack
121
129
  #
122
130
  def finish
123
131
  self.class.pack(checksum)
@@ -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,
@@ -10,10 +10,7 @@ module Digest
10
10
 
11
11
  FINAL_XOR = 0xffff
12
12
 
13
- REVERSE_CRC_RESULT = true
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) if REVERSE_DATA
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 = @crc + 0
33
- crc ^= FINAL_XOR if FINAL_XOR
34
- crc = revert_bits crc if REVERSE_CRC_RESULT
34
+ crc = super
35
+ crc ^= FINAL_XOR
36
+ crc = revert_bits(crc)
35
37
  return crc
36
38
  end
37
39
 
@@ -108,7 +108,7 @@ module Digest
108
108
  #
109
109
  def update(data)
110
110
  data.each_byte do |b|
111
- @crc = (((@crc >> 8) & 0x00ffffff) ^ @table[(@crc ^ b) & 0xff])
111
+ @crc = @table[(@crc ^ b) & 0xff] ^ ((@crc >> 8) & 0xffffffff)
112
112
  end
113
113
 
114
114
  return self
@@ -8,6 +8,7 @@ module Digest
8
8
 
9
9
  XOR_MASK = 0x00000000
10
10
 
11
+ # Generated by `./pycrc.py --algorithm=table-driven --model=crc-32-mpeg --generate=c`
11
12
  TABLE = [
12
13
  0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
13
14
  0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
@@ -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
  #
@@ -1,4 +1,4 @@
1
- require 'digest/crc'
1
+ require 'digest/crc8'
2
2
 
3
3
  module Digest
4
4
  #
@@ -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).should == expected
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.should == expected
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.should == expected.to_i(16)
25
+ expect(crc.checksum).to be == expected.to_i(16)
26
26
  end
27
27
  end
@@ -2,14 +2,22 @@ require 'spec_helper'
2
2
  require 'digest/crc'
3
3
 
4
4
  describe Digest::CRC do
5
- it "should define block_length of 1" do
6
- crc = subject
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
- crc.block_length.should == 1
12
+ it do
13
+ expect { subject.pack(0) }.to raise_error(NotImplementedError)
14
+ end
9
15
  end
10
16
 
11
- it "should pack to an empty String by default" do
12
- described_class.pack(0).should be_empty
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.should_not == described_class::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.should_not == described_class::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.should_not == described_class::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.should_not == described_class::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").should == subject::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").should == subject::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").should == subject::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").should == subject::TABLE
68
+ expect(instance.instance_variable_get("@table")).to be subject::TABLE
61
69
  end
62
70
  end
63
71
  end
@@ -1,2 +1 @@
1
- gem 'rspec', '~> 2.4'
2
1
  require 'rspec'
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.1
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: 2014-04-17 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubygems-tasks
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
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.2'
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
- - .gemtest
66
- - .gitignore
67
- - .rspec
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
- rubyforge_project:
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