Function crc8_rs::has_valid_crc8 [−][src]
pub fn has_valid_crc8<const DATA_SIZE: usize>(
data: [u8; DATA_SIZE],
polynomial: u8
) -> bool
Determine whether a data
buffer for a given generator polynomial
has a valid CRC.
Will fetch the CRC value for the data
buffer under the generator polynomial
and return
whether it equals zero, which indicates the integrity of the data. It is a short hand for
fetch_crc8(data, polynomial) == 0
.
Examples
use crc8_rs::{ has_valid_crc8, insert_crc8 }; const GENERATOR_POLYNOMIAL: u8 = 0xD5; // We add an empty byte at the end for the CRC let msg = b"Hello World!\0"; let msg = insert_crc8(*msg, GENERATOR_POLYNOMIAL); // Will verify just fine! assert!(has_valid_crc8(msg, GENERATOR_POLYNOMIAL)); let corrupted_msg = { let mut tmp_msg = msg; tmp_msg[1] = b'a'; tmp_msg }; // The message is now corrupted and thus it can't verify the integrity! assert!(!has_valid_crc8(corrupted_msg, GENERATOR_POLYNOMIAL));
Panics
The function will panic if given a zero-sized buffer. As can be seen in the following example.
ⓘ
use crc8_rs::has_valid_crc8; has_valid_crc8([], 0x42);