use crc::{Crc, CRC_32_ISCSI};
const CRC32C: Crc<u32> = Crc::<u32>::new(&CRC_32_ISCSI);
pub fn crc(data: &[u8]) -> u32 {
let c = CRC32C.checksum(data);
c.rotate_right(15).wrapping_add(0xa282ead8)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_crc_empty() {
let result = crc(&[]);
assert_ne!(result, 0);
}
#[test]
fn test_crc_consistency() {
let data = b"Hello, World!";
let crc1 = crc(data);
let crc2 = crc(data);
assert_eq!(crc1, crc2, "CRC should be deterministic");
}
#[test]
fn test_crc_different_data() {
let data1 = b"Hello";
let data2 = b"World";
let crc1 = crc(data1);
let crc2 = crc(data2);
assert_ne!(crc1, crc2, "Different data should produce different CRCs");
}
}