Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

base64codec.hpp 2.4KB

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