rippled
Loading...
Searching...
No Matches
tests/libxrpl/basics/base64.cpp
1#include <xrpl/basics/base64.h>
2
3#include <doctest/doctest.h>
4
5#include <string>
6
7using namespace ripple;
8
9static void
10check(std::string const& in, std::string const& out)
11{
12 auto const encoded = base64_encode(in);
13 CHECK(encoded == out);
14 CHECK(base64_decode(encoded) == in);
15}
16
17TEST_CASE("base64")
18{
19 check("", "");
20 check("f", "Zg==");
21 check("fo", "Zm8=");
22 check("foo", "Zm9v");
23 check("foob", "Zm9vYg==");
24 check("fooba", "Zm9vYmE=");
25 check("foobar", "Zm9vYmFy");
26
27 check(
28 "Man is distinguished, not only by his reason, but by this "
29 "singular passion from "
30 "other animals, which is a lust of the mind, that by a "
31 "perseverance of delight "
32 "in the continued and indefatigable generation of knowledge, "
33 "exceeds the short "
34 "vehemence of any carnal pleasure.",
35 "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dC"
36 "BieSB0aGlz"
37 "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIG"
38 "x1c3Qgb2Yg"
39 "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aG"
40 "UgY29udGlu"
41 "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleG"
42 "NlZWRzIHRo"
43 "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=");
44
45 std::string const notBase64 = "not_base64!!";
46 std::string const truncated = "not";
47 CHECK(base64_decode(notBase64) == base64_decode(truncated));
48}
void check(bool condition, std::string const &message)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string base64_decode(std::string_view data)
std::string base64_encode(std::uint8_t const *data, std::size_t len)