View source code
Display the source code in std/digest/crc.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

Module 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 std.digest.toHexString the result will be in an unexpected order. Use std.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");
writeln(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

NameDescription
crc32Of(data) This is a convenience alias for std.digest.digest using the CRC32 implementation.
crc64ECMAOf(data) This is a convenience alias for std.digest.digest using the CRC64-ECMA implementation.
crc64ISOOf(data) This is a convenience alias for std.digest.digest.digest using the CRC64-ISO implementation.

Structs

NameDescription
CRC Generic Template API used for CRC32 and CRC64 implementations.

Aliases

NameTypeDescription
CRC32 CRC!(32,3988292384L) Template API CRC32 implementation. See std.digest for differences between template and OOP API.
CRC32Digest std.digest.WrapperDigest!(std.digest.crc.CRC!(32,3988292384L).CRC) OOP API CRC32 implementation. See std.digest for differences between template and OOP API.
CRC64ECMA CRC!(64,-3932672073523589310L) Template API CRC64-ECMA implementation. See std.digest for differences between template and OOP API.
CRC64ECMADigest std.digest.WrapperDigest!(std.digest.crc.CRC!(64,-3932672073523589310L).CRC) OOP API CRC64-ECMA implementation. See std.digest for differences between template and OOP API.
CRC64ISO CRC!(64,-2882303761517117440L) Template API CRC64-ISO implementation. See std.digest for differences between template and OOP API.
CRC64ISODigest std.digest.WrapperDigest!(std.digest.crc.CRC!(64,-2882303761517117440L).CRC) OOP API CRC64-ISO implementation. See std.digest for differences between template and OOP API.
crcHexString toHexString!(Order.decreasing) producing the usual CRC32 string output.

Authors

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

License

Boost License 1.0.