* 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` */
| 40 | * @return converted `from` |
| 41 | */ |
| 42 | static 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. |
no test coverage detected