lokinet/llarp/service/address.cpp

31 lines
691 B
C++
Raw Normal View History

2018-12-12 02:15:08 +00:00
#include <service/address.hpp>
#include <algorithm>
2018-07-16 03:32:13 +00:00
namespace llarp
{
namespace service
{
std::string
2018-12-03 22:22:59 +00:00
Address::ToString(const char* tld) const
2018-07-16 03:32:13 +00:00
{
char tmp[(1 + 32) * 2] = {0};
std::string str = Base32Encode(*this, tmp);
2018-12-03 22:22:59 +00:00
return str + tld;
2018-07-16 03:32:13 +00:00
}
bool
2018-12-03 22:22:59 +00:00
Address::FromString(const std::string& str, const char* tld)
{
2018-12-03 22:22:59 +00:00
auto pos = str.find(tld);
if(pos == std::string::npos)
return false;
auto sub = str.substr(0, pos);
// make sure it's lowercase
2018-08-17 10:40:14 +00:00
std::transform(sub.begin(), sub.end(), sub.begin(), ::tolower);
2018-11-23 14:37:26 +00:00
return Base32Decode(sub, *this);
}
2018-07-16 03:32:13 +00:00
} // namespace service
} // namespace llarp