MCPcopy Create free account
hub / github.com/ElementsProject/elements / SetTor

Method SetTor

src/netaddress.cpp:229–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229bool CNetAddr::SetTor(const std::string& addr)
230{
231 static const char* suffix{".onion"};
232 static constexpr size_t suffix_len{6};
233
234 if (addr.size() <= suffix_len || addr.substr(addr.size() - suffix_len) != suffix) {
235 return false;
236 }
237
238 bool invalid;
239 const auto& input = DecodeBase32(addr.substr(0, addr.size() - suffix_len).c_str(), &invalid);
240
241 if (invalid) {
242 return false;
243 }
244
245 if (input.size() == torv3::TOTAL_LEN) {
246 Span<const uint8_t> input_pubkey{input.data(), ADDR_TORV3_SIZE};
247 Span<const uint8_t> input_checksum{input.data() + ADDR_TORV3_SIZE, torv3::CHECKSUM_LEN};
248 Span<const uint8_t> input_version{input.data() + ADDR_TORV3_SIZE + torv3::CHECKSUM_LEN, sizeof(torv3::VERSION)};
249
250 if (input_version != torv3::VERSION) {
251 return false;
252 }
253
254 uint8_t calculated_checksum[torv3::CHECKSUM_LEN];
255 torv3::Checksum(input_pubkey, calculated_checksum);
256
257 if (input_checksum != calculated_checksum) {
258 return false;
259 }
260
261 m_net = NET_ONION;
262 m_addr.assign(input_pubkey.begin(), input_pubkey.end());
263 return true;
264 }
265
266 return false;
267}
268
269bool CNetAddr::SetI2P(const std::string& addr)
270{

Callers

nothing calls this directly

Calls 7

DecodeBase32Function · 0.85
ChecksumFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45
assignMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected