[go: up one dir, main page]

Crate crc

source ·
Expand description

crc

Rust implementation of CRC.

Examples

Using a well-known algorithm:

const X25: crc::Crc<u16> = crc::Crc::<u16>::new(&crc::CRC_16_IBM_SDLC);
assert_eq!(X25.checksum(b"123456789"), 0x906e);

Using a custom algorithm:

const CUSTOM_ALG: crc::Algorithm<u16> = crc::Algorithm {
    width: 16,
    poly: 0x8005,
    init: 0xffff,
    refin: false,
    refout: false,
    xorout: 0x0000,
    check: 0xaee7,
    residue: 0x0000
};
let crc = crc::Crc::<u16>::new(&CUSTOM_ALG);
let mut digest = crc.digest();
digest.update(b"123456789");
assert_eq!(digest.finalize(), 0xaee7);

Modules

  • CRC algorithms as structs.
  • CRC polynomials and their aliases.

Structs

  • This struct describes a CRC algorithm using the fields specified by the Catalogue of parametrised CRC algorithms.
  • Implementation using a 256 entry lookup table. Use it with Crc<Bytewise<W>>
  • Crc with pluggable implementations ([Nolookup], Bytewise, Slice16). To choose the default implementation, use the Width directly (e.g. Crc<u32>).
  • Implementation using no lookup table. Use it with Crc<Nolookup<W>>
  • Implementation using a 16 * 256 entry lookup table. Use it with Crc<Slice16<W>>

Constants

Traits