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

Function SwapBase64

src/i2p.cpp:37–61  ·  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

35 * @return converted `from`
36 */
37static std::string SwapBase64(const std::string& from)
38{
39 std::string to;
40 to.resize(from.size());
41 for (size_t i = 0; i < from.size(); ++i) {
42 switch (from[i]) {
43 case '-':
44 to[i] = '+';
45 break;
46 case '~':
47 to[i] = '/';
48 break;
49 case '+':
50 to[i] = '-';
51 break;
52 case '/':
53 to[i] = '~';
54 break;
55 default:
56 to[i] = from[i];
57 break;
58 }
59 }
60 return to;
61}
62
63/**
64 * 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