Commit 58aa4375 authored by jan.koester's avatar jan.koester
Browse files

fixes

parent 9a805e61
Loading
Loading
Loading
Loading
+30 −1
Changes for src/base64.cpp: 30 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
#include <cctype>

namespace netplus {
    const std::string base64::basis_64 =
    const std::string basis_64 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
}

@@ -44,6 +44,31 @@ void netplus::base64::clear() {
    _data.clear();
}


bool netplus::base64::isBase64(const std::vector<char>& data) {
    if (data.empty()) {
        return false;
    }

    for (char c : data) {
        if (c == ' ' || c == '\r' || c == '\n' || c == '\t') {
            continue;
        }

        if (basis_64.find(c) == std::string::npos) {
            return false;
        }
    }

    size_t non_whitespace_size = 0;
    for (char c : data) {
        if (c != ' ' && c != '\r' && c != '\n' && c != '\t') {
            non_whitespace_size++;
        }
    }
    return true;
}

// --- DECODE to vector<char> ---
const netplus::base64 &netplus::base64::operator>>(std::vector<char> &src) const {
    unsigned long long val = 0;
@@ -84,6 +109,10 @@ const netplus::base64 &netplus::base64::operator>>(std::string &src) const {

// --- ENCODE from vector<char> ---
netplus::base64 &netplus::base64::operator<<(const std::vector<char> &data) {
    if(!isBase64(data)){
        std::copy(data.begin(),data.end(),std::back_inserter(_data));
        return *this;
    }
    size_t missing = 0;
    size_t ret_size = data.size();
    std::vector<char> ret;
+2 −2
Changes for src/base64.h: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ namespace netplus {

        void clear();

        bool isBase64(const std::vector<char>& data) ;

        // encode / decode operators
        const base64 &operator>>(std::vector<char> &src) const;
        const base64 &operator>>(std::string &src) const;
@@ -49,10 +51,8 @@ namespace netplus {
        base64 &operator<<(const base64 &data);

        const std::vector<char> &encoded() const;

    private:
        std::vector<char> _data;
        static const std::string basis_64;
    };
}