digest-crc 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/integration.yml +1 -1
  3. data/.github/workflows/ruby.yml +3 -3
  4. data/ChangeLog.md +6 -0
  5. data/LICENSE.txt +1 -1
  6. data/README.md +5 -10
  7. data/benchmarks.rb +1 -0
  8. data/digest-crc.gemspec +8 -4
  9. data/ext/digest/crc64_nvme/crc64_nvme.c +102 -0
  10. data/ext/digest/crc64_nvme/crc64_nvme.h +8 -0
  11. data/ext/digest/crc64_nvme/crc64_nvme_ext.c +31 -0
  12. data/ext/digest/crc64_nvme/extconf.rb +7 -0
  13. data/gemspec.yml +1 -1
  14. data/lib/digest/crc.rb +85 -9
  15. data/lib/digest/crc1.rb +2 -0
  16. data/lib/digest/crc15.rb +2 -32
  17. data/lib/digest/crc16.rb +2 -32
  18. data/lib/digest/crc16_ccitt.rb +2 -14
  19. data/lib/digest/crc16_dnp.rb +2 -14
  20. data/lib/digest/crc16_genibus.rb +2 -14
  21. data/lib/digest/crc16_kermit.rb +2 -14
  22. data/lib/digest/crc16_x_25.rb +3 -1
  23. data/lib/digest/crc16_xmodem.rb +2 -14
  24. data/lib/digest/crc16_zmodem.rb +2 -14
  25. data/lib/digest/crc24.rb +2 -33
  26. data/lib/digest/crc32.rb +2 -34
  27. data/lib/digest/crc32_bzip2.rb +2 -14
  28. data/lib/digest/crc32_mpeg.rb +2 -14
  29. data/lib/digest/crc32_posix.rb +2 -14
  30. data/lib/digest/crc32_xfer.rb +2 -14
  31. data/lib/digest/crc5.rb +2 -27
  32. data/lib/digest/crc64.rb +2 -38
  33. data/lib/digest/crc64_nvme.rb +90 -0
  34. data/lib/digest/crc8.rb +2 -27
  35. metadata +8 -36
  36. data/spec/crc15_spec.rb +0 -10
  37. data/spec/crc16_ccitt_spec.rb +0 -10
  38. data/spec/crc16_genibus_spec.rb +0 -10
  39. data/spec/crc16_kermit_spec.rb +0 -10
  40. data/spec/crc16_modbus_spec.rb +0 -10
  41. data/spec/crc16_qt_spec.rb +0 -10
  42. data/spec/crc16_spec.rb +0 -10
  43. data/spec/crc16_usb_spec.rb +0 -10
  44. data/spec/crc16_x_25_spec.rb +0 -10
  45. data/spec/crc16_xmodem_spec.rb +0 -10
  46. data/spec/crc16_zmodem_spec.rb +0 -10
  47. data/spec/crc1_spec.rb +0 -10
  48. data/spec/crc24_spec.rb +0 -10
  49. data/spec/crc32_bzip2_spec.rb +0 -10
  50. data/spec/crc32_jam_spec.rb +0 -10
  51. data/spec/crc32_mpeg_spec.rb +0 -16
  52. data/spec/crc32_posix_spec.rb +0 -10
  53. data/spec/crc32_spec.rb +0 -10
  54. data/spec/crc32_xfer_spec.rb +0 -10
  55. data/spec/crc32c_spec.rb +0 -10
  56. data/spec/crc5_spec.rb +0 -10
  57. data/spec/crc64_jones_spec.rb +0 -10
  58. data/spec/crc64_spec.rb +0 -10
  59. data/spec/crc64_xz_spec.rb +0 -10
  60. data/spec/crc8_1wire_spec.rb +0 -16
  61. data/spec/crc8_spec.rb +0 -10
  62. data/spec/crc_examples.rb +0 -37
  63. data/spec/crc_spec.rb +0 -72
  64. data/spec/integration/docker/Dockerfile.base +0 -9
  65. data/spec/integration/docker/Dockerfile.with-gcc +0 -3
  66. data/spec/integration/docker/Dockerfile.with-gcc-and-make +0 -3
  67. data/spec/integration/install_spec.rb +0 -59
  68. data/spec/spec_helper.rb +0 -3
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc16_x_25'
4
-
5
- describe Digest::CRC16X25 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '4b13' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc16_xmodem'
4
-
5
- describe Digest::CRC16XModem do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'd321' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc16_zmodem'
4
-
5
- describe Digest::CRC16ZModem do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'd321' }
8
-
9
- it_should_behave_like "CRC"
10
- end
data/spec/crc1_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc1'
4
-
5
- describe Digest::CRC1 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '0d' }
8
-
9
- it_should_behave_like "CRC"
10
- end
data/spec/crc24_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc24'
4
-
5
- describe Digest::CRC24 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '8c0072' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc32_bzip2'
4
-
5
- describe Digest::CRC32BZip2 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '506853b6' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc32_jam'
4
-
5
- describe Digest::CRC32Jam do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'd9e2511a' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc32_mpeg'
4
-
5
- describe Digest::CRC32MPEG do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'af97ac49' }
8
-
9
- it_should_behave_like "CRC"
10
- end
11
-
12
- describe "Digest::CRC32Mpeg" do
13
- subject { Digest::CRC32Mpeg }
14
-
15
- it { expect(subject).to eq(Digest::CRC32MPEG) }
16
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc32_posix'
4
-
5
- describe Digest::CRC32POSIX do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'c181fd8e' }
8
-
9
- it_should_behave_like "CRC"
10
- end
data/spec/crc32_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc32'
4
-
5
- describe Digest::CRC32 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '261daee5' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc32_xfer'
4
-
5
- describe Digest::CRC32XFER do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '0be368eb' }
8
-
9
- it_should_behave_like "CRC"
10
- end
data/spec/crc32c_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc32c'
4
-
5
- describe Digest::CRC32c do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'f3dbd4fe' }
8
-
9
- it_should_behave_like "CRC"
10
- end
data/spec/crc5_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc5'
4
-
5
- describe Digest::CRC5 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '01' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc64_jones'
4
-
5
- describe Digest::CRC64Jones do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '68a745ba133af9bd' }
8
-
9
- it_should_behave_like "CRC"
10
- end
data/spec/crc64_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc64'
4
-
5
- describe Digest::CRC64 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'bc66a5a9388a5bef' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc64_xz'
4
-
5
- describe Digest::CRC64XZ do
6
- let(:string) { '1234567890' }
7
- let(:expected) { 'b1cb31bbb4a2b2be' }
8
-
9
- it_should_behave_like "CRC"
10
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc8_1wire'
4
-
5
- describe Digest::CRC8_1Wire do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '4f' }
8
-
9
- it_should_behave_like "CRC"
10
- end
11
-
12
- describe "Digest::CRC81Wire" do
13
- subject { Digest::CRC81Wire }
14
-
15
- it { expect(subject).to eq(Digest::CRC8_1Wire) }
16
- end
data/spec/crc8_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'crc_examples'
3
- require 'digest/crc8'
4
-
5
- describe Digest::CRC8 do
6
- let(:string) { '1234567890' }
7
- let(:expected) { '52' }
8
-
9
- it_should_behave_like "CRC"
10
- end
data/spec/crc_examples.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for "CRC" do
4
- it "should calculate a checksum for text" do
5
- expect(described_class.hexdigest(string)).to be == expected
6
- end
7
-
8
- it "should calculate a checksum for multiple data" do
9
- middle = (string.length / 2)
10
-
11
- chunk1 = string[0...middle]
12
- chunk2 = string[middle..-1]
13
-
14
- crc = subject
15
- crc << chunk1
16
- crc << chunk2
17
-
18
- expect(crc.hexdigest).to be == expected
19
- end
20
-
21
- it "should provide direct access to the checksum value" do
22
- crc = subject
23
- crc << string
24
-
25
- expect(crc.checksum).to be == expected.to_i(16)
26
- end
27
-
28
- if defined?(Ractor)
29
- it "should calculate CRC inside ractor" do
30
- digest = Ractor.new(described_class, string) do |klass, string|
31
- klass.hexdigest(string)
32
- end.take
33
-
34
- expect(digest).to eq expected
35
- end
36
- end
37
- end
data/spec/crc_spec.rb DELETED
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
- require 'digest/crc'
3
-
4
- describe Digest::CRC do
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 }
11
-
12
- it do
13
- expect { subject.pack(0) }.to raise_error(NotImplementedError)
14
- end
15
- end
16
-
17
- describe "#update" do
18
- it do
19
- expect { subject.update('') }.to raise_error(NotImplementedError)
20
- end
21
- end
22
-
23
- context "when inherited" do
24
- subject do
25
- Class.new(described_class).tap do |klass|
26
- klass::WIDTH = 16
27
-
28
- klass::INIT_CRC = 0x01
29
-
30
- klass::XOR_MASK = 0x02
31
-
32
- klass::TABLE = [0x01, 0x02, 0x03, 0x04].freeze
33
- end
34
- end
35
-
36
- it "should override WIDTH" do
37
- expect(subject::WIDTH).not_to be described_class::WIDTH
38
- end
39
-
40
- it "should override INIT_CRC" do
41
- expect(subject::INIT_CRC).not_to be described_class::INIT_CRC
42
- end
43
-
44
- it "should override XOR_MASK" do
45
- expect(subject::XOR_MASK).not_to be described_class::XOR_MASK
46
- end
47
-
48
- it "should override TABLE" do
49
- expect(subject::TABLE).not_to be described_class::TABLE
50
- end
51
-
52
- describe "#initialize" do
53
- let(:instance) { subject.new }
54
-
55
- it "should initialize @init_crc" do
56
- expect(instance.instance_variable_get("@init_crc")).to be subject::INIT_CRC
57
- end
58
-
59
- it "should initialize @xor_mask" do
60
- expect(instance.instance_variable_get("@xor_mask")).to be subject::XOR_MASK
61
- end
62
-
63
- it "should initialize @width" do
64
- expect(instance.instance_variable_get("@width")).to be subject::WIDTH
65
- end
66
-
67
- it "should initialize @table" do
68
- expect(instance.instance_variable_get("@table")).to be subject::TABLE
69
- end
70
- end
71
- end
72
- end
@@ -1,9 +0,0 @@
1
- ARG RUBY_VERSION=2.7.0
2
- FROM ruby:${RUBY_VERSION}-slim
3
-
4
- RUN apt-get update -y -qq
5
- RUN apt-get install -y -qq bash
6
-
7
- COPY ./digest-crc.gem .
8
-
9
- ENTRYPOINT gem install ./digest-crc.gem
@@ -1,3 +0,0 @@
1
- FROM test-digest-crc-base
2
-
3
- RUN apt-get install -y -qq gcc
@@ -1,3 +0,0 @@
1
- FROM test-digest-crc-with-gcc
2
-
3
- RUN apt-get install -y -qq make
@@ -1,59 +0,0 @@
1
- require 'rspec'
2
-
3
- describe "installing digest-crc" do
4
- ROOT_DIR = File.expand_path('../../..',__FILE__)
5
- DOCKER_DIR = File.expand_path('../docker', __FILE__)
6
-
7
- IMAGES = %w[
8
- test-digest-crc-base
9
- test-digest-crc-with-gcc
10
- test-digest-crc-with-gcc-and-make
11
- ]
12
-
13
- before(:all) do
14
- puts ">>> Building digest-crc gem ..."
15
- Dir.chdir(ROOT_DIR) do
16
- system 'gem', 'build',
17
- '-o', File.join(DOCKER_DIR,'digest-crc.gem'),
18
- 'digest-crc.gemspec'
19
- end
20
-
21
- IMAGES.each do |image|
22
- suffix = image.sub('test-digest-crc-','')
23
-
24
- puts ">>> Building #{image} docker image ..."
25
- Dir.chdir(DOCKER_DIR) do
26
- system "docker build -t #{image} --file Dockerfile.#{suffix} ."
27
- end
28
- end
29
- end
30
-
31
- context "when installing into a slim environment" do
32
- let(:image) { 'test-digest-crc-base' }
33
-
34
- it "should successfully install digest-crc" do
35
- expect(system("docker run #{image}")).to be(true)
36
- end
37
- end
38
-
39
- context "when gcc is installed" do
40
- let(:image) { 'test-digest-crc-with-gcc' }
41
-
42
- it "should successfully install digest-crc" do
43
- expect(system("docker run #{image}")).to be(true)
44
- end
45
- end
46
-
47
- context "when gcc and make are installed" do
48
- let(:image) { 'test-digest-crc-with-gcc-and-make' }
49
-
50
- it "should successfully install digest-crc" do
51
- expect(system("docker run #{image}")).to be(true)
52
- end
53
- end
54
-
55
- after(:all) do
56
- puts ">>> Removing test-digest-crc docker images ..."
57
- system "docker image rm -f #{IMAGES.reverse.join(' ')}"
58
- end
59
- end
data/spec/spec_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'rspec'
2
- require 'simplecov'
3
- SimpleCov.start