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

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 // Common/CRC.h
michael@0 2
michael@0 3 #ifndef __COMMON_CRC_H
michael@0 4 #define __COMMON_CRC_H
michael@0 5
michael@0 6 #include <stddef.h>
michael@0 7 #include "Types.h"
michael@0 8
michael@0 9 class CCRC
michael@0 10 {
michael@0 11 UInt32 _value;
michael@0 12 public:
michael@0 13 static UInt32 Table[256];
michael@0 14 static void InitTable();
michael@0 15
michael@0 16 CCRC(): _value(0xFFFFFFFF){};
michael@0 17 void Init() { _value = 0xFFFFFFFF; }
michael@0 18 void UpdateByte(Byte v);
michael@0 19 void UpdateUInt16(UInt16 v);
michael@0 20 void UpdateUInt32(UInt32 v);
michael@0 21 void UpdateUInt64(UInt64 v);
michael@0 22 void Update(const void *data, size_t size);
michael@0 23 UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
michael@0 24 static UInt32 CalculateDigest(const void *data, size_t size)
michael@0 25 {
michael@0 26 CCRC crc;
michael@0 27 crc.Update(data, size);
michael@0 28 return crc.GetDigest();
michael@0 29 }
michael@0 30 static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
michael@0 31 {
michael@0 32 return (CalculateDigest(data, size) == digest);
michael@0 33 }
michael@0 34 };
michael@0 35
michael@0 36 #endif

mercurial