Base64.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-01-03
  6. * Changed: 2022-01-16
  7. *
  8. * */
  9. #ifndef LS_STD_BASE64_HPP
  10. #define LS_STD_BASE64_HPP
  11. #include <ls_std/encoding/IEncoding.hpp>
  12. #include <bitset>
  13. #include <vector>
  14. namespace ls_std
  15. {
  16. class Base64 : public ls_std::IEncoding
  17. {
  18. public:
  19. Base64() = default;
  20. ~Base64() = default;
  21. // implementation
  22. std::string encode(const std::string &_sequence) override;
  23. std::string decode(const std::string &_sequence) override;
  24. private:
  25. const std::vector<char> table
  26. {
  27. 'A','B','C','D','E','F','G','H',
  28. 'I','J','K','L','M','N','O','P',
  29. 'Q','R','S','T','U','V','W','X',
  30. 'Y','Z','a','b','c','d','e','f',
  31. 'g','h','i','j','k','l','m','n',
  32. 'o','p','q','r','s','t','u','v',
  33. 'w','x','y','z','0','1','2','3',
  34. '4','5','6','7','8','9','+','/'
  35. };
  36. static uint8_t _detectInitialShiftNumber(size_t size);
  37. std::string _getEncodingFromBitSequence(uint32_t bitSequence, size_t characterSequenceSize);
  38. static uint32_t _getBitSequenceFromCharacterSequence(const std::string &basicString);
  39. char _getCharacterFromLookUpTable(uint8_t byteBuffer, uint8_t shiftByBits);
  40. std::string _getEncodingFromCharacterSequence(const std::string& characterSequence);
  41. static std::string _getNextByteTriple(const std::string& _sequence, size_t index);
  42. };
  43. }
  44. #endif