OpenVPN 3 Core Library
Loading...
Searching...
No Matches
FakeSecureRand Class Reference

#include <test_helper.hpp>

Inheritance diagram for FakeSecureRand:
[legend]
Collaboration diagram for FakeSecureRand:
[legend]

Public Member Functions

 FakeSecureRand (const unsigned char initial=0)
 
virtual std::string name () const override
 Get the name of the random number generation algorithm.
 
virtual void rand_bytes (unsigned char *buf, size_t size) override
 Fill a buffer with random bytes.
 
virtual bool rand_bytes_noexcept (unsigned char *buf, size_t size) override
 Fill a buffer with random bytes without throwing exceptions.
 
- Public Member Functions inherited from openvpn::RandomAPI
template<typename T >
void rand_fill (T &obj)
 Fill a data object with random bytes.
 
template<typename T >
rand_get ()
 Create a data object filled with random bytes.
 
template<typename T >
rand_get_positive ()
 Create a data object filled with random bytes, always >= 0 for signed types.
 
template<typename T >
randrange (const T end)
 Return a uniformly distributed random number in the range [0, end)
 
template<typename T >
randrange (const T start, const T end)
 Return a uniformly distributed random number in the range [start, end].
 
std::uint32_t randrange32 (const std::uint32_t end)
 Return a uniformly distributed random number in the range [0, end)
 
std::uint32_t randrange32 (const std::uint32_t start, const std::uint32_t end)
 Return a uniformly distributed random number in the range [start, end].
 
std::uint8_t randbyte ()
 Return a random byte.
 
bool randbool ()
 Return a random boolean.
 
result_type operator() ()
 
- Public Member Functions inherited from openvpn::RC< thread_unsafe_refcount >
 RC () noexcept=default
 
 RC (const RC &)=delete
 
virtual ~RC ()=default
 
RCoperator= (const RC &)=delete
 
olong use_count () const noexcept
 Delegates call to RCImpl and returns the result.
 

Private Member Functions

void rand_bytes_ (unsigned char *buf, size_t size)
 

Private Attributes

unsigned char next
 

Additional Inherited Members

- Public Types inherited from openvpn::StrongRandomAPI
typedef RCPtr< StrongRandomAPIPtr
 Smart pointer type for managing the ownership of StrongRandomAPI objects.
 
- Public Types inherited from openvpn::RandomAPI
typedef RCPtr< RandomAPIPtr
 Smart pointer type for managing the ownership of RandomAPI objects.
 
typedef unsigned int result_type
 
- Public Types inherited from openvpn::RC< thread_unsafe_refcount >
typedef RCPtr< RCPtr
 
- Static Public Member Functions inherited from openvpn::RandomAPI
static constexpr result_type min ()
 
static constexpr result_type max ()
 
- Static Public Member Functions inherited from openvpn::RC< thread_unsafe_refcount >
static constexpr bool is_thread_safe ()
 Delegates call to RCImpl and returns the result.
 

Detailed Description

Predictable RNG that claims to be secure to be used in reproducable unit tests

Note: this is not fit to be used as UniformRandomBitGenerator since its maximum range is [0x03020100, 0xfffefdfc]. Especially the lower bound makes the std::shuffle implementation in libc++ loop endlessly.

Definition at line 334 of file test_helper.hpp.

Constructor & Destructor Documentation

◆ FakeSecureRand()

FakeSecureRand::FakeSecureRand ( const unsigned char  initial = 0)
inline

Definition at line 337 of file test_helper.hpp.

Member Function Documentation

◆ name()

virtual std::string FakeSecureRand::name ( ) const
inlineoverridevirtual

Get the name of the random number generation algorithm.

Returns
The name of the algorithm

Implements openvpn::RandomAPI.

Definition at line 342 of file test_helper.hpp.

◆ rand_bytes()

virtual void FakeSecureRand::rand_bytes ( unsigned char *  buf,
size_t  size 
)
inlineoverridevirtual

Fill a buffer with random bytes.

Parameters
bufPointer to the buffer
sizeNumber of bytes to generate

Implements openvpn::RandomAPI.

Definition at line 347 of file test_helper.hpp.

Here is the caller graph for this function:

◆ rand_bytes_()

void FakeSecureRand::rand_bytes_ ( unsigned char *  buf,
size_t  size 
)
inlineprivate

Definition at line 361 of file test_helper.hpp.

Here is the caller graph for this function:

◆ rand_bytes_noexcept()

virtual bool FakeSecureRand::rand_bytes_noexcept ( unsigned char *  buf,
size_t  size 
)
inlineoverridevirtual

Fill a buffer with random bytes without throwing exceptions.

Parameters
bufPointer to the buffer
sizeNumber of bytes to generate
Returns
true on success
false on failure

Implements openvpn::RandomAPI.

Definition at line 353 of file test_helper.hpp.

Member Data Documentation

◆ next

unsigned char FakeSecureRand::next
private

Definition at line 367 of file test_helper.hpp.


The documentation for this class was generated from the following file: