base32_rfc4648.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <limits>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. #include "exception.hpp"
  7. #define NKG_CURRENT_SOURCE_FILE() u8".\\navicat-keygen\\base32_rfc4648.hpp"
  8. #define NKG_CURRENT_SOURCE_LINE() __LINE__
  9. namespace nkg {
  10. struct base32_rfc4648 {
  11. using alphabet_index_t = size_t;
  12. static constexpr const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
  13. static constexpr const char padding_character = '=';
  14. class decoding_error : public ::nkg::exception {
  15. public:
  16. decoding_error(std::string_view file, int line, std::string_view message) noexcept :
  17. ::nkg::exception(file, line, message) {}
  18. };
  19. static char symbol(alphabet_index_t idx);
  20. static alphabet_index_t reverse_symbol(char c);
  21. static std::string encode(const std::vector<uint8_t>& data);
  22. static std::string encode(const void* data_ptr, size_t data_size);
  23. static std::vector<uint8_t> decode(std::string_view b32_string);
  24. };
  25. }
  26. #undef NKG_CURRENT_SOURCE_LINE
  27. #undef NKG_CURRENT_SOURCE_FILE