Skip to content

Commit

Permalink
Add Test::random_index test utility
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Jan 20, 2025
1 parent 1dc31ad commit fa5c704
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <botan/internal/cpuid.h>
#include <botan/internal/filesystem.h>
#include <botan/internal/fmt.h>
#include <botan/internal/loadstor.h>
#include <botan/internal/parsing.h>
#include <botan/internal/stl_util.h>
#include <fstream>
Expand Down Expand Up @@ -842,6 +843,10 @@ std::string Test::random_password(Botan::RandomNumberGenerator& rng) {
return Botan::hex_encode(rng.random_vec(len));
}

size_t Test::random_index(Botan::RandomNumberGenerator& rng, size_t max) {
return Botan::load_be(rng.random_array<8>()) % max;
}

std::vector<std::vector<uint8_t>> VarMap::get_req_bin_list(const std::string& key) const {
auto i = m_vars.find(key);
if(i == m_vars.end()) {
Expand Down
1 change: 1 addition & 0 deletions src/tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ class Test {
static std::shared_ptr<Botan::RandomNumberGenerator> new_shared_rng(std::string_view test_name);

static std::string random_password(Botan::RandomNumberGenerator& rng);
static size_t random_index(Botan::RandomNumberGenerator& rng, size_t max);
static uint64_t timestamp(); // nanoseconds arbitrary epoch

static std::vector<Test::Result> flatten_result_lists(std::vector<std::vector<Test::Result>> result_lists);
Expand Down

0 comments on commit fa5c704

Please sign in to comment.