2019-06-26 22:11:22 +02:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
namespace base64 {
|
|
|
|
|
/**
|
|
|
|
|
* Encodes a given string in Base64
|
|
|
|
|
* @param input The input string to Base64-encode
|
|
|
|
|
* @param inputSize The size of the input to decode
|
|
|
|
|
* @return A Base64-encoded version of the encoded string
|
|
|
|
|
*/
|
2019-07-02 02:13:42 +02:00
|
|
|
|
extern std::string encode(const char* input, const unsigned long inputSize);
|
2019-06-26 22:11:22 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encodes a given string in Base64
|
|
|
|
|
* @param input The input string to Base64-encode
|
|
|
|
|
* @return A Base64-encoded version of the encoded string
|
|
|
|
|
*/
|
2019-09-22 15:57:01 +01:00
|
|
|
|
inline std::string encode(const std::string& input) { return encode(input.c_str(), (unsigned long) input.size()); }
|
2019-06-26 22:11:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decodes a Base64-encoded string.
|
|
|
|
|
* @param input The input string to decode
|
|
|
|
|
* @return A string (binary) that represents the Base64-decoded data of the input
|
|
|
|
|
*/
|
2019-07-02 02:13:42 +02:00
|
|
|
|
extern std::string decode(const char* input, size_t size);
|
2019-06-26 22:11:22 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decodes a Base64-encoded string.
|
|
|
|
|
* @param input The input string to decode
|
|
|
|
|
* @return A string (binary) that represents the Base64-decoded data of the input
|
|
|
|
|
*/
|
|
|
|
|
inline std::string decode(const std::string& input) { return decode(input.c_str(), input.size()); }
|
|
|
|
|
|
|
|
|
|
//A–Z, a–z, 0–9, + und /
|
|
|
|
|
inline bool validate(const std::string& input) {
|
|
|
|
|
for(char c : input) {
|
|
|
|
|
if(c >= 'A' && c <= 'Z') continue;
|
|
|
|
|
if(c >= 'a' && c <= 'z') continue;
|
|
|
|
|
if(c >= '0' && c <= '9') continue;
|
|
|
|
|
if(c == '+' || c == '/' || c == '=') continue;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
inline std::string base64_encode(const char* input, const unsigned long inputSize) { return base64::encode(input, inputSize); }
|
2019-09-22 15:57:01 +01:00
|
|
|
|
inline std::string base64_encode(const std::string& input) { return base64::encode(input.c_str(), (unsigned long) input.size()); }
|