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