/* */ #ifndef _D_BASE64_H_ #define _D_BASE64_H_ #include namespace aria2 { class Base64 { private: /** * Removes non base64 chars(including '=') from src, and results are * stored in nsrc and its length is stored in nlength. * Caller must delete nsrc. */ static void removeNonBase64Chars(unsigned char*& nsrc, size_t& nlength, const unsigned char* src, size_t slength); public: /** * Encods src whose length is slength into base64 encoded data * and stores them to result. * result is allocated in this function and the length is stored to rlength. * If slength is equal to 0, then return with rlength set to 0 and result * is left untouched. * A caller must deallocate the memory used by result. */ static void encode(unsigned char*& result, size_t& rlength, const unsigned char* src, size_t slength); static void encode(unsigned char*& result, size_t& rlength, const char* src, size_t slength) { encode(result, rlength, (const unsigned char*)src, slength); } static std::string encode(const std::string& s); /** * Dencods base64 encoded src whose length is slength and stores them to * result. * result is allocated in this function and the length is stored to rlength. * If slength is equal to 0 or is not multiple of 4, then return with rlength * set to 0 and result is left untouched. * The function removes non-base64 characters before decoding. * A caller must deallocate the memory used by result. */ static void decode(unsigned char*& result, size_t& rlength, const unsigned char* src, size_t slength); static void decode(unsigned char*& result, size_t& rlength, const char* src, size_t slength) { decode(result, rlength, (const unsigned char*)src, slength); } static std::string decode(const std::string& s); }; } // namespace aria2 #endif // _BASE64_H_