View source code Display the source code in std/digest/crc.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Module std.digest.crc

Cyclic Redundancy Check (32-bit) implementation.

Category Functions
Template API CRC32
OOP API CRC32Digest
Helpers crcHexString crc32Of

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

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

Note

CRCs are usually printed with the MSB first. When using std.digest.digest.toHexString the result will be in an unexpected order. Use std.digest.digest.toHexString's optional order parameter to specify decreasing order for the correct result. The crcHexString alias can also be used for this purpose.

References

Wikipedia on CRC

Standards

Implements the 'common' IEEE CRC32 variant (LSB-first order, Initial value uint.max, complement result)

CTFE

Digests do not work in CTFE

Example

//Template API
import std.digest.crc;

ubyte[4] hash = crc32Of("The quick brown fox jumps over the lazy dog");
assert(crcHexString(hash) == "414FA339");

//Feeding data
ubyte[1024] data;
CRC32 crc;
crc.put(data[]);
crc.start(); //Start again
crc.put(data[]);
hash = crc.finish();

Example

//OOP API
import std.digest.crc;

auto crc = new CRC32Digest();
ubyte[] hash = crc.digest("The quick brown fox jumps over the lazy dog");
assert(crcHexString(hash) == "414FA339"); //352441c2

//Feeding data
ubyte[1024] data;
crc.put(data[]);
crc.reset(); //Start again
crc.put(data[]);
hash = crc.finish();

Functions

Name Description
crc32Of This is a convenience alias for std.digest.digest.digest using the CRC32 implementation.

Structs

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

Aliases

Name Type Description
CRC32Digest WrapperDigest!(std.digest.crc.CRC32) OOP API CRC32 implementation. See std.digest.digest for differences between template and OOP API.
crcHexString This is a convenience alias for std.digest.digest.toHexString producing the usual CRC32 string output.

Authors

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

License

Boost License 1.0.

Comments