std.digest.crc

Cyclic Redundancy Check (32-bit) implementation.

This module conforms to the APIs defined in std.digest. To understand the differences between the template and the OOP API, see std.digest.

This module publicly imports std.digest and can be used as a stand-alone module.

Note

CRCs are usually printed with the MSB first. When using toHexString the result will be in an unexpected

order. Use toHexString's optional order parameter to specify decreasing order for the correct result. The crcHexString alias can also be used for this purpose.

License

Boost License 1.0.

Authors

Pavel "EvilOne" Minayev, Alex Rønne Petersen, Johannes Pfau

References:

Wikipedia on CRC

Source: std/digest/crc.d

Standards

Implements the 'common' IEEE CRC32 variant

(LSB-first order, Initial value uint.max, complement result)

CTFE: Digests do not work in CTFE

Types 9

aliasCRC32 = CRC!(32, 0xEDB88320)

Template API CRC32 implementation. See std.digest for differences between template and OOP API.

aliasCRC64ECMA = CRC!(64, 0xC96C5795D7870F42)

Template API CRC64-ECMA implementation. See std.digest for differences between template and OOP API.

aliasCRC64ISO = CRC!(64, 0xD800000000000000)

Template API CRC64-ISO implementation. See std.digest for differences between template and OOP API.

structCRC(uint N, ulong P) if (N == 32 || N == 64)

Generic Template API used for CRC32 and CRC64 implementations.

The N parameter indicate the size of the hash in bits. The parameter P specify the polynomial to be used for reduction.

You may want to use the CRC32, CRC65ECMA and CRC64ISO aliases for convenience.

See std.digest for differences between template and OOP API.

Fields
T[256][8] tables
T _state
Methods
void put(scope const(ubyte)[] data...) @trusted pure nothrow @nogcUse this to feed the digest with data. Also implements the isOutputRange interface for `ubyte` and `const(ubyte)[]`.
void start() @safe pure nothrow @nogcUsed to initialize the CRC32 digest.
R finish() @safe pure nothrow @nogcReturns the finished CRC hash. This also calls start to reset the internal state.
R peek() const @safe pure nothrow @nogcWorks like `finish` but does not reset the internal state, so it's possible to continue putting data into this CRC after a call to peek.
aliascrcHexString = toHexString!(Order.decreasing)

producing the usual CRC32 string output.

aliascrcHexString = toHexString!(Order.decreasing, 16)

ditto

OOP API CRC32 implementation. See std.digest for differences between template and OOP API.

This is an alias for WrapperDigest!CRC32, see there for more information.

OOP API CRC64-ECMA implementation. See std.digest for differences between template and OOP API.

This is an alias for WrapperDigest!CRC64ECMA, see there for more information.

OOP API CRC64-ISO implementation. See std.digest for differences between template and OOP API.

This is an alias for WrapperDigest!CRC64ISO, see there for more information.

Functions 4

private fnT[256][8] genTables(T)(T polynomial)
fnubyte[4] crc32Of(T...)(T data)This is a convenience alias for digest using the CRC32 implementation.
fnubyte[8] crc64ECMAOf(T...)(T data)This is a convenience alias for digest using the CRC64-ECMA implementation.
fnubyte[8] crc64ISOOf(T...)(T data)This is a convenience alias for digest using the CRC64-ISO implementation.