class Digest::CRC

Base class for all CRC algorithms.

Constants

INIT_CRC

The initial value of the CRC checksum

TABLE

Default place holder CRC table

WIDTH

The bit width of the CRC checksum

XOR_MASK

The XOR mask to apply to the resulting CRC checksum

Public Class Methods

checksum(data) click to toggle source

Calculates the CRC checksum.

@param [String] data

The given data.

@return [Integer]

The CRC checksum.
# File lib/digest/crc.rb, line 32
def self.checksum(data)
  crc = self.new
  crc << data

  return crc.checksum
end
new() click to toggle source

Initializes the CRC checksum.

# 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
pack(crc) click to toggle source

Packs the given CRC checksum.

@return [String]

The packed CRC checksum.
# File lib/digest/crc.rb, line 45
def self.pack(crc)
  ''
end

Public Instance Methods

<<(data) click to toggle source

@see {#update}

# File lib/digest/crc.rb, line 92
def <<(data)
  update(data)
  return self
end
block_length() click to toggle source

The input block length.

@return [1]

# File lib/digest/crc.rb, line 66
def block_length
  1
end
checksum() click to toggle source

The resulting CRC checksum.

@return [Integer]

The resulting CRC checksum.
# File lib/digest/crc.rb, line 113
def checksum
  @crc ^ @xor_mask
end
digest_length() click to toggle source

The length of the digest.

@return [Integer]

The length in bytes.
# File lib/digest/crc.rb, line 76
def digest_length
  (@width / 8.0).ceil
end
finish() click to toggle source

Finishes the CRC checksum calculation.

@see {pack}

# File lib/digest/crc.rb, line 122
def finish
  self.class.pack(checksum)
end
reset() click to toggle source

Resets the CRC checksum.

@return [Integer]

The default value of the CRC checksum.
# File lib/digest/crc.rb, line 103
def reset
  @crc = @init_crc
end
update(data) click to toggle source

Updates the CRC checksum with the given data.

@param [String] data

The data to update the CRC checksum with.
# File lib/digest/crc.rb, line 86
def update(data)
end