A fork of https://github.com/ajungren/crc32_digest to support the latest version of Digest, and Rust 1.74 (November 2023)
An implementation of the digest
crate's Digest
and DynDigest
traits using
crc32fast
.
If digest
is built with the std
feature enabled, Crc32
will implement Write
as well.
Internally, the Crc32
struct provided by this crate implements the FixedOutput
, Input
, and Reset
traits. A
blanket impl
of Digest
and DynDigest
is provided by digest
for types implementing those
traits (along with Clone
and Default
).
Updated for Rust 1.74 and Digest 0.10.7
Write
support requires the std
feature of digest
to be enabled.
use crc32_digest::Crc32;
use digest::Digest;
fn main() {
let mut crc32 = Crc32::new();
crc32.update(b"hello, world");
let result = crc32.finalize();
// Get checksum as a byte slice
assert_eq!(result.as_slice(), &[0xff, 0xab, 0x72, 0x3a]);
// Format checksum as a lowercase hexadecimal string
assert_eq!(format!("{:x}", result), "ffab723a");
}
Alternatively, Crc32::from_state(state: u32)
can be used to create a new Crc32
instance with a specific initial
state.