123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- // base64codec.hpp
- //
- // Copyright (C) 2004-2020 MicroNeil Research Corporation.
- //
- // This software is released under the MIT license. See LICENSE.TXT.
- //
- // Tools for encoding and decoding base64 data.
-
- #pragma once
-
- #include <vector>
- #include <cstring>
- #include <string>
-
- namespace codedweller {
-
- typedef std::vector<unsigned char> base64buffer;
-
- class to_base64 : public base64buffer { // Converts binary data to base 64.
- private:
- bool BadConversion; // True if something went wrong.
- void convert(const unsigned char* bfr, const int len); // Does the actual work.
-
- public:
- to_base64(const std::vector<unsigned char>& bfr); // Converts from a base64buffer.
- to_base64(const std::vector<char>& bfr); // Converts from a buffer.
- to_base64(const std::string& s); // Converts from a c++ string.
- to_base64(const char* s); // Converts from a c string.
- to_base64(const unsigned char* bfr, const int len); // Converts from a uchar buffer.
- to_base64(const char* bfr, const int len); // Converts from a char buffer.
- bool Bad();
- };
-
- class from_base64 : public base64buffer { // Convert base64 data to binary.
- private:
- bool BadConversion; // True if the conversion didn't go well.
- unsigned char NextSixBits( // Helper for decoding & ingoring spaces.
- int& cursor,
- const unsigned char* bfr,
- const int len);
- void convert(const unsigned char* bfr, const int len); // Does the actual work.
-
- public:
- from_base64(const std::vector<unsigned char>& bfr); // Converts from a base64buffer.
- from_base64(const std::vector<char>& bfr); // Converts from a buffer.
- from_base64(const std::string& s); // Converts from a c++ string.
- from_base64(const char*); // Converts from a c_string.
- bool Bad(); // True if conversion wasn't complete.
- };
-
- }
|