blob: 90e6e3172619762869d3c842472c8f34433aac5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include "../include/odhtdb/InfoHash.hpp"
#include <sodium/crypto_generichash_blake2b.h>
#include <sodium/core.h>
#include <algorithm>
namespace odhtdb
{
InfoHash::InfoHash()
{
}
InfoHash::InfoHash(const u8 *data, const size_t size) :
key(data, size)
{
}
InfoHash InfoHash::generateHash(const u8 *data, const size_t size)
{
InfoHash infoHash;
int result = crypto_generichash_blake2b((unsigned char*)&infoHash.key.data[0], infoHash.key.data.size(), (const unsigned char*)data, size, nullptr, 0);
if(result < 0)
throw InfoHashException("Failed to hash data using blake2b");
return infoHash;
}
bool InfoHash::operator == (const InfoHash &other) const
{
return key == other.key;
}
bool InfoHash::operator != (const InfoHash &other) const
{
return !(*this == other);
}
}
|