19 #include <boost/test/unit_test.hpp> 32 BOOST_AUTO_TEST_SUITE(Crypto)
40 testPath +=
"/BasicTests";
42 cnote <<
"Testing Hex-Prefix-Encode...";
45 BOOST_REQUIRE_MESSAGE(s.length() > 0,
"Content from 'hexencodetest.json' is empty. Have you cloned the 'tests' repo branch develop?");
52 for (
auto& i: o[
"seq"].get_array())
53 v.push_back((
byte)i.get_int());
55 BOOST_REQUIRE( ! o[
"out"].is_null() );
62 static char const*
const s_tests[][2] =
69 {
"fooba",
"Zm9vYmE="},
70 {
"foobar",
"Zm9vYmFy"},
73 "This 4, 5, 6, 7, 8, 9, z, {, |, } tests Base64 encoder. " 74 "Show me: @, A, B, C, D, E, F, G, H, I, J, K, L, M, " 75 "N, O, P, Q, R, S, T, U, V, W, X, Y, Z, [, \\, ], ^, _, `, " 76 "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s.",
77 "U28/PHA+VGhpcyA0LCA1LCA2LCA3LCA4LCA5LCB6LCB7LCB8LCB9IHRlc3RzIEJhc2U2NCBlbmNv" 78 "ZGVyLiBTaG93IG1lOiBALCBBLCBCLCBDLCBELCBFLCBGLCBHLCBILCBJLCBKLCBLLCBMLCBNLCBO" 79 "LCBPLCBQLCBRLCBSLCBTLCBULCBVLCBWLCBXLCBYLCBZLCBaLCBbLCBcLCBdLCBeLCBfLCBgLCBh" 80 "LCBiLCBjLCBkLCBlLCBmLCBnLCBoLCBpLCBqLCBrLCBsLCBtLCBuLCBvLCBwLCBxLCByLCBzLg==" 83 static const auto c_numTests =
sizeof(s_tests) /
sizeof(s_tests[0]);
85 for (
size_t i = 0; i < c_numTests; ++i)
87 auto expectedDecoded = std::string{s_tests[i][0]};
88 auto expectedEncoded = std::string{s_tests[i][1]};
90 auto encoded =
toBase64(expectedDecoded);
92 auto decodedBytes =
fromBase64(expectedEncoded);
93 auto decoded =
bytesConstRef{decodedBytes.
data(), decodedBytes.size()}.toString();
const Object & get_obj() const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
std::string hexPrefixEncode(bytes const &_hexVector, bool _leaf, int _begin, int _end)
BOOST_AUTO_TEST_CASE(hexPrefix_test)
std::hash for asio::adress
std::string contentsString(std::string const &_file)
Retrieve and returns the contents of the given file as a std::string.
bool read_string(const String_type &s, Value_type &value)
std::vector< byte > bytes
std::string getTestPath()
std::string toBase64(bytesConstRef _in)
mConfig::Object_type mObject
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
bytes fromBase64(std::string const &_in)
#define BOOST_AUTO_TEST_SUITE_END()
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Helper functions to work with json::spirit and test files.
#define BOOST_CHECK(expr)