|
|
@ -220,25 +220,34 @@ static void Checksum(Span<const uint8_t> addr_pubkey, uint8_t (&checksum)[CHECKS |
|
|
|
|
|
|
|
}; // namespace torv3
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a TOR address and set this object to it. |
|
|
|
* |
|
|
|
* @returns Whether or not the operation was successful. |
|
|
|
* |
|
|
|
* @see CNetAddr::IsTor() |
|
|
|
*/ |
|
|
|
bool CNetAddr::SetSpecial(const std::string& str) |
|
|
|
bool CNetAddr::SetSpecial(const std::string& addr) |
|
|
|
{ |
|
|
|
if (!ValidAsCString(addr)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (SetTor(addr)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (SetI2P(addr)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
bool CNetAddr::SetTor(const std::string& addr) |
|
|
|
{ |
|
|
|
static const char* suffix{".onion"}; |
|
|
|
static constexpr size_t suffix_len{6}; |
|
|
|
|
|
|
|
if (!ValidAsCString(str) || str.size() <= suffix_len || |
|
|
|
str.substr(str.size() - suffix_len) != suffix) { |
|
|
|
if (addr.size() <= suffix_len || addr.substr(addr.size() - suffix_len) != suffix) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
bool invalid; |
|
|
|
const auto& input = DecodeBase32(str.substr(0, str.size() - suffix_len).c_str(), &invalid); |
|
|
|
const auto& input = DecodeBase32(addr.substr(0, addr.size() - suffix_len).c_str(), &invalid); |
|
|
|
|
|
|
|
if (invalid) { |
|
|
|
return false; |
|
|
|