Fix: Header crc calculation
Signed-off-by: Thomas Klaehn <tkl@blackfinn.de>
This commit is contained in:
@@ -54,10 +54,12 @@ func ParseHeader(data []byte) (*Header, error) {
|
|||||||
if h.Size == HeaderWithCRCSize {
|
if h.Size == HeaderWithCRCSize {
|
||||||
h.CRC = binary.LittleEndian.Uint16(data[12:14])
|
h.CRC = binary.LittleEndian.Uint16(data[12:14])
|
||||||
|
|
||||||
// Validate header CRC
|
// Validate header CRC (skip if CRC is 0x0000, which means "no validation")
|
||||||
calculatedCRC := CalculateCRC(data[0:12])
|
if h.CRC != 0x0000 {
|
||||||
if calculatedCRC != h.CRC {
|
calculatedCRC := CalculateCRC(data[0:12])
|
||||||
return nil, fmt.Errorf("header CRC mismatch: got 0x%04X, expected 0x%04X", h.CRC, calculatedCRC)
|
if calculatedCRC != h.CRC {
|
||||||
|
return nil, fmt.Errorf("header CRC mismatch: got 0x%04X, expected 0x%04X", h.CRC, calculatedCRC)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user