libxcks  0.1.0.1
libxcks::CRC32 Class Referencefinal

Computes the CRC-32 from a byte stream. More...

#include <crc32.hpp>

Inheritance diagram for libxcks::CRC32:
Collaboration diagram for libxcks::CRC32:

Public Member Functions

 CRC32 ()
 Default constructor. More...
 
void reset () override
 Resets the CRC32 to initial value. More...
 
uint32_t getUint32Value () const
 Returns the CRC32 value. More...
 
std::string toString (const bool hexInUpperCase=false) const override
 Returns the CRC32 value in a string. More...
 
uint8_t * getValue (uint8_t *buffer) const override
 Returns the CRC32 value in the first 4 bytes of the given address. More...
 
size_t getSize () const override
 Returns the minimal size to allocate in memory to store the checksum with the getValue(buffer) method. More...
 
void update (const uint8_t *buf, size_t len) override
 Updates the CRC32 with specified array of bytes. More...
 
std::string getName () const override
 Returns the name of the checksum or the hash algorithm. More...
 
ArrayString getAltNames () const override
 Returns the alternative names of the CRC32 checksum algorithm. More...
 
ChecksumAlgoId getID () const override
 Returns an unique identifier for the checksum or the hash algorithm. More...
 
- Public Member Functions inherited from libxcks::Checksum
virtual ~Checksum ()
 Destructor. More...
 

Static Public Member Functions

static std::string getChecksumName ()
 Returns the name of the checksum algorithm. More...
 
static constexpr ChecksumAlgoId getIdentifier ()
 Returns an unique identifier for the checksum algorithm. More...
 
static ArrayString getAlternativeNames ()
 Returns the alternative names of the CRC32 checksum algorithm. More...
 
static ChecksumgetNewInstance ()
 Gets a new instance of this class. More...
 
- Static Public Member Functions inherited from libxcks::Checksum
static ArrayString getAlternativeNames ()
 Returns the alternative name(s) of the checksum or the hash algorithm. More...
 

Protected Attributes

uint32_t crc32
 The current CRC32 value. More...
 

Static Protected Attributes

static const uint32_t crc_table [256]
 Table used to compute the CRC32 value. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from libxcks::ChecksumEx
static uint32_t swapOnLE (const uint32_t value)
 Swaps bytes on little endian architectures. More...
 
static uint32_t swapOnBE (const uint32_t value)
 Swaps bytes on big endian architectures. More...
 
static uint64_t swapOnLE (const uint64_t value)
 Swaps bytes on little endian architectures. More...
 
static uint64_t swapOnBE (const uint64_t value)
 Swaps bytes on big endian architectures. More...
 

Detailed Description

Computes the CRC-32 from a byte stream.

This class is writen with the code found in cksfv and zlib code.

Using this class in very simple:
Use the update method to provide to the class the bytes for computing the checksum.

The CRC-32 checksum value can be gotten by the getUint32Value method which puts the CRC32 checksum value in an unsigned 32 bits integer.

The CRC32 checksum computing can be reseted by the reset method.

Definition at line 52 of file crc32.hpp.

Constructor & Destructor Documentation

◆ CRC32()

libxcks::CRC32::CRC32 ( )

Default constructor.

Definition at line 98 of file crc32.cpp.

Member Function Documentation

◆ getAlternativeNames()

ArrayString libxcks::CRC32::getAlternativeNames ( )
static

Returns the alternative names of the CRC32 checksum algorithm.

Returns
The alternative names of the CRC32 checksum algorithm.

Definition at line 181 of file crc32.cpp.

◆ getAltNames()

ArrayString libxcks::CRC32::getAltNames ( ) const
inlineoverridevirtual

Returns the alternative names of the CRC32 checksum algorithm.

Returns
The alternative names of the CRC32 checksum algorithm.

Reimplemented from libxcks::Checksum.

Definition at line 130 of file crc32.hpp.

◆ getChecksumName()

static std::string libxcks::CRC32::getChecksumName ( )
inlinestatic

Returns the name of the checksum algorithm.

Returns
The name of the checksum algorithm.

Definition at line 154 of file crc32.hpp.

◆ getID()

ChecksumAlgoId libxcks::CRC32::getID ( ) const
inlineoverridevirtual

Returns an unique identifier for the checksum or the hash algorithm.

Remarks
The unique ID should be the CRC32 checksum of the algorithm's name returned by getName() but it's only a convention.
Returns
An unique identifier for the checksum or the hash algorithm.

Implements libxcks::Checksum.

Definition at line 144 of file crc32.hpp.

◆ getIdentifier()

static constexpr ChecksumAlgoId libxcks::CRC32::getIdentifier ( )
inlinestaticconstexpr

Returns an unique identifier for the checksum algorithm.

Remarks
The unique ID should be the CRC32 checksum of the algorithm's name returned by getChecksumName() but it's only a convention.
Returns
An unique identifier for the checksum algorithm.

Definition at line 169 of file crc32.hpp.

◆ getName()

std::string libxcks::CRC32::getName ( ) const
inlineoverridevirtual

Returns the name of the checksum or the hash algorithm.

Returns
The name of the checksum or the hash algorithm.

Implements libxcks::Checksum.

Definition at line 120 of file crc32.hpp.

◆ getNewInstance()

static Checksum* libxcks::CRC32::getNewInstance ( )
inlinestatic

Gets a new instance of this class.

The caller is responsible of the deletion of the instance with the delete operator.

Returns
A new instance of this class.

Definition at line 189 of file crc32.hpp.

◆ getSize()

size_t libxcks::CRC32::getSize ( ) const
inlineoverridevirtual

Returns the minimal size to allocate in memory to store the checksum with the getValue(buffer) method.

Returns
The minimal size to allocate in memory to store the checksum with the getValue(buffer) method.

Implements libxcks::Checksum.

Definition at line 105 of file crc32.hpp.

◆ getUint32Value()

uint32_t libxcks::CRC32::getUint32Value ( ) const

Returns the CRC32 value.

Returns
The current checksum value.

Definition at line 118 of file crc32.cpp.

◆ getValue()

uint8_t * libxcks::CRC32::getValue ( uint8_t *  buffer) const
overridevirtual

Returns the CRC32 value in the first 4 bytes of the given address.

Parameters
bufferThe buffer where the CRC32 value will be stored.
Returns
The address of the buffer.
Remarks
The memory for the 4 bytes must have been allocated before calling this method.

Implements libxcks::Checksum.

Definition at line 128 of file crc32.cpp.

◆ reset()

void libxcks::CRC32::reset ( )
overridevirtual

Resets the CRC32 to initial value.

Implements libxcks::ChecksumEx.

Definition at line 108 of file crc32.cpp.

◆ toString()

std::string libxcks::CRC32::toString ( const bool  hexInUpperCase = false) const
overridevirtual

Returns the CRC32 value in a string.

Parameters
hexInUpperCaseIf true the hexadecimal letters will be in uppercase.
Returns
The current CRC32 value.

Reimplemented from libxcks::ChecksumEx.

Definition at line 143 of file crc32.cpp.

◆ update()

void libxcks::CRC32::update ( const uint8_t *  buf,
size_t  len 
)
overridevirtual

Updates the CRC32 with specified array of bytes.

Parameters
bufThe byte array to update the CRC32 with.
lenThe number of bytes to use for the update.

Implements libxcks::Checksum.

Definition at line 162 of file crc32.cpp.

Member Data Documentation

◆ crc32

uint32_t libxcks::CRC32::crc32
protected

The current CRC32 value.

Definition at line 59 of file crc32.hpp.

◆ crc_table

const uint32_t libxcks::CRC32::crc_table
staticprotected

Table used to compute the CRC32 value.

Definition at line 56 of file crc32.hpp.


The documentation for this class was generated from the following files: