mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 22:29:23 +00:00
Change base64 decoder name, and add util for removing newlines
This commit is contained in:
@@ -159,11 +159,7 @@ xml_value_to_object(const tinyxml2::XMLNode* elem) {
|
||||
if (value_element_child == nullptr) {
|
||||
return torrent::Object("");
|
||||
}
|
||||
auto base64string = std::string(value_element_child->ToText()->Value());
|
||||
base64string.erase(std::remove_if(base64string.begin(), base64string.end(),
|
||||
[](char c) { return c == '\n' || c == '\r'; }),
|
||||
base64string.end());
|
||||
return torrent::Object(utils::base64decode(base64string));
|
||||
return torrent::Object(utils::decode_base64(utils::remove_newlines(value_element_child->ToText()->Value())));
|
||||
} else {
|
||||
throw xmlrpc_error(XMLRPC_INTERNAL_ERROR, "received unsupported value type: " + std::string(value_element_type));
|
||||
}
|
||||
|
||||
+13
-3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user