lokinet/llarp/service/tag.hpp

77 lines
1.6 KiB
C++
Raw Normal View History

2018-07-17 07:30:03 +00:00
#ifndef LLARP_SERVICE_TAG_HPP
#define LLARP_SERVICE_TAG_HPP
2018-12-12 00:48:54 +00:00
#include <dht/key.hpp>
#include <util/aligned.hpp>
2019-02-11 17:14:43 +00:00
#include <util/status.hpp>
2018-07-17 07:30:03 +00:00
#include <sodium/crypto_generichash.h>
2018-10-23 00:56:53 +00:00
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
2018-07-17 07:30:03 +00:00
namespace llarp
{
namespace service
{
2019-04-19 15:10:26 +00:00
struct Tag : public llarp::AlignedBuffer< 16 >
2018-07-17 07:30:03 +00:00
{
Tag() : llarp::AlignedBuffer< SIZE >()
2018-07-17 07:30:03 +00:00
{
}
Tag(const byte_t* d) : llarp::AlignedBuffer< SIZE >(d)
2018-07-17 07:30:03 +00:00
{
}
Tag(const std::string& str) : Tag()
{
2018-10-23 00:56:53 +00:00
// evidently, does nothing on LP64 systems (where size_t is *already*
// unsigned long but zero-extends this on LLP64 systems
// 2Jan19: reeee someone undid the patch
2019-01-19 01:04:47 +00:00
std::copy(
str.begin(),
str.begin() + std::min(std::string::size_type(16), str.size()),
begin());
2018-07-17 07:30:03 +00:00
}
2018-08-10 03:51:38 +00:00
Tag&
operator=(const Tag& other)
{
as_array() = other.as_array();
2018-08-10 03:51:38 +00:00
return *this;
}
2018-08-10 21:34:11 +00:00
Tag&
operator=(const std::string& str)
2018-07-18 03:10:21 +00:00
{
2019-01-19 01:04:47 +00:00
std::copy(
str.begin(),
str.begin() + std::min(std::string::size_type(16), str.size()),
begin());
2018-08-10 21:34:11 +00:00
return *this;
2018-07-18 03:10:21 +00:00
}
2019-02-11 17:14:43 +00:00
util::StatusObject
2019-04-19 15:10:26 +00:00
ExtractStatus() const
2019-02-11 17:14:43 +00:00
{
return util::StatusObject{{"name", ToString()}};
}
2018-07-17 07:30:03 +00:00
std::string
ToString() const;
2018-07-18 03:10:21 +00:00
2018-08-10 21:34:11 +00:00
bool
Empty() const
{
2019-02-20 13:28:35 +00:00
return data()[0] == 0;
2018-08-10 21:34:11 +00:00
}
using Hash = AlignedBuffer< SIZE >::Hash;
2018-07-17 07:30:03 +00:00
};
} // namespace service
} // namespace llarp
#endif