Crc32c structv0.1.0

Source
The CRC-32C of a message, computed a byte at a time.
pub struct Crc32c {
    // private fields
}

The variant to prefer for new work: it detects more of the double-bit errors that appear at storage-record lengths, and it is the one both supported architectures implement in hardware. Choose Crc32 only when an existing format requires it. Structural Copy; copying takes an independent snapshot of the register.

Constructors

Crc32c

pub func Crc32c() -> Crc32c

Constructs a checksum with nothing written into it yet.

Returns: a hasher with nothing written to it yet

Source

Methods

Reset

pub func Reset(self: &var Crc32c)

Puts the checksum back to where Crc32c() leaves one. self is borrowed mutably. Everything written so far is forgotten. Cannot fail. Runs in constant time and allocates nothing.

Source

Value

pub func Value(self: &Crc32c) -> uint32

The checksum of everything written so far. self is borrowed. The register complemented, which is the value every other implementation reports. Cannot fail. Runs in constant time and allocates nothing.

Returns: the checksum of everything written so far

Source

Implements Hasher

Crc32c conforms to Hasher.

Write

pub func Write(
    self: &var Crc32c,
    bytes: *byte,
    length: uint
)

Adds length bytes at bytes to the checksum. bytes is borrowed and read; length is read by value. A zero length changes nothing and is the one case in which bytes may be null. Splitting a message across several writes gives the same answer as one write. Runs in time proportional to length and allocates nothing. bytes must be readable for length bytes.

NameTypeDescription
bytes*bytethe bytes to absorb
lengthuinthow many bytes; zero absorbs nothing

Source

Finish

pub func Finish(self: &var Crc32c) -> uint64

The checksum of everything written so far, widened to 64 bits. self is borrowed. The upper 32 bits are always zero. Cannot fail. Runs in constant time and allocates nothing.

Returns: the hash of everything written since the last reset

Source

Crc32cPolynomial

pub const Crc32cPolynomial: uint32 = 0x82F63B78;

The reflected Castagnoli generator polynomial, which is what iSCSI, ext4, Btrfs and SCTP mean by "CRC-32C".

Source

Crc32cTable

pub const Crc32cTable: uint32[N] = …;

One byte of division by Crc32cPolynomial, precomputed for every possible byte.

Source

Crc32cOf

pub func Crc32cOf(bytes: *byte, length: uint) -> uint32

The CRC-32C of length bytes at bytes. bytes is borrowed and read; length is read by value. A zero length gives zero, and is the one case in which bytes may be null. Cannot fail. Runs in time proportional to length and allocates nothing. bytes must be readable for length bytes.

Source

Parameters

NameTypeDescription
bytes*bytethe bytes to hash
lengthuinthow many bytes

Returns: their CRC-32C checksum