#crc #check #cyclic #own #endian #byte #redundancy

无std mycrc

创建自己的循环冗余校验(CRC)

4个版本 (2个重大更改)

0.3.1 2021年8月11日
0.3.0 2021年8月11日
0.2.0 2021年8月9日
0.1.0 2021年8月8日

#1911 in 算法


用于 floaout

MIT/Apache

24KB
453

My CRC

Crate API

创建自己的循环冗余校验(CRC)。

入门

  1. 使用CRC::new创建自己的CRC。
  2. 从消息创建校验和。
  3. 使用CRC::is_error_free_bytes检查bytes [消息 + 校验和] 是否无错误。

示例

use mycrc::{CRC, Endian};

// message
const CHECK_BYTES: &[u8] = b"123456789";

// Create your own CRC.
let mut crc32c = CRC::<u32>::new(
    Endian::Little, // endian
    0x1edc6f41, // poly
    0xffffffff, // init
    true, // refin
    true, // refout
    0xffffffff, // xorout
);

// Checksum
assert_eq!(crc32c.checksum(CHECK_BYTES), 0xe3069283);
// Is error-free?
let checksum = crc32c.checksum_to_endian_bytes(CHECK_BYTES);
let bytes = [CHECK_BYTES, &checksum].concat();
assert!(crc32c.is_error_free_bytes(&bytes));

无运行时依赖