Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

base64codec.hpp 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // base64codec.hpp
  2. // Copyright (C) 2006 - 2009 MicroNeil Research Corporation
  3. // BASE64 encoder decoder objects extending vectors
  4. #pragma once
  5. #include <vector>
  6. #include <cstring>
  7. #include <string>
  8. namespace codedweller {
  9. typedef std::vector<unsigned char> base64buffer;
  10. class to_base64 : public base64buffer { // Converts binary data to base 64.
  11. private:
  12. bool BadConversion; // True if something went wrong.
  13. void convert(const unsigned char* bfr, const int len); // Does the actual work.
  14. public:
  15. to_base64(const std::vector<unsigned char>& bfr); // Converts from a base64buffer.
  16. to_base64(const std::vector<char>& bfr); // Converts from a buffer.
  17. to_base64(const std::string& s); // Converts from a c++ string.
  18. to_base64(const char* s); // Converts from a c string.
  19. to_base64(const unsigned char* bfr, const int len); // Converts from a uchar buffer.
  20. to_base64(const char* bfr, const int len); // Converts from a char buffer.
  21. bool Bad();
  22. };
  23. class from_base64 : public base64buffer { // Convert base64 data to binary.
  24. private:
  25. bool BadConversion; // True if the conversion didn't go well.
  26. unsigned char NextSixBits( // Helper for decoding & ingoring spaces.
  27. int& cursor,
  28. const unsigned char* bfr,
  29. const int len);
  30. void convert(const unsigned char* bfr, const int len); // Does the actual work.
  31. public:
  32. from_base64(const std::vector<unsigned char>& bfr); // Converts from a base64buffer.
  33. from_base64(const std::vector<char>& bfr); // Converts from a buffer.
  34. from_base64(const std::string& s); // Converts from a c++ string.
  35. from_base64(const char*); // Converts from a c_string.
  36. bool Bad(); // True if conversion wasn't complete.
  37. };
  38. }