Class: Digest::CRC
Overview
Base class for all CRC algorithms.
Constant Summary collapse
- INIT_CRC =
The initial value of the CRC checksum
0x00
- XOR_MASK =
The XOR mask to apply to the resulting CRC checksum
0x00
- WIDTH =
The bit width of the CRC checksum
0
- TABLE =
Default place holder CRC table
[].freeze
Class Method Summary collapse
-
.checksum(data) ⇒ Integer
Calculates the CRC checksum.
-
.pack(crc) ⇒ String
Packs the given CRC checksum.
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#block_length ⇒ 1
The input block length.
-
#checksum ⇒ Integer
The resulting CRC checksum.
-
#digest_length ⇒ Integer
The length of the digest.
-
#finish ⇒ Object
Finishes the CRC checksum calculation.
-
#initialize ⇒ CRC
constructor
Initializes the CRC checksum.
-
#reset ⇒ Integer
Resets the CRC checksum.
-
#update(data) ⇒ Object
Updates the CRC checksum with the given data.
Constructor Details
#initialize ⇒ CRC
Initializes the CRC checksum.
52 53 54 55 56 57 58 59 |
# File 'lib/digest/crc.rb', line 52 def initialize @init_crc = self.class.const_get(:INIT_CRC) @xor_mask = self.class.const_get(:XOR_MASK) @width = self.class.const_get(:WIDTH) @table = self.class.const_get(:TABLE) reset end |
Class Method Details
.checksum(data) ⇒ Integer
Calculates the CRC checksum.
32 33 34 35 36 37 |
# File 'lib/digest/crc.rb', line 32 def self.checksum(data) crc = self.new crc << data return crc.checksum end |
.pack(crc) ⇒ String
Packs the given CRC checksum.
45 46 47 |
# File 'lib/digest/crc.rb', line 45 def self.pack(crc) '' end |
Instance Method Details
#<<(data) ⇒ Object
92 93 94 95 |
# File 'lib/digest/crc.rb', line 92 def <<(data) update(data) return self end |
#block_length ⇒ 1
The input block length.
66 67 68 |
# File 'lib/digest/crc.rb', line 66 def block_length 1 end |
#checksum ⇒ Integer
The resulting CRC checksum.
113 114 115 |
# File 'lib/digest/crc.rb', line 113 def checksum @crc ^ @xor_mask end |
#digest_length ⇒ Integer
The length of the digest.
76 77 78 |
# File 'lib/digest/crc.rb', line 76 def digest_length (@width / 8.0).ceil end |
#finish ⇒ Object
Finishes the CRC checksum calculation.
122 123 124 |
# File 'lib/digest/crc.rb', line 122 def finish self.class.pack(checksum) end |
#reset ⇒ Integer
Resets the CRC checksum.
103 104 105 |
# File 'lib/digest/crc.rb', line 103 def reset @crc = @init_crc end |
#update(data) ⇒ Object
Updates the CRC checksum with the given data.
86 87 |
# File 'lib/digest/crc.rb', line 86 def update(data) end |