MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / SwapBase64

Function SwapBase64

src/i2p.cpp:42–66  ·  view source on GitHub ↗

* Swap Standard Base64 <-> I2P Base64. * Standard Base64 uses `+` and `/` as last two characters of its alphabet. * I2P Base64 uses `-` and `~` respectively. * So it is easy to detect in which one is the input and convert to the other. * @param[in] from Input to convert. * @return converted `from` */

Source from the content-addressed store, hash-verified

40 * @return converted `from`
41 */
42static std::string SwapBase64(const std::string& from)
43{
44 std::string to;
45 to.resize(from.size());
46 for (size_t i = 0; i < from.size(); ++i) {
47 switch (from[i]) {
48 case '-':
49 to[i] = '+';
50 break;
51 case '~':
52 to[i] = '/';
53 break;
54 case '+':
55 to[i] = '-';
56 break;
57 case '/':
58 to[i] = '~';
59 break;
60 default:
61 to[i] = from[i];
62 break;
63 }
64 }
65 return to;
66}
67
68/**
69 * Decode an I2P-style Base64 string.

Callers 2

DecodeI2PBase64Function · 0.85

Calls 2

resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected