pub struct Digest { /* private fields */ }Expand description
Represents a CRC Digest, which is used to compute CRC checksums.
The Digest struct maintains the state of the CRC computation, including
the current state, the amount of data processed, the CRC parameters, and
the calculator function used to perform the CRC calculation.
Implementations§
Source§impl Digest
impl Digest
Sourcepub fn new(algorithm: CrcAlgorithm) -> Self
pub fn new(algorithm: CrcAlgorithm) -> Self
Creates a new Digest instance for the specified CRC algorithm.
§Examples
use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc};
let mut digest = Digest::new(Crc32IsoHdlc);
digest.update(b"123456789");
let checksum = digest.finalize();
assert_eq!(checksum, 0xcbf43926);Sourcepub fn new_with_init_state(algorithm: CrcAlgorithm, init_state: u64) -> Self
pub fn new_with_init_state(algorithm: CrcAlgorithm, init_state: u64) -> Self
Creates a new Digest instance for the specified CRC algorithm with a custom initial state.
§Examples
use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc};
// CRC-32/ISO-HDLC with initial state of 0x00000000, instead of the default initial state
// of 0xffffffff,
let mut digest = Digest::new_with_init_state(Crc32IsoHdlc, 0x00000000);
digest.update(b"123456789");
let checksum = digest.finalize();
// different initial state, so checksum will be different
assert_eq!(checksum, 0xd202d277);
let mut digest = Digest::new_with_init_state(Crc32IsoHdlc, 0xffffffff);
digest.update(b"123456789");
let checksum = digest.finalize();
// same initial state as the default, so checksum will be the same
assert_eq!(checksum, 0xcbf43926);Sourcepub fn new_with_params(params: CrcParams) -> Self
pub fn new_with_params(params: CrcParams) -> Self
Creates a new Digest instance with custom CRC parameters.
§Examples
use crc_fast::{Digest, CrcParams};
// Define custom CRC-32 parameters (equivalent to CRC-32/ISO-HDLC)
let custom_params = CrcParams::new(
"CRC-32/CUSTOM",
32,
0x04c11db7,
0xffffffff,
true,
0xffffffff,
0xcbf43926,
);
let mut digest = Digest::new_with_params(custom_params);
digest.update(b"123456789");
let checksum = digest.finalize();
assert_eq!(checksum, 0xcbf43926);Sourcepub fn finalize_reset(&mut self) -> u64
pub fn finalize_reset(&mut self) -> u64
Finalizes the CRC computation, resets the state, and returns the result.
Sourcepub fn get_amount(&self) -> u64
pub fn get_amount(&self) -> u64
Gets the amount of data processed so far
Sourcepub fn get_state(&self) -> u64
pub fn get_state(&self) -> u64
Gets the current CRC state.
§Examples
use crc_fast::{Digest, CrcAlgorithm::Crc32IsoHdlc};
let mut digest = Digest::new(Crc32IsoHdlc);
digest.update(b"123456789");
let state = digest.get_state();
// non-finalized state, so it won't match the final checksum
assert_eq!(state, 0x340bc6d9);
// finalized state will match the checksum
assert_eq!(digest.finalize(), 0xcbf43926);Trait Implementations§
Source§impl DynDigest for Digest
Available on crate feature alloc only.
impl DynDigest for Digest
Available on crate feature
alloc only.Source§fn finalize_into(self, buf: &mut [u8]) -> Result<(), InvalidBufferSize>
fn finalize_into(self, buf: &mut [u8]) -> Result<(), InvalidBufferSize>
Write result into provided array and consume the hasher instance. Read more
Source§fn finalize_into_reset(
&mut self,
out: &mut [u8],
) -> Result<(), InvalidBufferSize>
fn finalize_into_reset( &mut self, out: &mut [u8], ) -> Result<(), InvalidBufferSize>
Write result into provided array and reset the hasher instance. Read more
Source§fn output_size(&self) -> usize
fn output_size(&self) -> usize
Get output size of the hasher
Source§fn finalize_reset(&mut self) -> Box<[u8]>
fn finalize_reset(&mut self) -> Box<[u8]>
Retrieve result and reset hasher instance
Source§impl Write for Digest
Available on crate feature std only.
impl Write for Digest
Available on crate feature
std only.Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Attempts to write an entire buffer into this writer. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored)Attempts to write multiple buffers into this writer. Read more
impl Copy for Digest
Auto Trait Implementations§
impl Freeze for Digest
impl RefUnwindSafe for Digest
impl Send for Digest
impl Sync for Digest
impl Unpin for Digest
impl UnwindSafe for Digest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more