rippled
Loading...
Searching...
No Matches
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 <test/jtx/Env.h>
21
22#include <xrpl/beast/utility/temp_dir.h>
23#include <xrpl/crypto/csprng.h>
24
25namespace ripple {
26
28{
29 void
31 {
32 testcase("Get Values");
33 try
34 {
35 auto& engine = crypto_prng();
36 auto rand_val = engine();
37 BEAST_EXPECT(rand_val >= engine.min());
38 BEAST_EXPECT(rand_val <= engine.max());
39
40 uint16_t twoByte{0};
41 engine(&twoByte, sizeof(uint16_t));
42 pass();
43 }
44 catch (std::exception&)
45 {
46 fail();
47 }
48 }
49
50public:
51 void
52 run() override
53 {
55 }
56};
57
58BEAST_DEFINE_TESTSUITE(CryptoPRNG, core, ripple);
59
60} // namespace ripple
A testsuite class.
Definition: suite.h:55
void pass()
Record a successful test condition.
Definition: suite.h:511
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:155
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition: suite.h:533
void run() override
Runs the suite.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
csprng_engine & crypto_prng()
The default cryptographically secure PRNG.
Definition: csprng.cpp:103