Debian Codegraph @

Source/7zip/Common/CRC.h

raw
1 /*
2 * CRC.h
3 *
4 * This file is a part of LZMA compression module for NSIS.
5 *
6 * Original LZMA SDK Copyright (C) 1999-2006 Igor Pavlov
7 * Modifications Copyright (C) 2003-2026 Amir Szekely <[email protected]>
8 *
9 * Licensed under the Common Public License version 1.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 *
12 * Licence details can be found in the file COPYING.
13 *
14 * This software is provided 'as-is', without any express or implied
15 * warranty.
16 *
17 * Reviewed for Unicode support by Jim Park -- 08/28/2007
18 */
19
20 #ifndef __COMMON_CRC_H
21 #define __COMMON_CRC_H
22
23 #include <stddef.h>
24 #include "Types.h"
25
26 class CCRC
27 {
28 UInt32 _value;
29 public:
30 static UInt32 Table[256];
31 static void InitTable();
32
33 CCRC(): _value(0xFFFFFFFF){};
34 void Init() { _value = 0xFFFFFFFF; }
35 void UpdateByte(Byte v);
36 void UpdateUInt16(UInt16 v);
37 void UpdateUInt32(UInt32 v);
38 void UpdateUInt64(UInt64 v);
39 void Update(const void *data, size_t size);
40 UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
41 static UInt32 CalculateDigest(const void *data, size_t size)
42 {
43 CCRC crc;
44 crc.Update(data, size);
45 return crc.GetDigest();
46 }
47 static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
48 {
49 return (CalculateDigest(data, size) == digest);
50 }
51 };
52
53 #endif