Xor-el / HashLib4Pascal

Hashing for Modern Object Pascal
MIT License
220 stars 80 forks source link

CRC8 Exception #23

Closed hafedh-trimeche closed 2 years ago

hafedh-trimeche commented 2 years ago

Invoking this function generated an exception:

function CRC8(const Buffer;const Size:Integer):UInt8;
var
  CRC : IHash;
begin
  if @Buffer=nil then Exit(0);
  CRC    := THashFactory.TChecksum.TCRC.CreateCRC(HlpCRC.CRC8);
  Result := CRC.ComputeUntyped(Buffer,Size).GetUInt8;
end;

Exception class EInvalidOperationHashLibException with message 'The size of the byte array (2) and integer type (1) have to match.'.

Best regards.

Xor-el commented 2 years ago

Hi, CRC8 can not fit into a byte since it is an Int16/UInt16. I suggest you use the GetUInt16 overload.