gix_features/hash.rs
1//! Hash functions and hash utilities
2
3/// Compute a CRC32 hash from the given `bytes`, returning the CRC32 hash.
4///
5/// When calling this function for the first time, `previous_value` should be `0`.
6/// Otherwise, it should be the previous return value of this function to provide a hash
7/// of multiple sequential chunks of `bytes`.
8#[cfg(feature = "crc32")]
9pub fn crc32_update(previous_value: u32, bytes: &[u8]) -> u32 {
10 let mut h = crc32fast::Hasher::new_with_initial(previous_value);
11 h.update(bytes);
12 h.finalize()
13}
14
15/// Compute a CRC32 value of the given input `bytes`.
16///
17/// In case multiple chunks of `bytes` are present, one should use [`crc32_update()`] instead.
18#[cfg(feature = "crc32")]
19pub fn crc32(bytes: &[u8]) -> u32 {
20 let mut h = crc32fast::Hasher::new();
21 h.update(bytes);
22 h.finalize()
23}