* 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` */
| 35 | * @return converted `from` |
| 36 | */ |
| 37 | static 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. |
no test coverage detected