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

70 lines
1.2 KiB
C++

#ifndef LLARP_SERVICE_TAG_HPP
#define LLARP_SERVICE_TAG_HPP
#include <sodium/crypto_generichash.h>
#include <llarp/aligned.hpp>
#include <llarp/dht/key.hpp>
namespace llarp
{
namespace service
{
struct Tag : public llarp::AlignedBuffer< 16 >
{
Tag() : llarp::AlignedBuffer< 16 >()
{
}
Tag(const byte_t* d) : llarp::AlignedBuffer< 16 >(d)
{
}
Tag(const std::string& str) : Tag()
{
#ifndef MIN
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
memcpy(data(), str.c_str(), MIN(16UL, str.size()));
#undef MIN
#endif
}
Tag&
operator=(const Tag& other)
{
memcpy(data(), other.data(), 16);
return *this;
}
Tag&
operator=(const std::string& str)
{
#ifndef MIN
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
memcpy(data(), str.data(), MIN(16UL, str.size()));
#undef MIN
#endif
return *this;
}
std::string
ToString() const;
bool
Empty() const
{
return ToString().empty();
}
struct Hash
{
std::size_t
operator()(const Tag& t) const
{
return *t.data_l();
}
};
};
} // namespace service
} // namespace llarp
#endif