* Derive the .b32.i2p address of an I2P destination (binary). * @param[in] dest I2P destination. * @return the address that corresponds to `dest` * @throw std::runtime_error if conversion fails */
| 84 | * @throw std::runtime_error if conversion fails |
| 85 | */ |
| 86 | static CNetAddr DestBinToAddr(const Binary& dest) |
| 87 | { |
| 88 | CSHA256 hasher; |
| 89 | hasher.Write(dest.data(), dest.size()); |
| 90 | unsigned char hash[CSHA256::OUTPUT_SIZE]; |
| 91 | hasher.Finalize(hash); |
| 92 | |
| 93 | CNetAddr addr; |
| 94 | const std::string addr_str = EncodeBase32(hash, false) + ".b32.i2p"; |
| 95 | if (!addr.SetSpecial(addr_str)) { |
| 96 | throw std::runtime_error(strprintf("Cannot parse I2P address: \"%s\"", addr_str)); |
| 97 | } |
| 98 | |
| 99 | return addr; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Derive the .b32.i2p address of an I2P destination (I2P-style Base64). |
no test coverage detected