SkMD5.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright 2012 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkMD5_DEFINED
  8. #define SkMD5_DEFINED
  9. #include "include/core/SkStream.h"
  10. #include "include/private/SkTo.h"
  11. /* Calculate a 128-bit MD5 message-digest of the bytes sent to this stream. */
  12. class SkMD5 : public SkWStream {
  13. public:
  14. SkMD5();
  15. /** Processes input, adding it to the digest.
  16. Calling this after finish is undefined. */
  17. bool write(const void* buffer, size_t size) final;
  18. size_t bytesWritten() const final { return SkToSizeT(this->byteCount); }
  19. struct Digest {
  20. uint8_t data[16];
  21. bool operator ==(Digest const& other) const {
  22. return 0 == memcmp(data, other.data, sizeof(data));
  23. }
  24. bool operator !=(Digest const& other) const { return !(*this == other); }
  25. };
  26. /** Computes and returns the digest. */
  27. Digest finish();
  28. private:
  29. uint64_t byteCount; // number of bytes, modulo 2^64
  30. uint32_t state[4]; // state (ABCD)
  31. uint8_t buffer[64]; // input buffer
  32. };
  33. #endif