| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
pub mod algorithm; |
| 6 |
pub mod consts; |
| 7 |
pub(crate) mod width32_ops; |
| 8 |
|
| 9 |
#[cfg(all( |
| 10 |
feature = "std", |
| 11 |
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64") |
| 12 |
))] |
| 13 |
pub(crate) mod fusion; |
| 14 |
|
| 15 |
#[cfg(test)] |
| 16 |
mod property_tests { |
| 17 |
use crate::test::miri_compatible_proptest_config; |
| 18 |
use crate::{checksum, CrcAlgorithm}; |
| 19 |
use proptest::prelude::*; |
| 20 |
|
| 21 |
proptest! { |
| 22 |
#![proptest_config(miri_compatible_proptest_config())] |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#[test] |
| 30 |
fn prop_crc32_compatibility(data in proptest::collection::vec(any::<u8>(), 0..1024)) { |
| 31 |
use crate::test::consts::{RUST_CRC32_ISCSI, RUST_CRC32_ISO_HDLC, RUST_CRC32_BZIP2, RUST_CRC32_MPEG_2}; |
| 32 |
|
| 33 |
|
| 34 |
let our_iscsi = checksum(CrcAlgorithm::Crc32Iscsi, &data); |
| 35 |
let ref_iscsi = RUST_CRC32_ISCSI.checksum(&data) as u64; |
| 36 |
prop_assert_eq!( |
| 37 |
our_iscsi, ref_iscsi, |
| 38 |
"CRC-32/ISCSI mismatch for {} bytes: our=0x{:08X}, ref=0x{:08X}", |
| 39 |
data.len(), our_iscsi, ref_iscsi |
| 40 |
); |
| 41 |
|
| 42 |
|
| 43 |
let our_hdlc = checksum(CrcAlgorithm::Crc32IsoHdlc, &data); |
| 44 |
let ref_hdlc = RUST_CRC32_ISO_HDLC.checksum(&data) as u64; |
| 45 |
prop_assert_eq!( |
| 46 |
our_hdlc, ref_hdlc, |
| 47 |
"CRC-32/ISO-HDLC mismatch for {} bytes: our=0x{:08X}, ref=0x{:08X}", |
| 48 |
data.len(), our_hdlc, ref_hdlc |
| 49 |
); |
| 50 |
|
| 51 |
|
| 52 |
let our_bzip2 = checksum(CrcAlgorithm::Crc32Bzip2, &data); |
| 53 |
let ref_bzip2 = RUST_CRC32_BZIP2.checksum(&data) as u64; |
| 54 |
prop_assert_eq!( |
| 55 |
our_bzip2, ref_bzip2, |
| 56 |
"CRC-32/BZIP2 mismatch for {} bytes: our=0x{:08X}, ref=0x{:08X}", |
| 57 |
data.len(), our_bzip2, ref_bzip2 |
| 58 |
); |
| 59 |
|
| 60 |
|
| 61 |
let our_mpeg2 = checksum(CrcAlgorithm::Crc32Mpeg2, &data); |
| 62 |
let ref_mpeg2 = RUST_CRC32_MPEG_2.checksum(&data) as u64; |
| 63 |
prop_assert_eq!( |
| 64 |
our_mpeg2, ref_mpeg2, |
| 65 |
"CRC-32/MPEG-2 mismatch for {} bytes: our=0x{:08X}, ref=0x{:08X}", |
| 66 |
data.len(), our_mpeg2, ref_mpeg2 |
| 67 |
); |
| 68 |
} |
| 69 |
} |
| 70 |
} |