lokinet/llarp/service/address.cpp

30 lines
679 B
C++
Raw Normal View History

#include <algorithm>
2018-08-17 10:40:14 +00:00
#include <llarp/service/address.hpp>
2018-07-16 03:32:13 +00:00
namespace llarp
{
namespace service
{
std::string
Address::ToString() const
{
char tmp[(1 + 32) * 2] = {0};
std::string str = Base32Encode(*this, tmp);
return str + ".loki";
}
bool
Address::FromString(const std::string& str)
{
auto pos = str.find(".loki");
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);
;
return Base32Decode(sub, *this);
}
2018-07-16 03:32:13 +00:00
} // namespace service
} // namespace llarp