1 /* 2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef CHECK_SUM_H 6 #define CHECK_SUM_H 7 8 9 #include <string.h> 10 11 #include <SHA256.h> 12 13 14 struct CheckSum { 15 const uint8* Data() const 16 { 17 return fData; 18 } 19 20 bool IsZero() const 21 { 22 for (size_t i = 0; i < sizeof(fData); i++) { 23 if (fData[i] != 0) 24 return false; 25 } 26 27 return true; 28 } 29 30 CheckSum& operator=(const CheckSum& other) 31 { 32 memcpy(fData, other.fData, sizeof(fData)); 33 return *this; 34 } 35 36 CheckSum& operator=(const void* buffer) 37 { 38 memcpy(fData, buffer, sizeof(fData)); 39 return *this; 40 } 41 42 bool operator==(const void* buffer) const 43 { 44 return memcmp(fData, buffer, sizeof(fData)) == 0; 45 } 46 47 bool operator!=(const void* buffer) const 48 { 49 return !(*this == buffer); 50 } 51 52 private: 53 uint8 fData[SHA_DIGEST_LENGTH]; 54 }; 55 56 57 #endif // CHECK_SUM_H 58