1 | // |
2 | // Checksum32.cpp |
3 | // |
4 | // Library: Foundation |
5 | // Package: Core |
6 | // Module: Checksum32 |
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/Checksum32.h" |
16 | #if defined(POCO_UNBUNDLED_ZLIB) |
17 | #include <zlib.h> |
18 | #else |
19 | #include "Poco/zlib.h" |
20 | #endif |
21 | |
22 | |
23 | namespace Poco { |
24 | |
25 | |
26 | Checksum32::Checksum32(): |
27 | _type(TYPE_CRC32_IMPL), |
28 | _value(crc32(0L, Z_NULL, 0)) |
29 | { |
30 | } |
31 | |
32 | |
33 | Checksum32::Checksum32(ChecksumImpl::Type t): |
34 | _type(t), |
35 | _value(0) |
36 | { |
37 | if (t == TYPE_CRC32_IMPL) |
38 | _value = crc32(0L, Z_NULL, 0); |
39 | else |
40 | _value = adler32(0L, Z_NULL, 0); |
41 | } |
42 | |
43 | |
44 | Checksum32::~Checksum32() |
45 | { |
46 | } |
47 | |
48 | |
49 | void Checksum32::update(const char* data, unsigned length) |
50 | { |
51 | if (_type == TYPE_ADLER32_IMPL) |
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 | |