Merge pull request #38414 from ClickHouse/fix-wrong-basex-commit

Correct submodule after "base-x" commit
This commit is contained in:
Alexey Milovidov 2022-06-25 03:06:33 +03:00 committed by GitHub
commit 9371a1917a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 4 additions and 3710 deletions

6
.gitmodules vendored
View File

@ -268,9 +268,9 @@
[submodule "contrib/hashidsxx"]
path = contrib/hashidsxx
url = https://github.com/schoentoon/hashidsxx.git
[submodule "contrib/base-x"]
path = contrib/base-x
url = https://github.com/ClickHouse/base-x.git
[submodule "contrib/liburing"]
path = contrib/liburing
url = https://github.com/axboe/liburing.git
[submodule "contrib/base-x"]
path = contrib/base-x
url = https://github.com/ClickHouse/base-x.git

1
contrib/base-x vendored Submodule

@ -0,0 +1 @@
Subproject commit a85f98fb4ed52c2f4029a4b6ac1ef0bafdfc56f5

View File

@ -1,4 +0,0 @@
.DS_Store
test
*.o
*.dSYM

View File

@ -1,36 +0,0 @@
sudo: false
language: cpp
compiler:
- clang
- gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
packages:
- g++-6
- clang-3.8
install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-6"; fi
- if [ "$CXX" == "clang++" ]; then export CXX="clang++-3.8"; fi
- sudo apt-get install -qq git cmake
before_script:
# not much better than git submodules, but there was never a need/want for the repo in this repo
- cd ..
- git clone https://github.com/google/googletest.git
- cd googletest
- git reset --hard d62d6c6556d96dda924382547c54a4b3afedb22c
- cmake CMakeLists.txt
- make
- cd ../base-x/tests
- make
script:
- make run

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2017 German Mendez Bravo (Kronuz) @ german dot mb at gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,97 +0,0 @@
# base-x [![License][license-img]][license-url] [![GitHub Stars][stars-img]][stars-url] [![GitHub Forks][forks-img]][forks-url] [![GitHub Watchers][watchers-img]][watchers-url] [![Tweet][tweet-img]][tweet-url]
[![Build Status](https://travis-ci.org/Kronuz/base-x.svg?branch=master)](https://travis-ci.org/Kronuz/base-x)
### BaseX encoder / decoder for C++
This is a fast base encoder / decoder of any given alphabet.
#### Example
``` cpp
// example.cc
// g++ -std=c++14 -o example example.cc
#include <iostream>
#include "base_x.hh"
int main() {
auto encoded = Base58::base58().encode("Hello world!");
std::cout << encoded << std::endl;
// => 1LDlk6QWOejX6rPrJ
return 0;
}
```
#### Compilation
* g++ and clang++ are supported.
* C++14 is required.
### Alphabets
See below for a list of commonly recognized alphabets, and their respective base.
Base | Factory | Alphabet
-----|---------------------|-------------
2 | base2::base2() | `01`
2 | base8::base8() | `01234567`
11 | bas11::bas11() | `0123456789a`
16 | base16::base16() | `0123456789abcdef`
32 | base32::base32() | `0123456789ABCDEFGHJKMNPQRSTVWXYZ`
36 | base36::base36() | `0123456789abcdefghijklmnopqrstuvwxyz`
58 | base58::base58() | `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`
58 | base58::bitcoin() | `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`
58 | base58::gmp() | `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv`
58 | base58::ripple() | `rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz`
58 | base58::flickr() | `123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ`
62 | base62::base62() | `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`
62 | base62::inverted() | `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`
64 | base64::base64() | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`
64 | base64::urlsafe() | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`
66 | base66::base66() | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~`
### How it works
It encodes octet arrays by doing long divisions on all significant digits in the
array, creating a representation of that number in the new base.
**If you need standard hex encoding, or base64 encoding, this module is NOT
appropriate.**
## Author
[**German Mendez Bravo (Kronuz)**](https://kronuz.io/)
[![Follow on GitHub][github-follow-img]][github-follow-url]
[![Follow on Twitter][twitter-follow-img]][twitter-follow-url]
## License
MIT License. See [LICENSE](LICENSE) for details.
Copyright (c) 2017 German Mendez Bravo (Kronuz) @ german dot mb at gmail.com
[license-url]: https://github.com/Kronuz/base-x/blob/master/LICENSE
[license-img]: https://img.shields.io/github/license/Kronuz/base-x.svg
[stars-url]: https://github.com/Kronuz/base-x/stargazers
[stars-img]: https://img.shields.io/github/stars/Kronuz/base-x.svg?style=social&amp;label=Stars
[forks-url]: https://github.com/Kronuz/base-x/network/members
[forks-img]: https://img.shields.io/github/forks/Kronuz/base-x.svg?style=social&amp;label=Forks
[watchers-url]: https://github.com/Kronuz/base-x/watchers
[watchers-img]: https://img.shields.io/github/watchers/Kronuz/base-x.svg?style=social&amp;label=Watchers
[tweet-img]: https://img.shields.io/twitter/url/https/github.com/Kronuz/base-x.svg?style=social
[tweet-url]: https://twitter.com/intent/tweet?text=Base-X+encoding%2Fdecoding+for+modern+C%2B%2B+by+%40germbravo:&url=https%3A%2F%2Fgithub.com%2FKronuz%2Fbase-x
[github-follow-url]: https://github.com/Kronuz
[github-follow-img]: https://img.shields.io/github/followers/Kronuz.svg?style=social&label=Follow
[twitter-follow-url]: https://twitter.com/intent/follow?screen_name=germbravo
[twitter-follow-img]: https://img.shields.io/twitter/follow/germbravo.svg?style=social&label=Follow

View File

@ -1,614 +0,0 @@
/*
base_x.hh
BaseX encoder / decoder for C++
Copyright (c) 2017 German Mendez Bravo (Kronuz) @ german dot mb at gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef __BASE_X__H_
#define __BASE_X__H_
#include <algorithm> // for std::find_if, std::reverse
#include <stdexcept> // for std::invalid_argument
#include <string> // for std::string
#include <type_traits> // for std::enable_if_t
#include "uinteger_t.hh"
class BaseX {
char _chr[256];
int _ord[256];
const int size;
const int alphabet_base;
const unsigned base_size;
const unsigned alphabet_base_bits;
const unsigned block_size;
const uinteger_t::digit alphabet_base_mask;
const unsigned padding_size;
const char padding;
const int flags;
constexpr char chr(unsigned char ord) const {
return _chr[ord];
}
constexpr int ord(unsigned char chr) const {
return _ord[chr];
}
public:
static constexpr int ignore_case = (1 << 0);
static constexpr int with_checksum = (1 << 1);
static constexpr int with_check = (1 << 2);
static constexpr int block_padding = (1 << 3);
template <std::size_t alphabet_size1, std::size_t extended_size1, std::size_t padding_size1, std::size_t translate_size1>
constexpr BaseX(int flgs, const char (&alphabet)[alphabet_size1], const char (&extended)[extended_size1], const char (&padding_string)[padding_size1], const char (&translate)[translate_size1]) :
_chr(),
_ord(),
size(alphabet_size1 - 1 + extended_size1 - 1),
alphabet_base(alphabet_size1 - 1),
base_size(uinteger_t::base_size(alphabet_base)),
alphabet_base_bits(uinteger_t::base_bits(alphabet_base)),
block_size((flgs & BaseX::block_padding) ? alphabet_base_bits : 0),
alphabet_base_mask(alphabet_base - 1),
padding_size(padding_size1 - 1),
padding(padding_size ? padding_string[0] : '\0'),
flags(flgs)
{
for (int c = 0; c < 256; ++c) {
_chr[c] = 0;
_ord[c] = alphabet_base;
}
for (int cp = 0; cp < alphabet_base; ++cp) {
auto ch = alphabet[cp];
_chr[cp] = ch;
ASSERT(_ord[(unsigned char)ch] == alphabet_base); // Duplicate character in the alphabet
_ord[(unsigned char)ch] = cp;
if (flags & BaseX::ignore_case) {
if (ch >= 'A' && ch <='Z') {
_ord[(unsigned char)ch - 'A' + 'a'] = cp;
} else if (ch >= 'a' && ch <='z') {
_ord[(unsigned char)ch - 'a' + 'A'] = cp;
}
}
}
for (std::size_t i = 0; i < extended_size1 - 1; ++i) {
auto ch = extended[i];
auto cp = alphabet_base + i;
_chr[cp] = ch;
ASSERT(_ord[(unsigned char)ch] == alphabet_base); // Duplicate character in the extended alphabet
_ord[(unsigned char)ch] = cp;
if (flags & BaseX::ignore_case) {
if (ch >= 'A' && ch <='Z') {
_ord[(unsigned char)ch - 'A' + 'a'] = cp;
} else if (ch >= 'a' && ch <='z') {
_ord[(unsigned char)ch - 'a' + 'A'] = cp;
}
}
}
int cp = -1;
for (std::size_t i = 0; i < translate_size1 - 1; ++i) {
auto ch = translate[i];
auto ncp = _ord[(unsigned char)ch];
if (ncp >= alphabet_base) {
ASSERT(_ord[(unsigned char)ch] == alphabet_base); // Invalid translation character
_ord[(unsigned char)ch] = cp;
if (flags & BaseX::ignore_case) {
if (ch >= 'A' && ch <='Z') {
_ord[(unsigned char)ch - 'A' + 'a'] = cp;
} else if (ch >= 'a' && ch <='z') {
_ord[(unsigned char)ch - 'a' + 'A'] = cp;
}
}
} else {
cp = ncp;
}
}
}
// Get string representation of value
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
void encode(Result& result, const uinteger_t& input) const {
std::size_t bp = 0;
uinteger_t quotient;
if (block_size) {
bp = ((input.bits() + 7) & 0xf8) % block_size;
bp = bp ? (block_size - bp) % block_size : 0;
if (bp) {
quotient = input << bp;
}
}
const uinteger_t& num = bp ? quotient : input;
auto num_sz = num.size();
if (num_sz) {
int sum = 0;
result.reserve(num_sz * base_size);
if (alphabet_base_bits) {
std::size_t shift = 0;
auto ptr = reinterpret_cast<const uinteger_t::half_digit*>(num.data());
uinteger_t::digit v = *ptr++;
v <<= uinteger_t::half_digit_bits;
for (auto i = num_sz * 2 - 1; i; --i) {
v >>= uinteger_t::half_digit_bits;
v |= (static_cast<uinteger_t::digit>(*ptr++) << uinteger_t::half_digit_bits);
do {
auto d = static_cast<int>((v >> shift) & alphabet_base_mask);
result.push_back(chr(d));
shift += alphabet_base_bits;
sum += d;
} while (shift <= uinteger_t::half_digit_bits);
shift -= uinteger_t::half_digit_bits;
}
v >>= (shift + uinteger_t::half_digit_bits);
while (v) {
auto d = static_cast<int>(v & alphabet_base_mask);
result.push_back(chr(d));
v >>= alphabet_base_bits;
sum += d;
}
auto s = chr(0);
auto rit_f = std::find_if(result.rbegin(), result.rend(), [s](const char& c) { return c != s; });
result.resize(result.rend() - rit_f); // shrink
} else {
uinteger_t uint_base = alphabet_base;
if (!bp) {
quotient = num;
}
do {
auto r = quotient.divmod(uint_base);
auto d = static_cast<int>(r.second);
result.push_back(chr(d));
quotient = std::move(r.first);
sum += d;
} while (quotient);
}
std::reverse(result.begin(), result.end());
if (padding_size) {
Result p;
p.resize((padding_size - (result.size() % padding_size)) % padding_size, padding);
result.append(p);
}
if (flags & BaseX::with_check) {
auto chk = static_cast<int>(num % size);
result.push_back(chr(chk));
sum += chk;
}
if (flags & BaseX::with_checksum) {
auto sz = result.size();
sz = (sz + sz / size) % size;
sum += sz;
sum = (size - sum % size) % size;
result.push_back(chr(sum));
}
} else {
result.push_back(chr(0));
}
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
Result encode(const uinteger_t& num) const {
Result result;
encode(result, num);
return result;
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
void encode(Result& result, const unsigned char* decoded, std::size_t decoded_size) const {
encode(result, uinteger_t(decoded, decoded_size, 256));
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
Result encode(const unsigned char* decoded, std::size_t decoded_size) const {
Result result;
encode(result, uinteger_t(decoded, decoded_size, 256));
return result;
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
void encode(Result& result, const char* decoded, std::size_t decoded_size) const {
encode(result, uinteger_t(decoded, decoded_size, 256));
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
Result encode(const char* decoded, std::size_t decoded_size) const {
Result result;
encode(result, uinteger_t(decoded, decoded_size, 256));
return result;
}
template <typename Result = std::string, typename T, std::size_t N, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
void encode(Result& result, T (&s)[N]) const {
encode(result, s, N - 1);
}
template <typename Result = std::string, typename T, std::size_t N, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
Result encode(T (&s)[N]) const {
Result result;
encode(result, s, N - 1);
return result;
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
void encode(Result& result, const std::string& binary) const {
return encode(result, binary.data(), binary.size());
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value>>
Result encode(const std::string& binary) const {
Result result;
encode(result, binary.data(), binary.size());
return result;
}
void decode(uinteger_t& result, const char* encoded, std::size_t encoded_size) const {
result = 0;
int sum = 0;
int sumsz = 0;
int direction = 1;
auto sz = encoded_size;
if (flags & BaseX::with_checksum) --sz;
if (flags & BaseX::with_check) --sz;
int bp = 0;
if (alphabet_base_bits) {
for (; sz; --sz, encoded += direction) {
auto c = *encoded;
if (c == padding) break;
auto d = ord(static_cast<int>(c));
if (d < 0) continue; // ignored character
if (d >= alphabet_base) {
throw std::invalid_argument("Error: Invalid character: '" + std::string(1, c) + "' at " + std::to_string(encoded_size - sz));
}
sum += d;
++sumsz;
result = (result << alphabet_base_bits) | d;
bp += block_size;
}
} else {
uinteger_t uint_base = alphabet_base;
for (; sz; --sz, encoded += direction) {
auto c = *encoded;
if (c == padding) break;
auto d = ord(static_cast<int>(c));
if (d < 0) continue; // ignored character
if (d >= alphabet_base) {
throw std::invalid_argument("Error: Invalid character: '" + std::string(1, c) + "' at " + std::to_string(encoded_size - sz));
}
sum += d;
++sumsz;
result = (result * uint_base) + d;
bp += block_size;
}
}
for (; sz && *encoded == padding; --sz, ++encoded);
result >>= (bp & 7);
if (flags & BaseX::with_check) {
auto c = *encoded;
auto d = ord(static_cast<int>(c));
if (d < 0 || d >= size) {
throw std::invalid_argument("Error: Invalid character: '" + std::string(1, c) + "' at " + std::to_string(encoded_size - sz));
}
auto chk = static_cast<int>(result % size);
if (d != chk) {
throw std::invalid_argument("Error: Invalid check");
}
sum += chk;
++sumsz;
++encoded;
}
if (flags & BaseX::with_checksum) {
auto c = *encoded;
auto d = ord(static_cast<int>(c));
if (d < 0 || d >= size) {
throw std::invalid_argument("Error: Invalid character: '" + std::string(1, c) + "' at " + std::to_string(encoded_size - sz));
}
sum += d;
sum += (sumsz + sumsz / size) % size;
if (sum % size) {
throw std::invalid_argument("Error: Invalid checksum");
}
}
}
template <typename Result, typename = typename std::enable_if_t<uinteger_t::is_result<Result>::value>>
void decode(Result& result, const char* encoded, std::size_t encoded_size) const {
uinteger_t num;
decode(num, encoded, encoded_size);
result = num.template str<Result>(256);
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value or std::is_integral<Result>::value>>
Result decode(const char* encoded, std::size_t encoded_size) const {
Result result;
decode(result, encoded, encoded_size);
return result;
}
template <typename Result = std::string, typename T, std::size_t N, typename = std::enable_if_t<uinteger_t::is_result<Result>::value or std::is_integral<Result>::value>>
void decode(Result& result, T (&s)[N]) const {
decode(result, s, N - 1);
}
template <typename Result = std::string, typename T, std::size_t N, typename = std::enable_if_t<uinteger_t::is_result<Result>::value or std::is_integral<Result>::value>>
Result decode(T (&s)[N]) const {
Result result;
decode(result, s, N - 1);
return result;
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value or std::is_integral<Result>::value>>
void decode(Result& result, const std::string& encoded) const {
decode(result, encoded.data(), encoded.size());
}
template <typename Result = std::string, typename = std::enable_if_t<uinteger_t::is_result<Result>::value or std::is_integral<Result>::value>>
Result decode(const std::string& encoded) const {
Result result;
decode(result, encoded.data(), encoded.size());
return result;
}
bool is_valid(const char* encoded, std::size_t encoded_size) const {
int sum = 0;
int sumsz = 0;
if (flags & BaseX::with_checksum) --sumsz;
for (; encoded_size; --encoded_size, ++encoded) {
auto d = ord(static_cast<int>(*encoded));
if (d < 0) continue; // ignored character
if (d >= alphabet_base) {
return false;
}
sum += d;
++sumsz;
}
if (flags & BaseX::with_checksum) {
sum += (sumsz + sumsz / size) % size;
if (sum % size) {
return false;
}
}
return true;
}
template <typename T, std::size_t N>
bool is_valid(T (&s)[N]) const {
return is_valid(s, N - 1);
}
bool is_valid(const std::string& encoded) const {
return is_valid(encoded.data(), encoded.size());
}
};
// base2
struct Base2 {
static const BaseX& base2() {
static constexpr BaseX encoder(0, "01", "", "", "");
return encoder;
}
static const BaseX& base2chk() {
static constexpr BaseX encoder(BaseX::with_checksum, "01", "", "", "");
return encoder;
}
};
// base8
struct Base8 {
static const BaseX& base8() {
static constexpr BaseX encoder(0, "01234567", "", "", "");
return encoder;
}
static const BaseX& base8chk() {
static constexpr BaseX encoder(BaseX::with_checksum, "01234567", "", "", "");
return encoder;
}
};
// base11
struct Base11 {
static const BaseX& base11() {
static constexpr BaseX encoder(BaseX::ignore_case, "0123456789a", "", "", "");
return encoder;
}
static const BaseX& base11chk() {
static constexpr BaseX encoder(BaseX::ignore_case | BaseX::with_checksum, "0123456789a", "", "", "");
return encoder;
}
};
// base16
struct Base16 {
static const BaseX& base16() {
static constexpr BaseX encoder(BaseX::ignore_case, "0123456789abcdef", "", "", "");
return encoder;
}
static const BaseX& base16chk() {
static constexpr BaseX encoder(BaseX::ignore_case | BaseX::with_checksum, "0123456789abcdef", "", "", "");
return encoder;
}
static const BaseX& rfc4648() {
static constexpr BaseX encoder(0, "0123456789ABCDEF", "", "", "");
return encoder;
}
};
// base32
struct Base32 {
static const BaseX& base32() {
static constexpr BaseX encoder(BaseX::ignore_case, "0123456789abcdefghijklmnopqrstuv", "", "", "");
return encoder;
}
static const BaseX& base32chk() {
static constexpr BaseX encoder(BaseX::ignore_case | BaseX::with_checksum, "0123456789abcdefghijklmnopqrstuv", "", "", "");
return encoder;
}
static const BaseX& crockford() {
static constexpr BaseX encoder(BaseX::ignore_case, "0123456789ABCDEFGHJKMNPQRSTVWXYZ", "", "", "-0O1IL");
return encoder;
}
static const BaseX& crockfordchk() {
static constexpr BaseX encoder(BaseX::ignore_case | BaseX::with_check, "0123456789ABCDEFGHJKMNPQRSTVWXYZ", "*~$=U", "", "-0O1IL");
return encoder;
}
static const BaseX& rfc4648() {
static constexpr BaseX encoder(BaseX::block_padding, "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", "", "========", "\n\r");
return encoder;
}
static const BaseX& rfc4648hex() {
static constexpr BaseX encoder(BaseX::block_padding, "0123456789ABCDEFGHIJKLMNOPQRSTUV", "", "========", "\n\r");
return encoder;
}
};
// base36
struct Base36 {
static const BaseX& base36() {
static constexpr BaseX encoder(BaseX::ignore_case, "0123456789abcdefghijklmnopqrstuvwxyz", "", "", "");
return encoder;
}
static const BaseX& base36chk() {
static constexpr BaseX encoder(BaseX::ignore_case | BaseX::with_checksum, "0123456789abcdefghijklmnopqrstuvwxyz", "", "", "");
return encoder;
}
};
// base58
struct Base58 {
static const BaseX& base58() {
static constexpr BaseX encoder(0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv", "", "", "");
return encoder;
}
static const BaseX& base58chk() {
static constexpr BaseX encoder(BaseX::with_checksum, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv", "", "", "");
return encoder;
}
static const BaseX& bitcoin() {
static constexpr BaseX encoder(0, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", "", "", "");
return encoder;
}
static const BaseX& bitcoinchk() {
static constexpr BaseX encoder(BaseX::with_checksum, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", "", "", "");
return encoder;
}
static const BaseX& ripple() {
static constexpr BaseX encoder(0, "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz", "", "", "");
return encoder;
}
static const BaseX& ripplechk() {
static constexpr BaseX encoder(BaseX::with_checksum, "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz", "", "", "");
return encoder;
}
static const BaseX& flickr() {
static constexpr BaseX encoder(0, "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", "", "", "");
return encoder;
}
static const BaseX& flickrchk() {
static constexpr BaseX encoder(BaseX::with_checksum, "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", "", "", "");
return encoder;
}
};
// base59
struct Base59 {
static const BaseX& base59() {
static constexpr BaseX encoder(0, "23456789abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ", "", "", "l1IO0");
return encoder;
}
static const BaseX& base59chk() {
static constexpr BaseX encoder(BaseX::with_checksum, "23456789abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ", "", "", "l1IO0");
return encoder;
}
static const BaseX& dubaluchk() {
static constexpr BaseX encoder(BaseX::with_checksum, "zy9MalDxwpKLdvW2AtmscgbYUq6jhP7E53TiXenZRkVCrouBH4GSQf8FNJO", "", "", "-l1IO0");
return encoder;
}
};
// base62
struct Base62 {
static const BaseX& base62() {
static constexpr BaseX encoder(0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "", "", "");
return encoder;
}
static const BaseX& base62chk() {
static constexpr BaseX encoder(BaseX::with_checksum, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "", "", "");
return encoder;
}
static const BaseX& inverted() {
static constexpr BaseX encoder(0, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "", "", "");
return encoder;
}
static const BaseX& invertedchk() {
static constexpr BaseX encoder(BaseX::with_checksum, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "", "", "");
return encoder;
}
};
// base64
struct Base64 {
static const BaseX& base64() {
static constexpr BaseX encoder(0, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "", "", "");
return encoder;
}
static const BaseX& base64chk() {
static constexpr BaseX encoder(BaseX::with_checksum, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "", "", "");
return encoder;
}
static const BaseX& url() {
static constexpr BaseX encoder(0, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "", "", "");
return encoder;
}
static const BaseX& urlchk() {
static constexpr BaseX encoder(BaseX::with_checksum, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "", "", "");
return encoder;
}
static const BaseX& rfc4648() {
static constexpr BaseX encoder(BaseX::block_padding, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", "", "====", "\n\r");
return encoder;
}
static const BaseX& rfc4648url() {
static constexpr BaseX encoder(BaseX::block_padding, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "", "====", "\n\r");
return encoder;
}
};
// base66
struct Base66 {
static const BaseX& base66() {
static constexpr BaseX encoder(0, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~", "", "", "");
return encoder;
}
static const BaseX& base66chk() {
static constexpr BaseX encoder(BaseX::with_checksum, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~", "", "", "");
return encoder;
}
};
#endif

View File

@ -1,30 +0,0 @@
/*
The MIT License (MIT)
Copyright (c) 2017 German Mendez Bravo (Kronuz) @ german dot mb at gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <gtest/gtest.h>
int main(int argc, char * argv[]){
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,359 +0,0 @@
/*
The MIT License (MIT)
Copyright (c) 2017 German Mendez Bravo (Kronuz) @ german dot mb at gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <gtest/gtest.h>
#include "base_x.hh"
static constexpr BaseX test_base2(0, "01", "", "", "");
static constexpr BaseX test_base16(0, "0123456789abcdef", "", "", "");
static constexpr BaseX test_base58(0, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", "", "", "");
TEST(UUID, Encode) {
EXPECT_EQ(Base62::base62().encode("\330\105\140\310\23\117\21\346\241\342\64\66\73\322\155\256"), "6a630O1jrtMjCrQDyG3D3O");
EXPECT_EQ(Base58::bitcoin().encode("\330\105\140\310\23\117\21\346\241\342\64\66\73\322\155\256"), "ThxCy1Ek2q6UhWQhj9CK1o");
EXPECT_EQ(Base58::base58().encode("\330\105\140\310\23\117\21\346\241\342\64\66\73\322\155\256"), "QetBu0Dh1m5ReTNeg8BI0k");
}
TEST(BaseX, checksums) {
EXPECT_EQ(Base64::base64().encode("Hello world!"), "SGVsbG8gd29ybGQh");
EXPECT_EQ(Base64::base64chk().encode("Hello world!"), "SGVsbG8gd29ybGQhG");
EXPECT_EQ(Base64::base64().decode("SGVsbG8gd29ybGQh"), "Hello world!");
EXPECT_EQ(Base64::base64chk().decode("SGVsbG8gd29ybGQhG"), "Hello world!");
EXPECT_EQ(Base62::base62().encode("Hello world!"), "T8dgcjRGuYUueWht");
EXPECT_EQ(Base62::base62chk().encode("Hello world!"), "T8dgcjRGuYUueWhtE");
EXPECT_EQ(Base62::base62().decode("T8dgcjRGuYUueWht"), "Hello world!");
EXPECT_EQ(Base62::base62chk().decode("T8dgcjRGuYUueWhtE"), "Hello world!");
EXPECT_EQ(Base62::base62chk().is_valid("T8dgcjRGuYUueWhtE"), true);
EXPECT_EQ(Base62::base62chk().is_valid("Some random text!"), false);
}
TEST(base16, Encoder) {
EXPECT_EQ(Base16::base16().encode("A"), "41");
EXPECT_EQ(Base16::base16().encode("AB"), "4142");
EXPECT_EQ(Base16::base16().encode("ABC"), "414243");
EXPECT_EQ(Base16::base16().encode("ABCD"), "41424344");
EXPECT_EQ(Base16::base16().encode("ABCDE"), "4142434445");
EXPECT_EQ(Base16::base16().encode("ABCDEF"), "414243444546");
EXPECT_EQ(Base16::rfc4648().encode("A"), "41");
EXPECT_EQ(Base16::rfc4648().encode("AB"), "4142");
EXPECT_EQ(Base16::rfc4648().encode("ABC"), "414243");
EXPECT_EQ(Base16::rfc4648().encode("ABCD"), "41424344");
EXPECT_EQ(Base16::rfc4648().encode("ABCDE"), "4142434445");
EXPECT_EQ(Base16::rfc4648().encode("ABCDEF"), "414243444546");
}
TEST(base16, Decoder) {
EXPECT_EQ(Base16::base16().decode("41"), "A");
EXPECT_EQ(Base16::base16().decode("4142"), "AB");
EXPECT_EQ(Base16::base16().decode("414243"), "ABC");
EXPECT_EQ(Base16::base16().decode("41424344"), "ABCD");
EXPECT_EQ(Base16::base16().decode("4142434445"), "ABCDE");
EXPECT_EQ(Base16::base16().decode("414243444546"), "ABCDEF");
EXPECT_EQ(Base16::rfc4648().decode("41"), "A");
EXPECT_EQ(Base16::rfc4648().decode("4142"), "AB");
EXPECT_EQ(Base16::rfc4648().decode("414243"), "ABC");
EXPECT_EQ(Base16::rfc4648().decode("41424344"), "ABCD");
EXPECT_EQ(Base16::rfc4648().decode("4142434445"), "ABCDE");
EXPECT_EQ(Base16::rfc4648().decode("414243444546"), "ABCDEF");
}
TEST(base32, Encoder) {
// Note base64() encoding is NOT the same as the standard (rfc4648)
EXPECT_EQ(Base32::base32().encode("A"), "21");
EXPECT_EQ(Base32::base32().encode("AB"), "ga2");
EXPECT_EQ(Base32::base32().encode("ABC"), "42gi3");
EXPECT_EQ(Base32::base32().encode("ABCD"), "10k4gq4");
EXPECT_EQ(Base32::base32().encode("ABCDE"), "85146h25");
EXPECT_EQ(Base32::base32().encode("ABCDEF"), "21891k8ha6");
EXPECT_EQ(Base32::base32().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "21891k8ha68t44iiib9h6ksjqga5956l2lapblgmaq");
EXPECT_EQ(Base32::rfc4648().encode("A"), "IE======");
EXPECT_EQ(Base32::rfc4648().encode("AB"), "IFBA====");
EXPECT_EQ(Base32::rfc4648().encode("ABC"), "IFBEG===");
EXPECT_EQ(Base32::rfc4648().encode("ABCD"), "IFBEGRA=");
EXPECT_EQ(Base32::rfc4648().encode("ABCDE"), "IFBEGRCF");
EXPECT_EQ(Base32::rfc4648().encode("ABCDEF"), "IFBEGRCFIY======");
EXPECT_EQ(Base32::rfc4648().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "IFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLI======");
EXPECT_EQ(Base32::crockford().encode(519571), "FVCK");
EXPECT_EQ(Base32::crockfordchk().encode(1234), "16JD");
EXPECT_EQ(Base32::crockfordchk().encode("Hello World"), "28CNP6RVS0AXQQ4V348");
}
TEST(base32, Decoder) {
// Note base64() encoding is NOT the same as the standard (rfc4648)
EXPECT_EQ(Base32::base32().decode("21"), "A");
EXPECT_EQ(Base32::base32().decode("ga2"), "AB");
EXPECT_EQ(Base32::base32().decode("42gi3"), "ABC");
EXPECT_EQ(Base32::base32().decode("10k4gq4"), "ABCD");
EXPECT_EQ(Base32::base32().decode("85146h25"), "ABCDE");
EXPECT_EQ(Base32::base32().decode("21891k8ha6"), "ABCDEF");
EXPECT_EQ(Base32::base32().decode("21891k8ha68t44iiib9h6ksjqga5956l2lapblgmaq"), "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
EXPECT_EQ(Base32::rfc4648().decode("IE======"), "A");
EXPECT_EQ(Base32::rfc4648().decode("IFBA===="), "AB");
EXPECT_EQ(Base32::rfc4648().decode("IFBEG==="), "ABC");
EXPECT_EQ(Base32::rfc4648().decode("IFBEGRA="), "ABCD");
EXPECT_EQ(Base32::rfc4648().decode("IFBEGRCF"), "ABCDE");
EXPECT_EQ(Base32::rfc4648().decode("IFBEGRCFIY======"), "ABCDEF");
EXPECT_EQ(Base32::rfc4648().decode("IFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLI======"), "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
EXPECT_EQ(Base32::crockford().decode<uinteger_t>("FVCK"), 519571);
EXPECT_EQ(Base32::crockfordchk().is_valid("16JD"), true);
EXPECT_EQ(Base32::crockfordchk().decode<uinteger_t>("16JD"), 1234);
EXPECT_EQ(Base32::crockfordchk().decode("2-8cn-p6r-vso-axq-q4v-348"), "Hello World");
}
TEST(base58, Encoder) {
EXPECT_EQ(Base58::base58().decode<uinteger_t>("1TFvCj"), 987654321);
EXPECT_EQ(Base58::base58().encode(987654321), "1TFvCj");
EXPECT_EQ(Base58::base58().encode("Hello world!"), "1LDlk6QWOejX6rPrJ");
EXPECT_EQ(Base58::bitcoin().encode("Hello world!"), "2NEpo7TZRhna7vSvL");
}
TEST(base62, Encoder) {
EXPECT_EQ(Base62::base62().decode<uinteger_t>("14q60P"), 987654321);
EXPECT_EQ(Base62::base62().encode(987654321), "14q60P");
EXPECT_EQ(Base62::base62().encode("Hello world!"), "T8dgcjRGuYUueWht");
EXPECT_EQ(Base62::inverted().encode("Hello world!"), "t8DGCJrgUyuUEwHT");
}
TEST(base64, Encoder) {
// Note Base64 encoding is NOT the same as the standard (rfc4648)
EXPECT_EQ(Base64::base64().encode("A"), "BB");
EXPECT_EQ(Base64::base64().encode("AB"), "EFC");
EXPECT_EQ(Base64::base64().encode("ABC"), "QUJD");
EXPECT_EQ(Base64::base64().encode("ABCD"), "BBQkNE");
EXPECT_EQ(Base64::base64().encode("ABCDE"), "EFCQ0RF");
EXPECT_EQ(Base64::base64().encode("ABCDEF"), "QUJDREVG");
EXPECT_EQ(Base64::base64().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "EFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFla");
EXPECT_EQ(Base64::rfc4648().encode("A"), "QQ==");
EXPECT_EQ(Base64::rfc4648().encode("AB"), "QUI=");
EXPECT_EQ(Base64::rfc4648().encode("ABC"), "QUJD");
EXPECT_EQ(Base64::rfc4648().encode("ABCD"), "QUJDRA==");
EXPECT_EQ(Base64::rfc4648().encode("ABCDE"), "QUJDREU=");
EXPECT_EQ(Base64::rfc4648().encode("ABCDEF"), "QUJDREVG");
EXPECT_EQ(Base64::rfc4648().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVo=");
}
TEST(base64, Decoder) {
// Note Base64 encoding is NOT the same as the standard (rfc4648)
EXPECT_EQ(Base64::base64().decode("BB"), "A");
EXPECT_EQ(Base64::base64().decode("EFC"), "AB");
EXPECT_EQ(Base64::base64().decode("QUJD"), "ABC");
EXPECT_EQ(Base64::base64().decode("BBQkNE"), "ABCD");
EXPECT_EQ(Base64::base64().decode("EFCQ0RF"), "ABCDE");
EXPECT_EQ(Base64::base64().decode("QUJDREVG"), "ABCDEF");
EXPECT_EQ(Base64::base64().decode("EFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFla"), "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
EXPECT_EQ(Base64::rfc4648().decode("QQ=="), "A");
EXPECT_EQ(Base64::rfc4648().decode("QUI="), "AB");
EXPECT_EQ(Base64::rfc4648().decode("QUJD"), "ABC");
EXPECT_EQ(Base64::rfc4648().decode("QUJDRA=="), "ABCD");
EXPECT_EQ(Base64::rfc4648().decode("QUJDREU="), "ABCDE");
EXPECT_EQ(Base64::rfc4648().decode("QUJDREVG"), "ABCDEF");
EXPECT_EQ(Base64::rfc4648().decode("QUJDREVG\nR0hJSktM\nTU5PUFFS\nU1RVVldY\nWVo="), "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
TEST(base58, ShouldEncodeAndDecodeIntegers) {
auto data = 987654321;
auto gmpEncoded = Base58::base58().encode(data);
auto bitcoinEncoded = Base58::bitcoin().encode(data);
auto rippleEncoded = Base58::ripple().encode(data);
auto flickrEncoded = Base58::flickr().encode(data);
EXPECT_EQ(gmpEncoded, "1TFvCj");
EXPECT_EQ(bitcoinEncoded, "2WGzDn");
EXPECT_EQ(rippleEncoded, "pWGzD8");
EXPECT_EQ(flickrEncoded, "2vgZdM");
auto gmpDecoded = Base58::base58().decode<uinteger_t>(gmpEncoded);
auto bitcoinDecoded = Base58::bitcoin().decode<uinteger_t>(bitcoinEncoded);
auto rippleDecoded = Base58::ripple().decode<uinteger_t>(rippleEncoded);
auto flickrDecoded = Base58::flickr().decode<uinteger_t>(flickrEncoded);
EXPECT_EQ(gmpDecoded, data);
EXPECT_EQ(bitcoinDecoded, data);
EXPECT_EQ(rippleDecoded, data);
EXPECT_EQ(flickrDecoded, data);
auto encoded = Base58::base58().encode(data);
auto decoded = Base58::base58().decode<uinteger_t>(encoded);
EXPECT_EQ(decoded, data);
}
TEST(base58, LongText) {
auto data = "Lorem ipsum dolor consectetur.";
auto gmpEncoded = Base58::base58().encode(data);
auto bitcoinEncoded = Base58::bitcoin().encode(data);
auto rippleEncoded = Base58::ripple().encode(data);
auto flickrEncoded = Base58::flickr().encode(data);
EXPECT_EQ(gmpEncoded, "FIHZQEpJ739QdqChX1PkgTBqP1FaDgJWQiGvY92YA");
EXPECT_EQ(bitcoinEncoded, "GKJcTFtL84ATguDka2SojWCuS2GdEjLZTmHzbA3bB");
EXPECT_EQ(rippleEncoded, "GKJcTEtL3hwTguDk2pSojWUuSpGdNjLZTmHzbwsbB");
EXPECT_EQ(flickrEncoded, "gjiBsfTk84asFUdKz2rNJvcUr2gCeJkysLhZAa3Ab");
auto gmpDecoded = Base58::base58().decode(gmpEncoded);
auto bitcoinDecoded = Base58::bitcoin().decode(bitcoinEncoded);
auto rippleDecoded = Base58::ripple().decode(rippleEncoded);
auto flickrDecoded = Base58::flickr().decode(flickrEncoded);
EXPECT_EQ(gmpDecoded, data);
EXPECT_EQ(bitcoinDecoded, data);
EXPECT_EQ(rippleDecoded, data);
EXPECT_EQ(flickrDecoded, data);
}
TEST(base58, Tests) {
EXPECT_EQ(test_base2.encode(uinteger_t("000f", 16)), "1111");
// EXPECT_EQ(test_base2.encode(uinteger_t("00ff", 16)), "011111111"); // ->>
EXPECT_EQ(test_base2.encode(uinteger_t("00ff", 16)), "11111111");
EXPECT_EQ(test_base2.encode(uinteger_t("0fff", 16)), "111111111111");
EXPECT_EQ(test_base2.encode(uinteger_t("ff00ff00", 16)), "11111111000000001111111100000000");
// EXPECT_EQ(test_base16.encode(uinteger_t("0000000f", 16)), "000f"); // ->>
EXPECT_EQ(test_base16.encode(uinteger_t("0000000f", 16)), "f");
// EXPECT_EQ(test_base16.encode(uinteger_t("000fff", 16)), "0fff"); // ->>
EXPECT_EQ(test_base16.encode(uinteger_t("000fff", 16)), "fff");
EXPECT_EQ(test_base16.encode(uinteger_t("ffff", 16)), "ffff");
// EXPECT_EQ(test_base58.encode(uinteger_t("", 16)), ""); // ->>
EXPECT_EQ(test_base58.encode(uinteger_t("", 16)), "1");
EXPECT_EQ(test_base58.encode(uinteger_t("61", 16)), "2g");
EXPECT_EQ(test_base58.encode(uinteger_t("626262", 16)), "a3gV");
EXPECT_EQ(test_base58.encode(uinteger_t("636363", 16)), "aPEr");
EXPECT_EQ(test_base58.encode(uinteger_t("73696d706c792061206c6f6e6720737472696e67", 16)), "2cFupjhnEsSn59qHXstmK2ffpLv2");
// EXPECT_EQ(test_base58.encode(uinteger_t("00eb15231dfceb60925886b67d065299925915aeb172c06647", 16)), "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"); // ->>
EXPECT_EQ(test_base58.encode(uinteger_t("00eb15231dfceb60925886b67d065299925915aeb172c06647", 16)), "NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L");
EXPECT_EQ(test_base58.encode(uinteger_t("516b6fcd0f", 16)), "ABnLTmg");
EXPECT_EQ(test_base58.encode(uinteger_t("bf4f89001e670274dd", 16)), "3SEo3LWLoPntC");
EXPECT_EQ(test_base58.encode(uinteger_t("572e4794", 16)), "3EFU7m");
EXPECT_EQ(test_base58.encode(uinteger_t("ecac89cad93923c02321", 16)), "EJDM8drfXA6uyA");
EXPECT_EQ(test_base58.encode(uinteger_t("10c8511e", 16)), "Rt5zm");
// EXPECT_EQ(test_base58.encode(uinteger_t("00000000000000000000", 16)), "1111111111"); // ->>
EXPECT_EQ(test_base58.encode(uinteger_t("00000000000000000000", 16)), "1");
EXPECT_EQ(test_base58.encode(uinteger_t("801184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd206ec97e", 16)), "5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD");
// EXPECT_EQ(test_base58.encode(uinteger_t("003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187", 16)), "16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS"); // ->>
EXPECT_EQ(test_base58.encode(uinteger_t("003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187", 16)), "6UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS");
EXPECT_EQ(test_base58.encode(uinteger_t("ffffffffffffffffffff", 16)), "FPBt6CHo3fovdL");
EXPECT_EQ(test_base58.encode(uinteger_t("ffffffffffffffffffffffffff", 16)), "NKioeUVktgzXLJ1B3t");
EXPECT_EQ(test_base58.encode(uinteger_t("ffffffffffffffffffffffffffffffff", 16)), "YcVfxkQb6JRzqk5kF2tNLv");
EXPECT_EQ(test_base2.encode(uinteger_t("fb6f9ac3", 16)), "11111011011011111001101011000011");
EXPECT_EQ(test_base2.encode(uinteger_t("179eea7a", 16)), "10111100111101110101001111010");
EXPECT_EQ(test_base2.encode(uinteger_t("6db825db", 16)), "1101101101110000010010111011011");
EXPECT_EQ(test_base2.encode(uinteger_t("93976aa7", 16)), "10010011100101110110101010100111");
EXPECT_EQ(test_base58.encode(uinteger_t("ef41b9ce7e830af7", 16)), "h26E62FyLQN");
EXPECT_EQ(test_base58.encode(uinteger_t("606cbc791036d2e9", 16)), "H8Sa62HVULG");
EXPECT_EQ(test_base58.encode(uinteger_t("bdcb0ea69c2c8ec8", 16)), "YkESUPpnfoD");
EXPECT_EQ(test_base58.encode(uinteger_t("1a2358ba67fb71d5", 16)), "5NaBN89ajtQ");
EXPECT_EQ(test_base58.encode(uinteger_t("e6173f0f4d5fb5d7", 16)), "fVAoezT1ZkS");
EXPECT_EQ(test_base58.encode(uinteger_t("91c81cbfdd58bbd2", 16)), "RPGNSU3bqTX");
EXPECT_EQ(test_base58.encode(uinteger_t("329e0bf0e388dbfe", 16)), "9U41ZkwwysT");
EXPECT_EQ(test_base58.encode(uinteger_t("30b10393210fa65b", 16)), "99NMW3WHjjY");
EXPECT_EQ(test_base58.encode(uinteger_t("ab3bdd18e3623654", 16)), "VeBbqBb4rCT");
EXPECT_EQ(test_base58.encode(uinteger_t("fe29d1751ec4af8a", 16)), "jWhmYLN9dUm");
EXPECT_EQ(test_base58.encode(uinteger_t("c1273ab5488769807d", 16)), "3Tbh4kL3WKW6g");
EXPECT_EQ(test_base58.encode(uinteger_t("6c7907904de934f852", 16)), "2P5jNYhfpTJxy");
EXPECT_EQ(test_base58.encode(uinteger_t("05f0be055db47a0dc9", 16)), "5PN768Kr5oEp");
EXPECT_EQ(test_base58.encode(uinteger_t("3511e6206829b35b12", 16)), "gBREojGaJ6DF");
EXPECT_EQ(test_base58.encode(uinteger_t("d1c7c2ddc4a459d503", 16)), "3fsekq5Esq2KC");
EXPECT_EQ(test_base58.encode(uinteger_t("1f88efd17ab073e9a1", 16)), "QHJbmW9ZY7jn");
EXPECT_EQ(test_base58.encode(uinteger_t("0f45dadf4e64c5d5c2", 16)), "CGyVUMmCKLRf");
EXPECT_EQ(test_base58.encode(uinteger_t("de1e5c5f718bb7fafa", 16)), "3pyy8U7w3KUa5");
EXPECT_EQ(test_base58.encode(uinteger_t("123190b93e9a49a46c", 16)), "ES3DeFrG1zbd");
EXPECT_EQ(test_base58.encode(uinteger_t("8bee94a543e7242e5a", 16)), "2nJnuWyLpGf6y");
EXPECT_EQ(test_base58.encode(uinteger_t("9fd5f2285362f5cfd834", 16)), "9yqFhqeewcW3pF");
EXPECT_EQ(test_base58.encode(uinteger_t("6987bac63ad23828bb31", 16)), "6vskE5Y1LhS3U4");
EXPECT_EQ(test_base58.encode(uinteger_t("19d4a0f9d459cc2a08b0", 16)), "2TAsHPuaLhh5Aw");
EXPECT_EQ(test_base58.encode(uinteger_t("a1e47ffdbea5a807ab26", 16)), "A6XzPgSUJDf1W5");
EXPECT_EQ(test_base58.encode(uinteger_t("35c231e5b3a86a9b83db", 16)), "42B8reRwPAAoAa");
EXPECT_EQ(test_base58.encode(uinteger_t("b2351012a48b8347c351", 16)), "B1hPyomGx4Vhqa");
EXPECT_EQ(test_base58.encode(uinteger_t("71d402694dd9517ea653", 16)), "7Pv2SyAQx2Upu8");
EXPECT_EQ(test_base58.encode(uinteger_t("55227c0ec7955c2bd6e8", 16)), "5nR64BkskyjHMq");
EXPECT_EQ(test_base58.encode(uinteger_t("17b3d8ee7907c1be34df", 16)), "2LEg7TxosoxTGS");
EXPECT_EQ(test_base58.encode(uinteger_t("7e7bba7b68bb8e95827f", 16)), "879o2ATGnmYyAW");
EXPECT_EQ(test_base58.encode(uinteger_t("db9c13f5ba7654b01407fb", 16)), "wTYfxjDVbiks874");
EXPECT_EQ(test_base58.encode(uinteger_t("6186449d20f5fd1e6c4393", 16)), "RBeiWhzZNL6VtMG");
EXPECT_EQ(test_base58.encode(uinteger_t("5248751cebf4ad1c1a83c3", 16)), "MQSVNnc8ehFCqtW");
EXPECT_EQ(test_base58.encode(uinteger_t("32090ef18cd479fc376a74", 16)), "DQdu351ExDaeYeX");
EXPECT_EQ(test_base58.encode(uinteger_t("7cfa5d6ed1e467d986c426", 16)), "XzW67T5qfEnFcaZ");
EXPECT_EQ(test_base58.encode(uinteger_t("9d8707723c7ede51103b6d", 16)), "g4eTCg6QJnB1UU4");
EXPECT_EQ(test_base58.encode(uinteger_t("6f4d1e392d6a9b4ed8b223", 16)), "Ubo7kZY5aDpAJp2");
EXPECT_EQ(test_base58.encode(uinteger_t("38057d98797cd39f80a0c9", 16)), "EtjQ2feamJvuqse");
EXPECT_EQ(test_base58.encode(uinteger_t("de7e59903177e20880e915", 16)), "xB2N7yRBnDYEoT2");
EXPECT_EQ(test_base58.encode(uinteger_t("b2ea24a28bc4a60b5c4b8d", 16)), "mNFMpJ2P3TGYqhv");
EXPECT_EQ(test_base58.encode(uinteger_t("cf84938958589b6ffba6114d", 16)), "4v8ZbsGh2ePz5sipt");
EXPECT_EQ(test_base58.encode(uinteger_t("dee13be7b8d8a08c94a3c02a", 16)), "5CwmE9jQqwtHkTF45");
EXPECT_EQ(test_base58.encode(uinteger_t("14cb9c6b3f8cd2e02710f569", 16)), "Pm85JHVAAdeUdxtp");
EXPECT_EQ(test_base58.encode(uinteger_t("ca3f2d558266bdcc44c79cb5", 16)), "4pMwomBAQHuUnoLUC");
EXPECT_EQ(test_base58.encode(uinteger_t("c031215be44cbad745f38982", 16)), "4dMeTrcxiVw9RWvj3");
EXPECT_EQ(test_base58.encode(uinteger_t("1435ab1dbc403111946270a5", 16)), "P7wX3sCWNrbqhBEC");
EXPECT_EQ(test_base58.encode(uinteger_t("d8c6e4d775e7a66a0d0f9f41", 16)), "56GLoRDGWGuGJJwPN");
EXPECT_EQ(test_base58.encode(uinteger_t("dcee35e74f0fd74176fce2f4", 16)), "5Ap1zyuYiJJFwWcMR");
EXPECT_EQ(test_base58.encode(uinteger_t("bfcc0ca4b4855d1cf8993fc0", 16)), "4cvafQW4PEhARKv9D");
EXPECT_EQ(test_base58.encode(uinteger_t("e02a3ac25ece7b54584b670a", 16)), "5EMM28xkpxZ1kkVUM");
EXPECT_EQ(test_base58.encode(uinteger_t("fe4d938fc3719f064cabb4bfff", 16)), "NBXKkbHwrAsiWTLAk6");
EXPECT_EQ(test_base58.encode(uinteger_t("9289cb4f6b15c57e6086b87ea5", 16)), "DCvDpjEXEbHjZqskKv");
EXPECT_EQ(test_base58.encode(uinteger_t("fc266f35626b3612bfe978537b", 16)), "N186PVoBWrNre35BGE");
EXPECT_EQ(test_base58.encode(uinteger_t("33ff08c06d92502bf258c07166", 16)), "5LC4SoW6jmTtbkbePw");
EXPECT_EQ(test_base58.encode(uinteger_t("6a81cac1f3666bc59dc67b1c3c", 16)), "9sXgUySUzwiqDU5WHy");
EXPECT_EQ(test_base58.encode(uinteger_t("9dfb8e7e744c544c0f323ea729", 16)), "EACsmGmkgcwsrPFzLg");
EXPECT_EQ(test_base58.encode(uinteger_t("1e7a1e284f70838b38442b682b", 16)), "3YEVk9bE7rw5qExMkv");
EXPECT_EQ(test_base58.encode(uinteger_t("2a862ad57901a8235f5dc74eaf", 16)), "4YS259nuTLfeXa5Wuc");
EXPECT_EQ(test_base58.encode(uinteger_t("74c82096baef21f9d3089e5462", 16)), "AjAcKEhUfrqm8smvM7");
EXPECT_EQ(test_base58.encode(uinteger_t("7a3edbc23d7b600263920261cc", 16)), "BBZXyRgey5S5DDZkcK");
EXPECT_EQ(test_base58.encode(uinteger_t("20435664c357d25a9c8df751cf4f", 16)), "CrwNL6Fbv4pbRx1zd9g");
EXPECT_EQ(test_base58.encode(uinteger_t("51a7aa87cf5cb1c12d045ec3422d", 16)), "X27NHGgKXmGzzQvDtpC");
EXPECT_EQ(test_base58.encode(uinteger_t("344d2e116aa26f1062a2cb6ebbef", 16)), "LEDLDvL1Hg4qt1efVXt");
EXPECT_EQ(test_base58.encode(uinteger_t("6941add7be4c0b5c7163e4928f8e", 16)), "fhMyN6gwoxE3uYraVzV");
EXPECT_EQ(test_base58.encode(uinteger_t("10938fcbb7c4ab991649734a14bf", 16)), "76TPrSDxzGQfSzMu974");
EXPECT_EQ(test_base58.encode(uinteger_t("eafe04d944ba504e9af9117b07de", 16)), "2VPgov563ryfe4L2Bj6M");
EXPECT_EQ(test_base58.encode(uinteger_t("58d0aeed4d35da20b6f052127edf", 16)), "ZenZhXF9YwP8nQvNtNz");
EXPECT_EQ(test_base58.encode(uinteger_t("d734984e2f5aecf25f7a3e353f8a", 16)), "2N7n3jFsTdyN49Faoq6h");
EXPECT_EQ(test_base58.encode(uinteger_t("57d873fdb405b7daf4bafa62068a", 16)), "ZJ7NwoP4wHvwyZg3Wjs");
EXPECT_EQ(test_base58.encode(uinteger_t("bda4ec7b40d0d65ca95dec4c4d3b", 16)), "2CijxjsNyvqTwPCfDcpA");
EXPECT_EQ(test_base58.encode(uinteger_t("826c4abdceb1b91f0d4ad665f86d2e", 16)), "4edfvuDQu9KzVxLuXHfMo");
EXPECT_EQ(test_base58.encode(uinteger_t("e7ecb35d07e65b960cb10574a4f51a", 16)), "7VLRYdB4cToipp2J2p3v9");
EXPECT_EQ(test_base58.encode(uinteger_t("4f2d72ead87b31d6869fba39eac6dc", 16)), "3DUjqJRcfdWhpsrLrGcQs");
EXPECT_EQ(test_base58.encode(uinteger_t("8b4f5788d60030950d5dfbf94c585d", 16)), "4u44JSRH5jP5X39YhPsmE");
EXPECT_EQ(test_base58.encode(uinteger_t("ee4c0a0025d1a74ace9fe349355cc5", 16)), "7fgACjABRQUGUEpN6VBBA");
EXPECT_EQ(test_base58.encode(uinteger_t("58ac05b9a0b4b66083ff1d489b8d84", 16)), "3UtJPyTwGXapcxHx8Rom5");
EXPECT_EQ(test_base58.encode(uinteger_t("1aa35c05e1132e8e049aafaef035d8", 16)), "kE2eSU7gM2619pT82iGP");
EXPECT_EQ(test_base58.encode(uinteger_t("771b0c28608484562a292e5d5d2b30", 16)), "4LGYeWhyfrjUByibUqdVR");
EXPECT_EQ(test_base58.encode(uinteger_t("78ff9a0e56f9e88dc1cd654b40d019", 16)), "4PLggs66qAdbmZgkaPihe");
EXPECT_EQ(test_base58.encode(uinteger_t("6d691bdd736346aa5a0a95b373b2ab", 16)), "44Y6qTgSvRMkdqpQ5ufkN");
}

File diff suppressed because it is too large Load Diff