blob: b0bd64369510c8af1773cbac314c13bc1dfb521e (
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
38
39
40
41
42
43
|
#include "../include/sibs/PubsubKey.hpp"
namespace sibs
{
static const char *HEX_TABLE = "0123456789abcdef";
PubsubKey::PubsubKey() :
data({})
{
}
PubsubKey::PubsubKey(const void *data, const usize size)
{
usize _size = std::min(size, PUBSUB_KEY_LENGTH);
std::copy((char*)data, (char*)data + _size, this->data.begin());
if(size < PUBSUB_KEY_LENGTH)
std::fill_n(this->data.begin() + size, PUBSUB_KEY_LENGTH - size, 0);
}
bool PubsubKey::operator == (const PubsubKey &other) const
{
return data == other.data;
}
bool PubsubKey::operator != (const PubsubKey &other) const
{
return data != other.data;
}
std::string PubsubKey::toString() const
{
std::string result;
result.reserve(data.size() * 2);
for(usize i = 0; i < data.size(); ++i)
{
u8 c = data[i];
result += HEX_TABLE[(c & 0xF0) >> 4];
result += HEX_TABLE[c & 0x0F];
}
return result;
}
}
|