mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-02 03:40:12 +00:00
31 lines
691 B
C++
31 lines
691 B
C++
#include <service/address.hpp>
|
|
|
|
#include <algorithm>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace service
|
|
{
|
|
std::string
|
|
Address::ToString(const char* tld) const
|
|
{
|
|
char tmp[(1 + 32) * 2] = {0};
|
|
std::string str = Base32Encode(*this, tmp);
|
|
return str + tld;
|
|
}
|
|
|
|
bool
|
|
Address::FromString(const std::string& str, const char* tld)
|
|
{
|
|
auto pos = str.find(tld);
|
|
if(pos == std::string::npos)
|
|
return false;
|
|
auto sub = str.substr(0, pos);
|
|
// make sure it's lowercase
|
|
std::transform(sub.begin(), sub.end(), sub.begin(), ::tolower);
|
|
|
|
return Base32Decode(sub, *this);
|
|
}
|
|
} // namespace service
|
|
} // namespace llarp
|