Exemple #1
0
func (c *crc16Validator) Checksum(data []byte) (rawCRC []byte) {
	// Calculate the CRC checksum of data.
	crc := crc16.Checksum(data, c.table)

	// Transform to a byte slice.
	rawCRC = make([]byte, 2)
	binary.LittleEndian.PutUint16(rawCRC, crc)

	return rawCRC
}
Exemple #2
0
func (c *crc16Validator) Validate(data []byte, rawCRC []byte) bool {
	// Convert the raw CRC byte slice.
	origCRC := binary.LittleEndian.Uint16(rawCRC)

	// Calculate the CRC checksum of data.
	crc := crc16.Checksum(data, c.table)

	// Compare the checksums.
	return crc == origCRC
}