You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/include/llarp/service/tag.hpp

55 lines
1017 B
C++

#ifndef LLARP_SERVICE_TAG_HPP
#define LLARP_SERVICE_TAG_HPP
6 years ago
#include <sodium/crypto_generichash.h>
#include <llarp/aligned.hpp>
6 years ago
#include <llarp/dht/key.hpp>
namespace llarp
{
namespace service
{
struct Tag : public llarp::AlignedBuffer< 16 >
{
Tag() : llarp::AlignedBuffer< 16 >()
{
Zero();
}
Tag(const byte_t* d) : llarp::AlignedBuffer< 16 >(d)
{
}
Tag(const std::string& str) : Tag()
{
#ifndef MIN
6 years ago
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
6 years ago
memcpy(data(), str.c_str(), MIN(16UL, str.size()));
6 years ago
#undef MIN
#endif
}
llarp::dht::Key_t
Key() const
6 years ago
{
llarp::dht::Key_t k;
crypto_generichash(k, 32, data(), 16, nullptr, 0);
return k;
}
std::string
ToString() const;
6 years ago
struct Hash
{
std::size_t
operator()(const Tag& t) const
{
return *t.data_l();
}
};
};
} // namespace service
} // namespace llarp
#endif