Class: Digest::CRC
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
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.
46 47 48 |
# File 'lib/digest/crc.rb', line 46 def initialize @crc = self.class.const_get(:INIT_CRC) end |
Class Method Details
.checksum(data) ⇒ Integer
Calculates the CRC checksum.
26 27 28 29 30 31 |
# File 'lib/digest/crc.rb', line 26 def self.checksum(data) crc = self.new crc << data return crc.checksum end |
.pack(crc) ⇒ String
Packs the given CRC checksum.
39 40 41 |
# File 'lib/digest/crc.rb', line 39 def self.pack(crc) '' end |
Instance Method Details
#<<(data) ⇒ Object
81 82 83 84 |
# File 'lib/digest/crc.rb', line 81 def <<(data) update(data) return self end |
#block_length ⇒ 1
The input block length.
55 56 57 |
# File 'lib/digest/crc.rb', line 55 def block_length 1 end |
#checksum ⇒ Integer
The resulting CRC checksum.
102 103 104 |
# File 'lib/digest/crc.rb', line 102 def checksum @crc ^ self.class.const_get(:XOR_MASK) end |
#digest_length ⇒ Integer
The length of the digest.
65 66 67 |
# File 'lib/digest/crc.rb', line 65 def digest_length (self.class.const_get(:WIDTH) / 8.0).ceil end |
#finish ⇒ Object
Finishes the CRC checksum calculation.
111 112 113 |
# File 'lib/digest/crc.rb', line 111 def finish self.class.pack(checksum) end |
#reset ⇒ Integer
Resets the CRC checksum.
92 93 94 |
# File 'lib/digest/crc.rb', line 92 def reset @crc = self.class.const_get(:INIT_CRC) end |
#update(data) ⇒ Object
Updates the CRC checksum with the given data.
75 76 |
# File 'lib/digest/crc.rb', line 75 def update(data) end |