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