Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_base64.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE base64
2#include <boost/test/included/unit_test.hpp>
3
6
7using namespace fc;
8using namespace std::literals;
9
10BOOST_AUTO_TEST_SUITE(base64)
11
13 auto input = "abc123$&()'?\xb4\xf5\x01\xfa~a"s;
14 auto expected_output = "YWJjMTIzJCYoKSc/tPUB+n5h"s;
15
16 BOOST_CHECK_EQUAL(expected_output, base64_encode(input));
18
19BOOST_AUTO_TEST_CASE(base64urlenc) try {
20 auto input = "abc123$&()'?\xb4\xf5\x01\xfa~a"s;
21 auto expected_output = "YWJjMTIzJCYoKSc_tPUB-n5h"s;
22
23 BOOST_CHECK_EQUAL(expected_output, base64url_encode(input));
25
26BOOST_AUTO_TEST_CASE(base64dec) try {
27 auto input = "YWJjMTIzJCYoKSc/tPUB+n5h"s;
28 auto expected_output = "abc123$&()'?\xb4\xf5\x01\xfa~a"s;
29
30 BOOST_CHECK_EQUAL(expected_output, base64_decode(input));
32
33BOOST_AUTO_TEST_CASE(base64urldec) try {
34 auto input = "YWJjMTIzJCYoKSc_tPUB-n5h"s;
35 auto expected_output = "abc123$&()'?\xb4\xf5\x01\xfa~a"s;
36
37 BOOST_CHECK_EQUAL(expected_output, base64url_decode(input));
39
40BOOST_AUTO_TEST_CASE(base64dec_extraequals) try {
41 auto input = "YWJjMTIzJCYoKSc/tPUB+n5h========="s;
42 auto expected_output = "abc123$&()'?\xb4\xf5\x01\xfa~a"s;
43
44 BOOST_CHECK_EQUAL(expected_output, base64_decode(input));
46
47BOOST_AUTO_TEST_CASE(base64dec_bad_stuff) try {
48 auto input = "YWJjMTIzJCYoKSc/tPU$B+n5h="s;
49
50 BOOST_CHECK_EXCEPTION(base64_decode(input), fc::exception, [](const fc::exception& e) {
51 return e.to_detail_string().find("encountered non-base64 character") != std::string::npos;
52 });
54
55BOOST_AUTO_TEST_SUITE_END()
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
std::string to_detail_string(log_level ll=log_level::all) const
Defines exception's used by fc.
namespace sysio::chain
Definition authority.cpp:3
std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
Definition base64.cpp:92
std::string base64url_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
Definition base64.cpp:101
std::string base64url_decode(const std::string &encoded_string)
Definition base64.cpp:156
std::string base64_decode(const std::string &encoded_string)
Definition base64.cpp:152
BOOST_AUTO_TEST_CASE(base64enc)
FC_LOG_AND_RETHROW()
char * s