| 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 "SkTypes.h" | |
| 12 #include "SkEndian.h" | |
| 13 #include "SkStream.h" | 11 #include "SkStream.h" |
| 14 | 12 |
| 15 //The following macros can be defined to affect the MD5 code generated. | 13 /* Calculate a 128-bit MD5 message-digest of the bytes sent to this stream. */ |
| 16 //SK_MD5_CLEAR_DATA causes all intermediate state to be overwritten with 0's. | |
| 17 //SK_CPU_LENDIAN allows 32 bit <=> 8 bit conversions without copies (if alligned
). | |
| 18 //SK_CPU_FAST_UNALIGNED_ACCESS allows 32 bit <=> 8 bit conversions without copie
s if SK_CPU_LENDIAN. | |
| 19 | |
| 20 class SkMD5 : public SkWStream { | 14 class SkMD5 : public SkWStream { |
| 21 public: | 15 public: |
| 22 SkMD5(); | 16 SkMD5(); |
| 23 | 17 |
| 24 /** Processes input, adding it to the digest. | 18 /** Processes input, adding it to the digest. |
| 25 * Note that this treats the buffer as a series of uint8_t values. | 19 Calling this after finish is undefined. */ |
| 26 */ | 20 bool write(const void* buffer, size_t size) final; |
| 27 bool write(const void* buffer, size_t size) override { | |
| 28 this->update(reinterpret_cast<const uint8_t*>(buffer), size); | |
| 29 return true; | |
| 30 } | |
| 31 | 21 |
| 32 size_t bytesWritten() const override { return SkToSizeT(this->byteCount); } | 22 size_t bytesWritten() const final { return SkToSizeT(this->byteCount); } |
| 33 | 23 |
| 34 /** Processes input, adding it to the digest. Calling this after finish is u
ndefined. */ | 24 /** Alias for write() */ |
| 35 void update(const uint8_t* input, size_t length); | 25 void update(const uint8_t* b, size_t l) { (void)this->write(b, l); } |
| 36 | 26 |
| 37 struct Digest { | 27 struct Digest { |
| 38 uint8_t data[16]; | 28 uint8_t data[16]; |
| 39 bool operator ==(Digest const& other) const { | 29 bool operator ==(Digest const& other) const { |
| 40 return 0 == memcmp(data, other.data, sizeof(data)); | 30 return 0 == memcmp(data, other.data, sizeof(data)); |
| 41 } | 31 } |
| 42 bool operator !=(Digest const& other) const { | 32 bool operator !=(Digest const& other) const { return !(*this == other);
} |
| 43 return 0 != memcmp(data, other.data, sizeof(data)); | |
| 44 } | |
| 45 }; | 33 }; |
| 46 | 34 |
| 47 /** Computes and returns the digest. */ | 35 /** Computes and returns the digest. */ |
| 48 void finish(Digest& digest); | 36 void finish(Digest& digest); |
| 49 | 37 |
| 50 private: | 38 private: |
| 51 // number of bytes, modulo 2^64 | 39 uint64_t byteCount; // number of bytes, modulo 2^64 |
| 52 uint64_t byteCount; | 40 uint32_t state[4]; // state (ABCD) |
| 53 | 41 uint8_t buffer[64]; // input buffer |
| 54 // state (ABCD) | |
| 55 uint32_t state[4]; | |
| 56 | |
| 57 // input buffer | |
| 58 uint8_t buffer[64]; | |
| 59 }; | 42 }; |
| 60 | 43 |
| 61 #endif | 44 #endif |
| OLD | NEW |