diff --git a/crates/crc/src/crc_32.rs b/crates/crc/src/crc_32.rs index 614daa5..e0e0c3f 100755 --- a/crates/crc/src/crc_32.rs +++ b/crates/crc/src/crc_32.rs @@ -44,7 +44,6 @@ pub const CRC32_INIT: u32 = 0xffffffff; /// Implements CRC-32/ISO-HDLC with look up table pub struct Crc32(::Checksum); -impl Crc32 {} impl Crc for Crc32 { type Input = [u8]; type Checksum = u32; @@ -74,10 +73,8 @@ mod tests { #[test] fn test_check() { - let mut c = Crc32::new(); - c.process(&CHECK_DATA); // see https://reveng.sourceforge.io/crc-catalogue/17plus.htm#crc.cat-bits.32 for the check // value - assert_eq!(*c.shift_reg(), 0xCBF43926); + assert_eq!(Crc32::checksum(&CHECK_DATA), 0xCBF43926); } } diff --git a/crates/crc/src/lib.rs b/crates/crc/src/lib.rs index e61b73e..cd32044 100755 --- a/crates/crc/src/lib.rs +++ b/crates/crc/src/lib.rs @@ -5,7 +5,7 @@ //! ## Acknowledgements //! //! Many thanks to the [crc-catalogue](https://reveng.sourceforge.io/crc-catalogue/) for providing -//! some test vectors. +//! an overview over the various algorithms with test vectors and examples. #![cfg_attr(not(test), no_std)] @@ -15,11 +15,16 @@ pub const CHECK_DATA: [u8; 9] = *b"123456789"; pub use crc_32::*; -pub trait Crc { +pub trait Crc: Sized { type Input: ?Sized; - type Checksum: Eq + Default; + type Checksum: Eq + Default + Copy; fn new() -> Self; fn process(&mut self, data: &Self::Input); fn shift_reg(&mut self) -> &mut Self::Checksum; + fn checksum(data: &Self::Input) -> Self::Checksum { + let mut c = Self::new(); + c.process(data); + *c.shift_reg() + } }