|
|
|
|
@ -10,23 +10,23 @@ namespace baseN
|
|
|
|
|
/**
|
|
|
|
|
* @param digits char[base] array of digits
|
|
|
|
|
* @param digits_size size of digits array. Equals to base
|
|
|
|
|
* @param map [out] int8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. -1 if there is no symbol
|
|
|
|
|
* @param map [out] uint8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. 255 if there is no symbol
|
|
|
|
|
* @throw std::logic_error if alphabet contain same chars
|
|
|
|
|
*/
|
|
|
|
|
void digitsMap(const char *digits, uint8_t digits_size, int8_t *map);
|
|
|
|
|
void digitsMap(const char *digits, uint8_t digits_size, uint8_t *map);
|
|
|
|
|
/**
|
|
|
|
|
* @param str [in] pointer to string
|
|
|
|
|
* @param str_size
|
|
|
|
|
* @param map int8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. -1 if there is no symbol
|
|
|
|
|
* @param map uint8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. 255 if there is no symbol
|
|
|
|
|
* @return that string doesn't contain unnecessary symbols
|
|
|
|
|
*/
|
|
|
|
|
bool isValid(const char *str, size_t str_size, const int8_t *map) noexcept;
|
|
|
|
|
bool isValid(const char *str, size_t str_size, const uint8_t *map) noexcept;
|
|
|
|
|
/**
|
|
|
|
|
* @param str string or string_view which you want to decode
|
|
|
|
|
* @param map int8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. -1 if there is no symbol
|
|
|
|
|
* @param map uint8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. 255 if there is no symbol
|
|
|
|
|
* @return that string doesn't contain unnecessary symbols
|
|
|
|
|
*/
|
|
|
|
|
bool isValid(std::string_view str, const int8_t *map) noexcept;
|
|
|
|
|
bool isValid(std::string_view str, const uint8_t *map) noexcept;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param data vector or span of data which you want to encode
|
|
|
|
|
@ -53,7 +53,7 @@ namespace baseN
|
|
|
|
|
* @code{cpp}
|
|
|
|
|
* std::vector<uint8_t> data;
|
|
|
|
|
* std::string str(baseN::sizeEncoded(data, 58), ' ');
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* auto offset = baseN::encode(data.data(), data.size(), str.data(), str.size(), 58, base58::digits);
|
|
|
|
|
* // deleting leading zeroes
|
|
|
|
|
* str.erase(str.begin(), str.begin() + offset);
|
|
|
|
|
@ -81,11 +81,11 @@ namespace baseN
|
|
|
|
|
* @param data_size
|
|
|
|
|
* @param base from 1 to 255
|
|
|
|
|
* @param digits char[base] array of digits
|
|
|
|
|
* @param map int8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. -1 if there is no symbol
|
|
|
|
|
* @param map uint8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. 255 if there is no symbol
|
|
|
|
|
* @code{cpp}
|
|
|
|
|
* std::string str;
|
|
|
|
|
* std::vector<uint8_t> data(baseN::sizeDecoded(str, 58));
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* auto offset = baseN::decode(str.data(), str.size(), data.data(), data.size(), 58, base58::digits, base58::map);
|
|
|
|
|
* // deleting leading zeroes
|
|
|
|
|
* data.erase(data.begin(), data.begin() + offset);
|
|
|
|
|
@ -93,17 +93,17 @@ namespace baseN
|
|
|
|
|
* @return number of leading chars, which should be trimmed
|
|
|
|
|
* @warning contain leading zeros, returns count of them
|
|
|
|
|
*/
|
|
|
|
|
size_t decode(const char *str, size_t str_size, uint8_t *data, size_t data_size, uint8_t base, const char *digits, const int8_t *map);
|
|
|
|
|
size_t decode(const char *str, size_t str_size, uint8_t *data, size_t data_size, uint8_t base, const char *digits, const uint8_t *map);
|
|
|
|
|
/**
|
|
|
|
|
* @param str string or string_view which you want to decode
|
|
|
|
|
* @param base from 1 to 255
|
|
|
|
|
* @param digits char[base] array of digits
|
|
|
|
|
* @param map int8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. -1 if there is no symbol
|
|
|
|
|
* @param map uint8_t[256] array, where at an index equal to the value of the symbol is the index of this symbol in the digits array. 255 if there is no symbol
|
|
|
|
|
* @code{cpp}
|
|
|
|
|
* std::string str;
|
|
|
|
|
* auto data = baseN::decode(str, 58, base58::digits, base58::map);
|
|
|
|
|
* @endcode
|
|
|
|
|
* @return decoded data
|
|
|
|
|
*/
|
|
|
|
|
std::vector<uint8_t> decode(std::string_view str, uint8_t base, const char *digits, const int8_t *map) noexcept;
|
|
|
|
|
std::vector<uint8_t> decode(std::string_view str, uint8_t base, const char *digits, const uint8_t *map) noexcept;
|
|
|
|
|
}
|