aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenĂ© Meusel <[email protected]>2022-04-05 09:59:35 +0200
committerGitHub <[email protected]>2022-04-05 09:59:35 +0200
commit13ca87fab8cfad8b1600c2507139b4336a991f6c (patch)
tree725f25371bd856c133896228f6796345f1e559d8
parentb0409695bc9362b159399ea40cafbe18902da812 (diff)
parent2e9b9f911e42395280cdf10d7b1dd73b7166e81c (diff)
Merge pull request #2949 from neXenio/tls13/fallback_rng
[TLS 1.3] Fallback for Fixed_Output_RNG
-rw-r--r--src/tests/test_rng.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/tests/test_rng.h b/src/tests/test_rng.h
index 080603a23..921ce6766 100644
--- a/src/tests/test_rng.h
+++ b/src/tests/test_rng.h
@@ -76,13 +76,23 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
m_buf.insert(m_buf.end(), output.begin(), output.end());
}
+ /**
+ * Provide a non-fixed RNG as fallback to be used once the Fixed_Output_RNG runs out of bytes.
+ * If more bytes are provided after that, those will be preferred over the fallback again.
+ */
+ Fixed_Output_RNG(RandomNumberGenerator& fallback_rng)
+ : m_fallback(&fallback_rng) {}
+
Fixed_Output_RNG() = default;
protected:
uint8_t random()
{
if(m_buf.empty())
{
- throw Test_Error("Fixed output RNG ran out of bytes, test bug?");
+ if(m_fallback.has_value())
+ return m_fallback.value()->next_byte();
+ else
+ throw Test_Error("Fixed output RNG ran out of bytes, test bug?");
}
uint8_t out = m_buf.front();
@@ -92,6 +102,7 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
private:
std::deque<uint8_t> m_buf;
+ std::optional<RandomNumberGenerator*> m_fallback;
};
/**