rippled
CryptoPRNG_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2017 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 #include <ripple/beast/utility/temp_dir.h>
21 #include <ripple/crypto/csprng.h>
22 #include <boost/filesystem.hpp>
23 #include <fstream>
24 #include <streambuf>
25 #include <test/jtx/Env.h>
26 
27 namespace ripple {
28 
29 class CryptoPRNG_test : public beast::unit_test::suite
30 {
31  void
33  {
34  testcase("Get Values");
35  try
36  {
37  auto& engine = crypto_prng();
38  auto rand_val = engine();
39  BEAST_EXPECT(rand_val >= engine.min());
40  BEAST_EXPECT(rand_val <= engine.max());
41 
42  uint16_t twoByte{0};
43  engine(&twoByte, sizeof(uint16_t));
44  pass();
45  }
46  catch (std::exception&)
47  {
48  fail();
49  }
50  }
51 
52 public:
53  void
54  run() override
55  {
56  testGetValues();
57  }
58 };
59 
60 BEAST_DEFINE_TESTSUITE(CryptoPRNG, core, ripple);
61 
62 } // namespace ripple
ripple::CryptoPRNG_test
Definition: CryptoPRNG_test.cpp:29
fstream
ripple::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
std::exception
STL class.
streambuf
ripple::crypto_prng
csprng_engine & crypto_prng()
The default cryptographically secure PRNG.
Definition: csprng.cpp:99
ripple::CryptoPRNG_test::testGetValues
void testGetValues()
Definition: CryptoPRNG_test.cpp:32
ripple::CryptoPRNG_test::run
void run() override
Definition: CryptoPRNG_test.cpp:54
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29