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.

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

mercurial