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