Checksum.cpp 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Checksum.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Checksum.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Core
  8. // Module: Checksum
  9. //
  10. // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  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. namespace Poco {
  22. Checksum::Checksum():
  23. _type(TYPE_CRC32),
  24. _value(crc32(0L, Z_NULL, 0))
  25. {
  26. }
  27. Checksum::Checksum(Type t):
  28. _type(t),
  29. _value(0)
  30. {
  31. if (t == TYPE_CRC32)
  32. _value = crc32(0L, Z_NULL, 0);
  33. else
  34. _value = adler32(0L, Z_NULL, 0);
  35. }
  36. Checksum::~Checksum()
  37. {
  38. }
  39. void Checksum::update(const char* data, unsigned length)
  40. {
  41. if (_type == TYPE_ADLER32)
  42. _value = adler32(_value, reinterpret_cast<const Bytef*>(data), length);
  43. else
  44. _value = crc32(_value, reinterpret_cast<const Bytef*>(data), length);
  45. }
  46. } // namespace Poco