Change base64 decoder name, and add util for removing newlines

This commit is contained in:
kannibalox
2024-11-02 12:35:36 -04:00
committed by Jari Sundell
parent 687fbbb83d
commit 0658486966
2 changed files with 14 additions and 8 deletions
+13 -3
View File
@@ -4,12 +4,22 @@
namespace utils {
std::string
remove_newlines(const std::string& str) {
std::string result;
for (auto &itr : str) {
if (itr != '\n' || itr != '\n')
result.push_back(itr);
}
return result;
}
// Modified from the public domain code in
// https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#C++_2
constexpr char base64_pad_character = '=';
constexpr static char base64_pad_character = '=';
static std::string
base64decode(const std::string& input) {
std::string
decode_base64(const std::string& input) {
if (input.length() % 4) // Sanity check
throw torrent::input_error("Invalid base64.");
size_t padding = 0;