1 //
2 // Checksum.cpp
3 //
4 // Library: Foundation
5 // Package: Core
6 // Module: Checksum
7 //
8 // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
9 // and Contributors.
10 //
11 // SPDX-License-Identifier: BSL-1.0
12 //
13
14
15 #include "Poco/Checksum.h"
16 #if defined(POCO_UNBUNDLED)
17 #include <zlib.h>
18 #else
19 #include "Poco/zlib.h"
20 #endif
21
22
23 namespace Poco {
24
25
Checksum()26 Checksum::Checksum():
27 _type(TYPE_CRC32),
28 _value(crc32(0L, Z_NULL, 0))
29 {
30 }
31
32
Checksum(Type t)33 Checksum::Checksum(Type t):
34 _type(t),
35 _value(0)
36 {
37 if (t == TYPE_CRC32)
38 _value = crc32(0L, Z_NULL, 0);
39 else
40 _value = adler32(0L, Z_NULL, 0);
41 }
42
43
~Checksum()44 Checksum::~Checksum()
45 {
46 }
47
48
update(const char * data,unsigned length)49 void Checksum::update(const char* data, unsigned length)
50 {
51 if (_type == TYPE_ADLER32)
52 _value = adler32(_value, reinterpret_cast<const Bytef*>(data), length);
53 else
54 _value = crc32(_value, reinterpret_cast<const Bytef*>(data), length);
55 }
56
57
58 } // namespace Poco
59