00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __DSL_SODIUM_HASH__
00012 #define __DSL_SODIUM_HASH__
00013
00023 #define HASH_SIZE_BYTES (crypto_generichash_BYTES)
00024
00028 class DSL_SODIUM_API_CLASS DS_Hash {
00029 public:
00030 uint8_t hash[HASH_SIZE_BYTES];
00031
00032 DS_Hash();
00033
00034 vector<uint8_t> GetVector();
00035
00036 void SetNull();
00037 bool IsNull();
00038 bool IsValid();
00039
00040 bool SetFromHexString(string str);
00041 bool SetFromBinaryData(uint8_t * p_hash, size_t len);
00042
00043 bool operator == (const DS_Hash &b) const {
00044 return (memcmp(hash, b.hash, HASH_SIZE_BYTES) == 0) ? true : false;
00045 }
00046 bool operator != (const DS_Hash &b) const {
00047 return (memcmp(hash, b.hash, HASH_SIZE_BYTES) != 0) ? true : false;
00048 }
00049 bool operator < (const DS_Hash &b) const {
00050 if (memcmp(hash, b.hash, HASH_SIZE_BYTES) < 0) {
00051 return true;
00052 }
00053 return false;
00054 }
00055 };
00056 extern DSL_SODIUM_API_CLASS DS_Hash null_hash;
00057
00062 class DSL_SODIUM_API_CLASS DS_Hasher : public DS_Hash {
00063 public:
00064
00065 DS_Hasher();
00066 DS_Hasher(const uint8_t * data, size_t len);
00067 DS_Hasher(vector<uint8_t>& data);
00068
00069 DS_Hash HashData(const uint8_t * data, size_t len);
00070 DS_Hash HashData(vector<uint8_t>& data);
00071 };
00072
00075 #endif // __DSL_SODIUM_HASH__