OpenVPN 3 Core Library
Loading...
Searching...
No Matches
rc Namespace Reference

Classes

struct  Arbitrary< openvpn::TunBuilderCapture::Route >
 Specialization of the Arbitrary template for TunBuilderCapture::Route. More...
 
struct  Arbitrary< openvpn::TunBuilderCapture::RouteAddress >
 Specialization of the Arbitrary struct for RouteAddress. More...
 
struct  Arbitrary< openvpn::TunBuilderCapture::RouteBase >
 Specialization of Arbitrary for the RouteBase type. More...
 
struct  Arbitrary< RedirectGatewayFlagsValues >
 Template specialization for generating arbitrary RedirectGatewayFlagsValues. More...
 
struct  Arbitrary< std::variant< T, Ts... > >
 Specialization of Arbitrary for creating arbitrary std::variant values. More...
 

Typedefs

using RedirectGatewayFlagsValues = openvpn::RedirectGatewayFlags::Flags
 
using RouteBased = std::variant< openvpn::TunBuilderCapture::Route, openvpn::TunBuilderCapture::RouteAddress, openvpn::TunBuilderCapture::RouteBase >
 Alias representing a route-based variant type.
 

Functions

template<size_t N>
auto atLeastOneFalse () -> Gen< std::array< bool, N > >
 Generates an array of booleans that contains at least one false.
 
template<size_t N>
auto generateValidityFlags (const bool all_valid=true) -> Gen< std::array< bool, N > >
 Generates an array of validity flags for component testing.
 
auto IPv4Octet (const bool valid=true) -> Gen< int >
 Generates a valid or invalid IPv4 octet value.
 
auto IPv4Address (const bool valid=true) -> Gen< std::string >
 Generates a random IPv4 address.
 
auto asciiPrintableCode () -> Gen< int >
 Generates a random printable ASCII character code.
 
auto hexChar (const bool valid=true) -> Gen< std::string >
 Generates a valid or invalid hexadecimal character.
 
auto IPv6HextetValue (const bool valid=true) -> Gen< std::string >
 Generates a hextet value of an IPv6 address.
 
std::string removeLeadingZerosFromHextet (const std::string &hextet)
 Removes leading zeros from a hextet (IPv6 segment).
 
void removeLeadingZerosFromHextets (std::vector< std::string > &hextets)
 Removes leading zeros from a vector of hextets.
 
void replaceSequenceOfZerosWithDoubleColon (std::vector< std::string > &hextets)
 Replaces the longest sequence of consecutive "0" strings in a vector with "::".
 
std::string stringifyHextetsToAddressWithColons (const std::vector< std::string > &hextets)
 Converts a vector of hextets to an IPv6 address string with colons.
 
std::string compressIPv6Address (std::vector< std::string > hextets)
 Compress an IPv6 address by simplifying its representation.
 
auto IPv6Address (const bool valid=true) -> Gen< std::string >
 Generates a random IPv6 address.
 
auto alpha (const bool valid=true) -> Gen< char >
 Generates alphabetic or non-alphabetic characters.
 
auto from_allowed_chars (const std::string_view &allowed_chars, const bool valid=true) -> Gen< char >
 Generates characters based on an allowed character set.
 
auto string_from_allowed_chars (const std::string_view &allowed_chars, const bool valid=true) -> Gen< std::string >
 Generates strings based on allowed characters.
 
auto port (const bool valid=true) -> Gen< int >
 Generates a port number value.
 
auto calculateIPPrefixRange (const std::string &ipAddress) -> std::tuple< int, int >
 Calculates the valid IP prefix range for a given IP address.
 

Variables

static const std::string ALPHA_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
static const std::string DIGITS = "1234567890"
 

Typedef Documentation

◆ RedirectGatewayFlagsValues

◆ RouteBased

Alias representing a route-based variant type.

This alias holds one of three possible route-related types: openvpn::TunBuilderCapture::Route, openvpn::TunBuilderCapture::RouteAddress, or openvpn::TunBuilderCapture::RouteBase.

Definition at line 502 of file test_generators.hpp.

Function Documentation

◆ alpha()

auto rc::alpha ( const bool  valid = true) -> Gen<char>
inline

Generates alphabetic or non-alphabetic characters.

Creates a generator that produces either valid alphabetic characters (A-Z, a-z) or non-alphabetic characters, depending on the input parameter. When generating valid alphabetic characters, it selects from a predefined set of characters. For invalid characters, it uses a character generator with a predicate that ensures the character is not alphabetic.

Parameters
validIf true (default), generates valid alphabetic characters. If false, generates non-alphabetic characters.
Returns
Gen<char> A generator that produces characters according to the specified criteria:
  • When valid=true: returns a generator for alphabetic characters (A-Z, a-z)
  • When valid=false: returns a generator for non-alphabetic characters

Definition at line 552 of file test_generators.hpp.

◆ asciiPrintableCode()

auto rc::asciiPrintableCode ( ) -> Gen<int>
inline

Generates a random printable ASCII character code.

This function generates an integer value representing printable ASCII character, ranging from 32 (space) to 126 (tilde) without 37 (percent sign)

Returns
A generator producing printable ASCII character code.
Warning
It does not generate percent sign (%)

Example usage:

auto code = *asciiPrintableCode();
auto asciiPrintableCode() -> Gen< int >
Generates a random printable ASCII character code.

Definition at line 155 of file test_generators.hpp.

Here is the caller graph for this function:

◆ atLeastOneFalse()

template<size_t N>
auto rc::atLeastOneFalse ( ) -> Gen<std::array<bool, N>>

Generates an array of booleans that contains at least one false.

This template function generates an array of booleans of size N such that at least one of the elements in the array is false.

Template Parameters
NThe size of the array to be generated.
Returns
A generator that produces array where at least one boolean value is false.

Example usage:

auto falseBoolean = *atLeastOneFalse<5>();

Definition at line 40 of file test_generators.hpp.

◆ calculateIPPrefixRange()

auto rc::calculateIPPrefixRange ( const std::string &  ipAddress) -> std::tuple<int, int>
inline

Calculates the valid IP prefix range for a given IP address.

This function takes an IPv4 address as a string and calculates the minimum and maximum valid prefix lengths. It converts the address to its integer representation and determines the smallest prefix that can correctly represent the network containing this address based on the position of the least significant '1' bit.

For example:

  • For 192.168.1.0, the range would be {24, 32}
  • For 10.0.0.0, the range would be {7, 32}
Parameters
ipAddressAn IPv4 address in dotted decimal notation (e.g., "192.168.1.0")
Returns
A tuple containing:
  • First element: The minimum valid prefix length (between 0 and 32)
  • Second element: The maximum valid prefix length (always 32)

Definition at line 654 of file test_generators.hpp.

◆ compressIPv6Address()

std::string rc::compressIPv6Address ( std::vector< std::string >  hextets)
inline

Compress an IPv6 address by simplifying its representation.

This function takes a list of hextets (hexadecimal segments of an IPv6 address), removes leading zeros from each hextet, replaces the largest contiguous sequence of zeroed hextets with a double colon (::), and converts the simplified hextets back into a string representation of the IPv6 address.

Parameters
hextetsA vector of strings, where each string represents one hextet of an IPv6 address.
Returns
A string containing the compressed IPv6 address.

Definition at line 321 of file test_generators.hpp.

Here is the caller graph for this function:

◆ from_allowed_chars()

auto rc::from_allowed_chars ( const std::string_view &  allowed_chars,
const bool  valid = true 
) -> Gen<char>
inline

Generates characters based on an allowed character set.

Creates a generator that either produces characters from a specified set of allowed characters, or characters that are specifically not in that set, depending on the valid parameter. When valid is true, it generates only characters from the allowed set. When valid is false, it generates only characters that are not in the allowed set.

Parameters
allowed_charsA string_view containing the set of allowed characters
validBoolean flag to determine whether to generate characters from the allowed set (true) or characters not in the allowed set (false). Defaults to true.
Returns
Gen<char> A character generator that produces either valid or invalid characters based on the allowed_chars set

Definition at line 577 of file test_generators.hpp.

Here is the caller graph for this function:

◆ generateValidityFlags()

template<size_t N>
auto rc::generateValidityFlags ( const bool  all_valid = true) -> Gen<std::array<bool, N>>

Generates an array of validity flags for component testing.

Template Parameters
NNumber of validity flags to generate
Parameters
all_validIf true, generates all flags as valid (true). If false, generates flags with at least one invalid (false) value.
Returns
Generator producing an array of N boolean flags. When all_valid is true : returns array with all elements set to true When all_valid is false : returns array with at least one element set to false

Example usage:

// Generate flags for testing URL components (all valid)
auto [scheme_is_valid, authority_is_valid] = *generateValidityFlags<2>(true);
// Generate flags with at least one invalid component
auto [scheme_is_valid, authority_is_valid] = *generateValidityFlags<2>(false);

Definition at line 74 of file test_generators.hpp.

◆ hexChar()

auto rc::hexChar ( const bool  valid = true) -> Gen<std::string>
inline

Generates a valid or invalid hexadecimal character.

This function generates a single hexadecimal character. If valid is true, it generates a value within the valid ranges of 0-9, A-F, and a-f. If valid is false, it generates a character outside of these ranges to represent an invalid hexadecimal character.

Parameters
validA boolean flag indicating whether to generate a valid or invalid hexadecimal character. Default is true.
Returns
A generator producing either valid or invalid hexadecimal character.

Example usage:

auto hex_generator = *hexChar();
auto hexChar(const bool valid=true) -> Gen< std::string >
Generates a valid or invalid hexadecimal character.

Definition at line 181 of file test_generators.hpp.

Here is the caller graph for this function:

◆ IPv4Address()

auto rc::IPv4Address ( const bool  valid = true) -> Gen<std::string>
inline

Generates a random IPv4 address.

This function generates a random IPv4 address. The validity of the octets can be controlled by the valid parameter. If valid is true, all four octets will be valid. Otherwise, at least one octet will be invalid. The resulting IPv4 address is formatted as X.X.X.X where X is a number between 0 and 255 (or an invalid value if valid is false).

Parameters
validA boolean flag indicating whether the generated address should be valid. Defaults to true.
Returns
A generator producing either valid on invalid IPv4 address.

Example usage:

auto address = *IPv4Address();
auto IPv4Address(const bool valid=true) -> Gen< std::string >
Generates a random IPv4 address.
remote_address address

Definition at line 125 of file test_generators.hpp.

◆ IPv4Octet()

auto rc::IPv4Octet ( const bool  valid = true) -> Gen<int>
inline

Generates a valid or invalid IPv4 octet value.

This function generates a value that represents an IPv4 octet. If valid is true, it generates a value within the valid range of 0 to 255. If valid is false, it generates values outside this range to represent an invalid octet.

Parameters
validA boolean flag indicating whether to generate a valid or invalid octet value. Default is true.
Returns
A generator producing either valid IPv4 octet value (0-255) or invalid value.

Example usage:

auto octet = *IPv4Octet();
auto IPv4Octet(const bool valid=true) -> Gen< int >
Generates a valid or invalid IPv4 octet value.

Definition at line 96 of file test_generators.hpp.

Here is the caller graph for this function:

◆ IPv6Address()

auto rc::IPv6Address ( const bool  valid = true) -> Gen<std::string>
inline

Generates a random IPv6 address.

This function generates a random IPv6 address. The validity of the hextets can be controlled by the valid parameter. If valid is true, all eight hextets will be valid. Otherwise, at least one hextet will be invalid. The resulting IPv6 address is formatted as X:X:X:X:X:X:X:X where X is a hextet (4 hex chars) within the valid ranges of 0-9, A-F, and a-f.

This function generates either a valid or an invalid IPv6 address.

Parameters
validA boolean flag indicating whether the generated IPv6 address should be valid. Defaults to true.
Returns
A generator that produces a valid or invalid IPv6 address.

Example usage:

auto address = *IPv6Address();
auto IPv6Address(const bool valid=true) -> Gen< std::string >
Generates a random IPv6 address.

Definition at line 345 of file test_generators.hpp.

◆ IPv6HextetValue()

auto rc::IPv6HextetValue ( const bool  valid = true) -> Gen<std::string>
inline

Generates a hextet value of an IPv6 address.

This function generates a hextet (4 characters) value of an IPv6 address, which may consist of valid or invalid hexadecimal characters based on the valid parameter.

Parameters
validA boolean indicating whether the generated hextet should only contain valid hexadecimal characters. If set to true, all characters will be valid. If set to false, at least one character will be invalid. Default is true.
Returns
A generator producing either valid or invalid hextet value.

Example usage:

auto hextet = *IPv6HextetValue();
auto IPv6HextetValue(const bool valid=true) -> Gen< std::string >
Generates a hextet value of an IPv6 address.

Definition at line 222 of file test_generators.hpp.

Here is the caller graph for this function:

◆ port()

auto rc::port ( const bool  valid = true) -> Gen<int>
inline

Generates a port number value.

Creates a generator that produces either valid or invalid port numbers. If valid is true, generates numbers in the valid port range [0, 65535]. If valid is false, generates numbers outside the valid port range.

Parameters
validBoolean flag to determine if valid (true) or invalid (false) port numbers should be generated. Defaults to true.
Returns
Gen<int> A generator that produces port numbers according to the valid parameter.

Definition at line 626 of file test_generators.hpp.

◆ removeLeadingZerosFromHextet()

std::string rc::removeLeadingZerosFromHextet ( const std::string &  hextet)
inline

Removes leading zeros from a hextet (IPv6 segment).

This function trims all leading zeros from a given hextet string. If the hextet only contains zeros (or is empty), it returns "0".

Parameters
hextetThe input string representing a hextet (e.g., "0001", "0ABC").
Returns
A string without leading zeros.

Definition at line 247 of file test_generators.hpp.

Here is the caller graph for this function:

◆ removeLeadingZerosFromHextets()

void rc::removeLeadingZerosFromHextets ( std::vector< std::string > &  hextets)
inline

Removes leading zeros from a vector of hextets.

This function modifies a vector of IPv6 hextets by removing leading zeros from each hextet using the removeLeadingZerosFromHextet transformation. The operation is performed in-place.

Parameters
hextetsA reference to a vector of strings representing IPv6 hextets. Each hextet will be stripped of its leading zeros.

Definition at line 261 of file test_generators.hpp.

Here is the caller graph for this function:

◆ replaceSequenceOfZerosWithDoubleColon()

void rc::replaceSequenceOfZerosWithDoubleColon ( std::vector< std::string > &  hextets)
inline

Replaces the longest sequence of consecutive "0" strings in a vector with "::".

This function finds the longest contiguous sequence of "0" strings in the provided hextets vector, replaces it with a single "::", and removes the other "0" strings in the sequence. If there are multiple sequences of the same length, it acts on the first one found.

Parameters
hextetsA vector of strings representing the hextets (subdivisions) of an IPv6 address.

Definition at line 274 of file test_generators.hpp.

Here is the caller graph for this function:

◆ string_from_allowed_chars()

auto rc::string_from_allowed_chars ( const std::string_view &  allowed_chars,
const bool  valid = true 
) -> Gen<std::string>
inline

Generates strings based on allowed characters.

Creates a generator that produces strings either containing only allowed characters or containing at least one character not in the allowed set. When valid is true, it generates strings using only allowed characters. When valid is false, it generates strings that contain at least one character not present in allowed_chars.

Parameters
allowed_charsA string_view containing the set of allowed characters
validBoolean flag to control generation mode:
  • true : generate strings using only allowed characters
  • false : generate strings containing at least one invalid character (defaults to true)
Returns
A generator that produces std::string values according to the specified constraints

Definition at line 605 of file test_generators.hpp.

◆ stringifyHextetsToAddressWithColons()

std::string rc::stringifyHextetsToAddressWithColons ( const std::vector< std::string > &  hextets)
inline

Converts a vector of hextets to an IPv6 address string with colons.

This function takes a vector of strings representing hextets (parts of an IPv6 address) and constructs a colon-separated IPv6 address. The function ensures that colons are correctly placed between the hextets, and it avoids adding redundant colons around "::" which represents a compressed sequence of zeroes in an IPv6 address.

Parameters
hextetsA vector of strings, where each string represents a hextet or "::".
Returns
A string representation of the IPv6 address with colons separating the hextets.

Definition at line 298 of file test_generators.hpp.

Here is the caller graph for this function:

Variable Documentation

◆ ALPHA_CHARACTERS

const std::string rc::ALPHA_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
static

Definition at line 534 of file test_generators.hpp.

◆ DIGITS

const std::string rc::DIGITS = "1234567890"
static

Definition at line 535 of file test_generators.hpp.