other-licenses/7zstub/src/Common/CRC.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/Common/CRC.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +// Common/CRC.h
     1.5 +
     1.6 +#ifndef __COMMON_CRC_H
     1.7 +#define __COMMON_CRC_H
     1.8 +
     1.9 +#include <stddef.h>
    1.10 +#include "Types.h"
    1.11 +
    1.12 +class CCRC
    1.13 +{
    1.14 +  UInt32 _value;
    1.15 +public:
    1.16 +	static UInt32 Table[256];
    1.17 +	static void InitTable();
    1.18 +
    1.19 +  CCRC():  _value(0xFFFFFFFF){};
    1.20 +  void Init() { _value = 0xFFFFFFFF; }
    1.21 +  void UpdateByte(Byte v);
    1.22 +  void UpdateUInt16(UInt16 v);
    1.23 +  void UpdateUInt32(UInt32 v);
    1.24 +  void UpdateUInt64(UInt64 v);
    1.25 +  void Update(const void *data, size_t size);
    1.26 +  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } 
    1.27 +  static UInt32 CalculateDigest(const void *data, size_t size)
    1.28 +  {
    1.29 +    CCRC crc;
    1.30 +    crc.Update(data, size);
    1.31 +    return crc.GetDigest();
    1.32 +  }
    1.33 +  static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
    1.34 +  {
    1.35 +    return (CalculateDigest(data, size) == digest);
    1.36 +  }
    1.37 +};
    1.38 +
    1.39 +#endif

mercurial