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