digest-crc 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/integration.yml +1 -1
  3. data/.github/workflows/ruby.yml +6 -6
  4. data/ChangeLog.md +11 -0
  5. data/Gemfile +2 -1
  6. data/LICENSE.txt +1 -1
  7. data/README.md +5 -10
  8. data/benchmarks.rb +1 -0
  9. data/digest-crc.gemspec +8 -4
  10. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +4 -0
  11. data/ext/digest/crc15/crc15_ext.c +4 -0
  12. data/ext/digest/crc16/crc16_ext.c +4 -0
  13. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +4 -0
  14. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +4 -0
  15. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +4 -0
  16. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +4 -0
  17. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +4 -1
  18. data/ext/digest/crc16_usb/crc16_usb_ext.c +4 -1
  19. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +4 -1
  20. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +4 -0
  21. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +4 -0
  22. data/ext/digest/crc24/crc24_ext.c +4 -0
  23. data/ext/digest/crc32/crc32_ext.c +4 -0
  24. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +4 -0
  25. data/ext/digest/crc32_jam/crc32_jam_ext.c +4 -1
  26. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +4 -0
  27. data/ext/digest/crc32_posix/crc32_posix_ext.c +4 -0
  28. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +4 -0
  29. data/ext/digest/crc32c/crc32c_ext.c +4 -1
  30. data/ext/digest/crc5/crc5_ext.c +4 -0
  31. data/ext/digest/crc64/crc64_ext.c +4 -0
  32. data/ext/digest/crc64_jones/crc64_jones_ext.c +4 -1
  33. data/ext/digest/crc64_nvme/crc64_nvme.c +102 -0
  34. data/ext/digest/crc64_nvme/crc64_nvme.h +8 -0
  35. data/ext/digest/crc64_nvme/crc64_nvme_ext.c +31 -0
  36. data/ext/digest/crc64_nvme/extconf.rb +7 -0
  37. data/ext/digest/crc64_xz/crc64_xz_ext.c +4 -1
  38. data/ext/digest/crc8/crc8_ext.c +4 -0
  39. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +4 -1
  40. data/gemspec.yml +1 -1
  41. data/lib/digest/crc.rb +85 -9
  42. data/lib/digest/crc1.rb +2 -0
  43. data/lib/digest/crc15.rb +2 -32
  44. data/lib/digest/crc16.rb +2 -32
  45. data/lib/digest/crc16_ccitt.rb +2 -14
  46. data/lib/digest/crc16_dnp.rb +2 -14
  47. data/lib/digest/crc16_genibus.rb +2 -14
  48. data/lib/digest/crc16_kermit.rb +2 -14
  49. data/lib/digest/crc16_x_25.rb +3 -1
  50. data/lib/digest/crc16_xmodem.rb +2 -14
  51. data/lib/digest/crc16_zmodem.rb +2 -14
  52. data/lib/digest/crc24.rb +2 -33
  53. data/lib/digest/crc32.rb +2 -34
  54. data/lib/digest/crc32_bzip2.rb +2 -14
  55. data/lib/digest/crc32_mpeg.rb +2 -14
  56. data/lib/digest/crc32_posix.rb +2 -14
  57. data/lib/digest/crc32_xfer.rb +2 -14
  58. data/lib/digest/crc5.rb +19 -44
  59. data/lib/digest/crc64.rb +2 -38
  60. data/lib/digest/crc64_nvme.rb +90 -0
  61. data/lib/digest/crc8.rb +2 -27
  62. metadata +8 -36
  63. data/spec/crc15_spec.rb +0 -10
  64. data/spec/crc16_ccitt_spec.rb +0 -10
  65. data/spec/crc16_genibus_spec.rb +0 -10
  66. data/spec/crc16_kermit_spec.rb +0 -10
  67. data/spec/crc16_modbus_spec.rb +0 -10
  68. data/spec/crc16_qt_spec.rb +0 -10
  69. data/spec/crc16_spec.rb +0 -10
  70. data/spec/crc16_usb_spec.rb +0 -10
  71. data/spec/crc16_x_25_spec.rb +0 -10
  72. data/spec/crc16_xmodem_spec.rb +0 -10
  73. data/spec/crc16_zmodem_spec.rb +0 -10
  74. data/spec/crc1_spec.rb +0 -10
  75. data/spec/crc24_spec.rb +0 -10
  76. data/spec/crc32_bzip2_spec.rb +0 -10
  77. data/spec/crc32_jam_spec.rb +0 -10
  78. data/spec/crc32_mpeg_spec.rb +0 -16
  79. data/spec/crc32_posix_spec.rb +0 -10
  80. data/spec/crc32_spec.rb +0 -10
  81. data/spec/crc32_xfer_spec.rb +0 -10
  82. data/spec/crc32c_spec.rb +0 -10
  83. data/spec/crc5_spec.rb +0 -12
  84. data/spec/crc64_jones_spec.rb +0 -10
  85. data/spec/crc64_spec.rb +0 -10
  86. data/spec/crc64_xz_spec.rb +0 -10
  87. data/spec/crc8_1wire_spec.rb +0 -16
  88. data/spec/crc8_spec.rb +0 -10
  89. data/spec/crc_examples.rb +0 -27
  90. data/spec/crc_spec.rb +0 -72
  91. data/spec/integration/docker/Dockerfile.base +0 -9
  92. data/spec/integration/docker/Dockerfile.with-gcc +0 -3
  93. data/spec/integration/docker/Dockerfile.with-gcc-and-make +0 -3
  94. data/spec/integration/install_spec.rb +0 -59
  95. data/spec/spec_helper.rb +0 -1
data/lib/digest/crc.rb CHANGED
@@ -17,6 +17,9 @@ module Digest
17
17
  # The bit width of the CRC checksum
18
18
  WIDTH = 0
19
19
 
20
+ # Define true or false whether the input direction is bit reversed or not of the CRC checksum
21
+ REFLECT_INPUT = nil
22
+
20
23
  # Default place holder CRC table
21
24
  TABLE = [].freeze
22
25
 
@@ -45,20 +48,46 @@ module Digest
45
48
  # @return [String]
46
49
  # The packed CRC checksum.
47
50
  #
48
- # @abstract
49
- #
50
51
  def self.pack(crc)
51
- raise(NotImplementedError,"#{self.class}##{__method__} not implemented")
52
+ unless (width = self::WIDTH) > 0
53
+ raise(NotImplementedError, "#{self} is incompleted as CRC")
54
+ end
55
+
56
+ bitclass = width + (-width & 0x07)
57
+ byte_count = bitclass / 8
58
+
59
+ crc &= ~(-1 << width)
60
+
61
+ result = [crc].pack("Q>")
62
+ result[0, result.bytesize - byte_count] = ""
63
+ result
64
+ end
65
+
66
+ #
67
+ # Determines whether the library is using the optimized C extensions
68
+ # implementation, or the pure-Ruby implementation.
69
+ #
70
+ # @return [:c_ext, :pure]
71
+ #
72
+ # @since 0.7.0
73
+ #
74
+ def self.implementation
75
+ if instance_method(:update).source_location.nil?
76
+ :c_ext
77
+ else
78
+ :pure
79
+ end
52
80
  end
53
81
 
54
82
  #
55
83
  # Initializes the CRC checksum.
56
84
  #
57
85
  def initialize
58
- @init_crc = self.class.const_get(:INIT_CRC)
59
- @xor_mask = self.class.const_get(:XOR_MASK)
60
- @width = self.class.const_get(:WIDTH)
61
- @table = self.class.const_get(:TABLE)
86
+ @init_crc = self.class.const_get(:INIT_CRC)
87
+ @xor_mask = self.class.const_get(:XOR_MASK)
88
+ @width = self.class.const_get(:WIDTH)
89
+ @reflect_input = self.class.const_get(:REFLECT_INPUT)
90
+ @table = self.class.const_get(:TABLE)
62
91
 
63
92
  reset
64
93
  end
@@ -88,10 +117,57 @@ module Digest
88
117
  # @param [String] data
89
118
  # The data to update the CRC checksum with.
90
119
  #
91
- # @abstract
120
+ # @raise [NotImplementedError]
121
+ # If WIDTH, TABLE, or REFLECT_INPUT constants are not set properly.
92
122
  #
93
123
  def update(data)
94
- raise(NotImplementedError,"#{self.class}##{__method__} not implemented")
124
+ unless @width >= 1
125
+ raise(NotImplementedError, "incompleted #{self.class} as CRC (expected WIDTH to be 1 or more)")
126
+ end
127
+
128
+ if @table.empty?
129
+ raise(NotImplementedError, "incompleted #{self.class} as CRC (expected TABLE to be not empty)")
130
+ end
131
+
132
+ if @reflect_input.nil?
133
+ raise(NotImplementedError, "incompleted #{self.class} as CRC (expected REFLECT_INPUT to be not nil)")
134
+ end
135
+
136
+ table = @table
137
+ crc = @crc
138
+
139
+ if @reflect_input
140
+ if @width > 8
141
+ data.each_byte do |b|
142
+ crc = table[b ^ (0xff & crc)] ^ (crc >> 8)
143
+ end
144
+ else
145
+ data.each_byte do |b|
146
+ # Omit (crc >> 8) since bits upper than the lower 8 bits are always 0
147
+ crc = table[b ^ (0xff & crc)]
148
+ end
149
+ end
150
+ else
151
+ if @width > 8
152
+ higher_bit_off = @width - 8
153
+ remain_mask = ~(-1 << higher_bit_off)
154
+
155
+ data.each_byte do |b|
156
+ crc = table[b ^ (0xff & (crc >> higher_bit_off))] ^ ((remain_mask & crc) << 8)
157
+ end
158
+ else
159
+ padding = 8 - @width
160
+
161
+ data.each_byte do |b|
162
+ # Omit (crc << 8) since bits lower than the upper 8 bits are always 0
163
+ crc = table[b ^ (0xff & (crc << padding))]
164
+ end
165
+ end
166
+ end
167
+
168
+ @crc = crc
169
+
170
+ self
95
171
  end
96
172
 
97
173
  #
data/lib/digest/crc1.rb CHANGED
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC1 < CRC
8
8
 
9
+ WIDTH = 1
10
+
9
11
  #
10
12
  # Packs the CRC1 checksum.
11
13
  #
data/lib/digest/crc15.rb CHANGED
@@ -10,6 +10,8 @@ module Digest
10
10
 
11
11
  WIDTH = 15
12
12
 
13
+ REFLECT_INPUT = false
14
+
13
15
  # Generated by `./pycrc.py --algorithm=table-driven --model=crc-16 --generate=c`
14
16
  TABLE = [
15
17
  0x0000, 0x4599, 0x4eab, 0x0b32, 0x58cf, 0x1d56, 0x1664, 0x53fd, 0x7407, 0x319e, 0x3aac, 0x7f35, 0x2cc8, 0x6951, 0x6263, 0x27fa,
@@ -30,38 +32,6 @@ module Digest
30
32
  0x276f, 0x62f6, 0x69c4, 0x2c5d, 0x7fa0, 0x3a39, 0x310b, 0x7492, 0x5368, 0x16f1, 0x1dc3, 0x585a, 0x0ba7, 0x4e3e, 0x450c, 0x0095
31
33
  ].freeze
32
34
 
33
- #
34
- # Packs the CRC15 checksum.
35
- #
36
- # @param [Integer] crc
37
- # The CRC15 checksum to pack.
38
- #
39
- # @return [String]
40
- # The packed CRC15 checksum.
41
- #
42
- def self.pack(crc)
43
- buffer = ''
44
-
45
- buffer << ((crc & 0x7f00) >> 8).chr
46
- buffer << (crc & 0xff).chr
47
-
48
- buffer
49
- end
50
-
51
- #
52
- # Updates the CRC15 checksum.
53
- #
54
- # @param [String] data
55
- # The data to update the checksum with.
56
- #
57
- def update(data)
58
- data.each_byte do |b|
59
- @crc = (@table[((@crc >> 7) ^ b) & 0xff] ^ (@crc << 8)) & 0x7fff
60
- end
61
-
62
- return self
63
- end
64
-
65
35
  end
66
36
  end
67
37
 
data/lib/digest/crc16.rb CHANGED
@@ -8,6 +8,8 @@ module Digest
8
8
 
9
9
  WIDTH = 16
10
10
 
11
+ REFLECT_INPUT = true
12
+
11
13
  INIT_CRC = 0x0000
12
14
 
13
15
  # Generated by `./pycrc.py --algorithm=table-driven --model=crc-16`
@@ -46,38 +48,6 @@ module Digest
46
48
  0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
47
49
  ].freeze
48
50
 
49
- #
50
- # Packs the CRC16 checksum.
51
- #
52
- # @param [Integer] crc
53
- # The CRC16 checksum to pack.
54
- #
55
- # @return [String]
56
- # The packed CRC16 checksum.
57
- #
58
- def self.pack(crc)
59
- buffer = ''
60
-
61
- buffer << ((crc & 0xff00) >> 8).chr
62
- buffer << (crc & 0xff).chr
63
-
64
- buffer
65
- end
66
-
67
- #
68
- # Updates the CRC16 checksum.
69
- #
70
- # @param [String] data
71
- # The data to update the checksum with.
72
- #
73
- def update(data)
74
- data.each_byte do |b|
75
- @crc = ((@table[(@crc ^ b) & 0xff] ^ (@crc >> 8)) & 0xffff)
76
- end
77
-
78
- return self
79
- end
80
-
81
51
  end
82
52
  end
83
53
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC16CCITT < CRC16
8
8
 
9
+ REFLECT_INPUT = false
10
+
9
11
  INIT_CRC = 0xffff
10
12
 
11
13
  # Generated by `./pycrc.py --algorithm=table-driven --model=crc-16-ccitt --generate=c`
@@ -44,20 +46,6 @@ module Digest
44
46
  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
45
47
  ].freeze
46
48
 
47
- #
48
- # Updates the CRC16 CCITT checksum.
49
- #
50
- # @param [String] data
51
- # The data to update the checksum with.
52
- #
53
- def update(data)
54
- data.each_byte do |b|
55
- @crc = ((@table[((@crc >> 8) ^ b) & 0xff] ^ (@crc << 8)) & 0xffff)
56
- end
57
-
58
- return self
59
- end
60
-
61
49
  end
62
50
  end
63
51
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC16DNP < CRC16
8
8
 
9
+ REFLECT_INPUT = true
10
+
9
11
  INIT_CRC = 0
10
12
 
11
13
  TABLE = [
@@ -43,20 +45,6 @@ module Digest
43
45
  0x91af, 0xa7f1, 0xfd13, 0xcb4d, 0x48d7, 0x7e89, 0x246b, 0x1235
44
46
  ].freeze
45
47
 
46
- #
47
- # Updates the CRC16 DNP checksum.
48
- #
49
- # @param [String] data
50
- # The data to update the checksum with.
51
- #
52
- def update(data)
53
- data.each_byte do |b|
54
- @crc = ((@crc >> 8) ^ @table[(@crc ^ b) & 0xff])
55
- end
56
-
57
- return self
58
- end
59
-
60
48
  def finish
61
49
  self.class.pack(~@crc)
62
50
  end
@@ -8,6 +8,8 @@ module Digest
8
8
  #
9
9
  class CRC16Genibus < CRC16
10
10
 
11
+ REFLECT_INPUT = false
12
+
11
13
  INIT_XOR = 0xffff
12
14
 
13
15
  INIT_CRC = 0x0000 ^ INIT_XOR
@@ -50,20 +52,6 @@ module Digest
50
52
  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
51
53
  ].freeze
52
54
 
53
- #
54
- # Updates the CRC16 Genibus checksum.
55
- #
56
- # @param [String] data
57
- # The data to update the checksum with.
58
- #
59
- def update(data)
60
- data.each_byte do |b|
61
- @crc = (@table[((@crc >> 8) ^ b) & 0xff] ^ (@crc << 8)) & 0xffff
62
- end
63
-
64
- return self
65
- end
66
-
67
55
  end
68
56
  end
69
57
 
@@ -8,6 +8,8 @@ module Digest
8
8
  #
9
9
  class CRC16Kermit < CRC16
10
10
 
11
+ REFLECT_INPUT = true
12
+
11
13
  # Generated by `./pycrc.py --algorithm=table-driven --model=kermit --generate=c`
12
14
  TABLE = [
13
15
  0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
@@ -44,20 +46,6 @@ module Digest
44
46
  0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
45
47
  ].freeze
46
48
 
47
- #
48
- # Updates the CRC16 Kermit checksum.
49
- #
50
- # @param [String] data
51
- # The data to update the checksum with.
52
- #
53
- def update(data)
54
- data.each_byte do |b|
55
- @crc = (@table[(@crc ^ b) & 0xff] ^ (@crc >> 8)) & 0xffff
56
- end
57
-
58
- return self
59
- end
60
-
61
49
  end
62
50
  end
63
51
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC16X25 < CRC16
8
8
 
9
+ REFLECT_INPUT = true
10
+
9
11
  INIT_XOR = 0xffff
10
12
 
11
13
  INIT_CRC = 0x0 ^ INIT_XOR
@@ -47,7 +49,7 @@ module Digest
47
49
  0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
48
50
  0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
49
51
  ].freeze
50
-
52
+
51
53
  end
52
54
  end
53
55
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC16XModem < CRC16
8
8
 
9
+ REFLECT_INPUT = false
10
+
9
11
  # Generated by `./pycrc.py --algorithm=table-driven --model=xmodem --generate=c`
10
12
  TABLE = [
11
13
  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
@@ -42,20 +44,6 @@ module Digest
42
44
  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
43
45
  ].freeze
44
46
 
45
- #
46
- # Updates the CRC16 XModem checksum.
47
- #
48
- # @param [String] data
49
- # The data to update the checksum with.
50
- #
51
- def update(data)
52
- data.each_byte do |b|
53
- @crc = ((@table[((@crc >> 8) ^ b) & 0xff] ^ (@crc << 8)) & 0xffff)
54
- end
55
-
56
- return self
57
- end
58
-
59
47
  end
60
48
  end
61
49
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC16ZModem < CRC16
8
8
 
9
+ REFLECT_INPUT = false
10
+
9
11
  # Generated by `./pycrc.py --algorithm=table-driven --model=zmodem --generate=c`
10
12
  TABLE = [
11
13
  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
@@ -42,20 +44,6 @@ module Digest
42
44
  0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
43
45
  ].freeze
44
46
 
45
- #
46
- # Updates the CRC16 checksum.
47
- #
48
- # @param [String] data
49
- # The data to update the checksum with.
50
- #
51
- def update(data)
52
- data.each_byte do |b|
53
- @crc = ((@table[((@crc >> 8) ^ b) & 0xff] ^ (@crc << 8)) & 0xffff)
54
- end
55
-
56
- return self
57
- end
58
-
59
47
  end
60
48
  end
61
49
 
data/lib/digest/crc24.rb CHANGED
@@ -8,6 +8,8 @@ module Digest
8
8
 
9
9
  WIDTH = 24
10
10
 
11
+ REFLECT_INPUT = false
12
+
11
13
  INIT_CRC = 0xb704ce
12
14
 
13
15
  # Generated by `./pycrc.py --algorithm=table-drive --model=crc24 --generate=c`
@@ -46,39 +48,6 @@ module Digest
46
48
  0x42fa2f, 0xc4b6d4, 0xc82f22, 0x4e63d9, 0xd11cce, 0x575035, 0x5bc9c3, 0xdd8538
47
49
  ].freeze
48
50
 
49
- #
50
- # Packs the CRC24 checksum.
51
- #
52
- # @param [Integer] crc
53
- # The checksum to pack.
54
- #
55
- # @return [String]
56
- # The packed checksum.
57
- #
58
- def self.pack(crc)
59
- buffer = ''
60
-
61
- buffer << ((crc & 0xff0000) >> 16).chr
62
- buffer << ((crc & 0x00ff00) >> 8).chr
63
- buffer << (crc & 0x0000ff).chr
64
-
65
- buffer
66
- end
67
-
68
- #
69
- # Updates the CRC24 checksum.
70
- #
71
- # @param [String] data
72
- # The data to update the checksum with.
73
- #
74
- def update(data)
75
- data.each_byte do |b|
76
- @crc = ((@table[((@crc >> 16) ^ b) & 0xff] ^ (@crc << 8)) & 0xffffff)
77
- end
78
-
79
- return self
80
- end
81
-
82
51
  end
83
52
  end
84
53
 
data/lib/digest/crc32.rb CHANGED
@@ -8,6 +8,8 @@ module Digest
8
8
 
9
9
  WIDTH = 32
10
10
 
11
+ REFLECT_INPUT = true
12
+
11
13
  INIT_CRC = 0xffffffff
12
14
 
13
15
  XOR_MASK = 0xffffffff
@@ -80,40 +82,6 @@ module Digest
80
82
  0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
81
83
  ].freeze
82
84
 
83
- #
84
- # Packs the CRC32 checksum.
85
- #
86
- # @param [Integer] crc
87
- # The checksum to pack.
88
- #
89
- # @return [String]
90
- # The packed checksum.
91
- #
92
- def self.pack(crc)
93
- buffer = ''
94
-
95
- buffer << ((crc & 0xff000000) >> 24).chr
96
- buffer << ((crc & 0xff0000) >> 16).chr
97
- buffer << ((crc & 0xff00) >> 8).chr
98
- buffer << (crc & 0xff).chr
99
-
100
- buffer
101
- end
102
-
103
- #
104
- # Updates the CRC32 checksum.
105
- #
106
- # @param [String] data
107
- # The data to update the checksum with.
108
- #
109
- def update(data)
110
- data.each_byte do |b|
111
- @crc = @table[(@crc ^ b) & 0xff] ^ ((@crc >> 8) & 0xffffffff)
112
- end
113
-
114
- return self
115
- end
116
-
117
85
  end
118
86
  end
119
87
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC32BZip2 < CRC32
8
8
 
9
+ REFLECT_INPUT = false
10
+
9
11
  # Generated by `./pycrc.py --algorithm=table-driven --model=crc-32-bzip2 --generate=c`
10
12
  TABLE = [
11
13
  0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
@@ -42,20 +44,6 @@ module Digest
42
44
  0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
43
45
  ].freeze
44
46
 
45
- #
46
- # Updates the CRC32 BZip2 checksum.
47
- #
48
- # @param [String] data
49
- # The data to update the checksum with.
50
- #
51
- def update(data)
52
- data.each_byte do |b|
53
- @crc = (@table[((@crc >> 24) ^ b) & 0xff] ^ (@crc << 8)) & 0xffffffff
54
- end
55
-
56
- return self
57
- end
58
-
59
47
  end
60
48
  end
61
49
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC32MPEG < CRC32
8
8
 
9
+ REFLECT_INPUT = false
10
+
9
11
  XOR_MASK = 0x00000000
10
12
 
11
13
  # Generated by `./pycrc.py --algorithm=table-driven --model=crc-32-mpeg --generate=c`
@@ -76,20 +78,6 @@ module Digest
76
78
  0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
77
79
  ].freeze
78
80
 
79
- #
80
- # Updates the CRC32 Mpeg checksum.
81
- #
82
- # @param [String] data
83
- # The data to update the checksum with.
84
- #
85
- def update(data)
86
- data.each_byte do |b|
87
- @crc = ((@table[((@crc >> 24) ^ b) & 0xff] ^ (@crc << 8)) & 0xffffffff)
88
- end
89
-
90
- return self
91
- end
92
-
93
81
  end
94
82
 
95
83
  # @deprecated Please use {CRC32MPEG}.
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC32POSIX < CRC32
8
8
 
9
+ REFLECT_INPUT = false
10
+
9
11
  INIT_CRC = 0x00000000
10
12
 
11
13
  TABLE = [
@@ -43,20 +45,6 @@ module Digest
43
45
  0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
44
46
  ].freeze
45
47
 
46
- #
47
- # Updates the CRC32 POSIX checksum.
48
- #
49
- # @param [String] data
50
- # The data to update the checksum with.
51
- #
52
- def update(data)
53
- data.each_byte do |b|
54
- @crc = (@table[((@crc >> 24) ^ b) & 0xff] ^ (@crc << 8)) & 0xffffffff
55
- end
56
-
57
- return self
58
- end
59
-
60
48
  end
61
49
  end
62
50
 
@@ -6,6 +6,8 @@ module Digest
6
6
  #
7
7
  class CRC32XFER < CRC32
8
8
 
9
+ REFLECT_INPUT = false
10
+
9
11
  INIT_CRC = 0x00000000
10
12
 
11
13
  XOR_MASK = 0x00000000
@@ -46,20 +48,6 @@ module Digest
46
48
  0x00006628, 0x00006687, 0x00006776, 0x000067d9, 0x00006494, 0x0000643b, 0x000065ca, 0x00006565
47
49
  ].freeze
48
50
 
49
- #
50
- # Updates the CRC32 XFER checksum.
51
- #
52
- # @param [String] data
53
- # The data to update the checksum with.
54
- #
55
- def update(data)
56
- data.each_byte do |b|
57
- @crc = (@table[((@crc >> 24) ^ b) & 0xff] ^ (@crc << 8)) & 0xffffffff
58
- end
59
-
60
- return self
61
- end
62
-
63
51
  end
64
52
  end
65
53