/src/gitoxide/gix-features/src/hash.rs
Line | Count | Source |
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")] |
9 | 0 | pub fn crc32_update(previous_value: u32, bytes: &[u8]) -> u32 { |
10 | 0 | let mut h = crc32fast::Hasher::new_with_initial(previous_value); |
11 | 0 | h.update(bytes); |
12 | 0 | h.finalize() |
13 | 0 | } |
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")] |
19 | 3.05k | pub fn crc32(bytes: &[u8]) -> u32 { |
20 | 3.05k | let mut h = crc32fast::Hasher::new(); |
21 | 3.05k | h.update(bytes); |
22 | 3.05k | h.finalize() |
23 | 3.05k | } |