aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_rng.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-01 21:20:55 +0000
committerlloyd <[email protected]>2014-01-01 21:20:55 +0000
commit197dc467dec28a04c3b2f30da7cef122dfbb13e9 (patch)
treecdbd3ddaec051c72f0a757db461973d90c37b97a /src/tests/test_rng.h
parent62faac373c07cfe10bc8c309e89ebdd30d8e5eaa (diff)
Shuffle things around. Add NIST X.509 test to build.
Diffstat (limited to 'src/tests/test_rng.h')
-rw-r--r--src/tests/test_rng.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/tests/test_rng.h b/src/tests/test_rng.h
new file mode 100644
index 000000000..b3da5f08a
--- /dev/null
+++ b/src/tests/test_rng.h
@@ -0,0 +1,61 @@
+
+#ifndef BOTAN_TESTS_FIXED_RNG_H__
+#define BOTAN_TESTS_FIXED_RNG_H__
+
+#include <deque>
+#include <string>
+#include <stdexcept>
+#include <botan/rng.h>
+#include <botan/hex.h>
+
+using Botan::byte;
+
+class Fixed_Output_RNG : public Botan::RandomNumberGenerator
+ {
+ public:
+ bool is_seeded() const { return !buf.empty(); }
+
+ byte random()
+ {
+ if(!is_seeded())
+ throw std::runtime_error("Out of bytes");
+
+ byte out = buf.front();
+ buf.pop_front();
+ return out;
+ }
+
+ void reseed(size_t) {}
+
+ void randomize(byte out[], size_t len)
+ {
+ for(size_t j = 0; j != len; j++)
+ out[j] = random();
+ }
+
+ void add_entropy(const byte b[], size_t s)
+ {
+ buf.insert(buf.end(), b, b + s);
+ }
+
+ std::string name() const { return "Fixed_Output_RNG"; }
+
+ void clear() throw() {}
+
+ Fixed_Output_RNG(const std::vector<byte>& in)
+ {
+ buf.insert(buf.end(), in.begin(), in.end());
+ }
+
+ Fixed_Output_RNG(const std::string& in_str)
+ {
+ std::vector<byte> in = Botan::hex_decode(in_str);
+ buf.insert(buf.end(), in.begin(), in.end());
+ }
+
+ Fixed_Output_RNG() {}
+ private:
+ std::deque<byte> buf;
+ };
+
+#endif