rippled
base64_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2018 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 //
21 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
22 //
23 // Distributed under the Boost Software License, Version 1.0. (See accompanying
24 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
25 //
26 // Official repository: https://github.com/boostorg/beast
27 //
28 
29 #include <ripple/basics/base64.h>
30 #include <ripple/beast/unit_test.h>
31 
32 namespace ripple {
33 
34 class base64_test : public beast::unit_test::suite
35 {
36 public:
37  void
38  check(std::string const& in, std::string const& out)
39  {
40  auto const encoded = base64_encode(in);
41  BEAST_EXPECT(encoded == out);
42  BEAST_EXPECT(base64_decode(encoded) == in);
43  }
44 
45  void
46  run() override
47  {
48  check("", "");
49  check("f", "Zg==");
50  check("fo", "Zm8=");
51  check("foo", "Zm9v");
52  check("foob", "Zm9vYg==");
53  check("fooba", "Zm9vYmE=");
54  check("foobar", "Zm9vYmFy");
55 
56  check(
57  "Man is distinguished, not only by his reason, but by this "
58  "singular passion from "
59  "other animals, which is a lust of the mind, that by a "
60  "perseverance of delight "
61  "in the continued and indefatigable generation of knowledge, "
62  "exceeds the short "
63  "vehemence of any carnal pleasure.",
64  "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dC"
65  "BieSB0aGlz"
66  "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIG"
67  "x1c3Qgb2Yg"
68  "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aG"
69  "UgY29udGlu"
70  "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleG"
71  "NlZWRzIHRo"
72  "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=");
73 
74  std::string const notBase64 = "not_base64!!";
75  std::string const truncated = "not";
76  BEAST_EXPECT(base64_decode(notBase64) == base64_decode(truncated));
77  }
78 };
79 
80 BEAST_DEFINE_TESTSUITE(base64, ripple_basics, ripple);
81 
82 } // namespace ripple
std::string
STL class.
ripple::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
ripple::base64_encode
std::string base64_encode(std::uint8_t const *data, std::size_t len)
Definition: base64.cpp:236
ripple::QualityDirection::in
@ in
ripple::base64_test::run
void run() override
Definition: base64_test.cpp:46
ripple::QualityDirection::out
@ out
ripple::base64_decode
std::string base64_decode(std::string const &data)
Definition: base64.cpp:245
ripple::base64_test
Definition: base64_test.cpp:34
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::base64_test::check
void check(std::string const &in, std::string const &out)
Definition: base64_test.cpp:38