#pragma once

#include <string>
#include <vector>

using namespace std;

class BASE64 {
public:
	BASE64();
	~BASE64();

	string encode(unsigned char * input, int len, bool padding = false);
	vector<unsigned char> decode(const char * input, int len = -1, int * outlen = nullptr);

	int encode_pad_length(int len, int *pad);

private:
	void encode_exactly(const unsigned char *buf, int len, char *encbuf, int enclen);

	int decode_into(const char *buf, int len, unsigned char *decbuf, int declen);
	int decode_alphabet(const char valmap[], const char *buf, int len, unsigned char *decbuf, int declen, int padding);

	static const char values[];
	static const char alphabet[];
};
