Module std.digest.crc
Cyclic Redundancy Check (32-bit) implementation.
Category | Functions |
---|---|
Template API | CRC CRC32 CRC64ECMA CRC64ISO
|
OOP API | CRC32Digest CRC64ECMADigest CRC64ISODigest |
Helpers | crcHexString crc32Of crc64ECMAOf crc64ISOOf |
This module conforms to the APIs defined in std
. To understand the
differences between the template and the OOP API, see std
.
This module publicly imports std
and can be used as a stand-alone
module.
Note
CRCs are usually printed with the MSB first. When using
std
the result will be in an unexpected
order. Use std
's optional order parameter
to specify decreasing order for the correct result. The crcHexString
alias can also be used for this purpose.
References
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
Name | Description |
---|---|
crc32Of(data)
|
This is a convenience alias for std using the
CRC32 implementation.
|
crc64ECMAOf(data)
|
This is a convenience alias for std using the
CRC64-ECMA implementation.
|
crc64ISOOf(data)
|
This is a convenience alias for std using the
CRC64-ISO implementation.
|
Structs
Name | Description |
---|---|
CRC
|
Generic Template API used for CRC32 and CRC64 implementations. |
Aliases
Name | Type | Description |
---|---|---|
CRC32
|
CRC!(32,3988292384L)
|
Template API CRC32 implementation.
See std for differences between template and OOP API.
|
CRC32Digest
|
std
|
OOP API CRC32 implementation.
See std for differences between template and OOP API.
|
CRC64ECMA
|
CRC!(64,-3932672073523589310L)
|
Template API CRC64-ECMA implementation.
See std for differences between template and OOP API.
|
CRC64ECMADigest
|
std
|
OOP API CRC64-ECMA implementation.
See std for differences between template and OOP API.
|
CRC64ISO
|
CRC!(64,-2882303761517117440L)
|
Template API CRC64-ISO implementation.
See std for differences between template and OOP API.
|
CRC64ISODigest
|
std
|
OOP API CRC64-ISO implementation.
See std 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