aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/rng/rng.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-10-12 15:32:14 -0400
committerJack Lloyd <[email protected]>2016-10-12 15:32:14 -0400
commited9e147695e4c5e800e83654baf365a634f3a2a7 (patch)
tree59bad402cff7d7af9baa5fd79081d677b60afc83 /src/lib/rng/rng.h
parentd59b164a2ad2bc2290265530ac1a5c7be7855975 (diff)
Abstract out mutex type. Make threads optional.
Diffstat (limited to 'src/lib/rng/rng.h')
-rw-r--r--src/lib/rng/rng.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/lib/rng/rng.h b/src/lib/rng/rng.h
index d1cdcfff2..e3640a32f 100644
--- a/src/lib/rng/rng.h
+++ b/src/lib/rng/rng.h
@@ -11,9 +11,9 @@
#include <botan/entropy_src.h>
#include <botan/secmem.h>
#include <botan/exceptn.h>
+#include <botan/mutex.h>
#include <chrono>
#include <string>
-#include <mutex>
namespace Botan {
@@ -193,6 +193,7 @@ class BOTAN_DLL Null_RNG final : public RandomNumberGenerator
std::string name() const override { return "Null_RNG"; }
};
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
/**
* Wraps access to a RNG in a mutex
*/
@@ -201,25 +202,25 @@ class BOTAN_DLL Serialized_RNG final : public RandomNumberGenerator
public:
void randomize(byte out[], size_t len) override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
m_rng->randomize(out, len);
}
bool is_seeded() const override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return m_rng->is_seeded();
}
void clear() override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
m_rng->clear();
}
std::string name() const override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return m_rng->name();
}
@@ -227,23 +228,24 @@ class BOTAN_DLL Serialized_RNG final : public RandomNumberGenerator
size_t poll_bits = BOTAN_RNG_RESEED_POLL_BITS,
std::chrono::milliseconds poll_timeout = BOTAN_RNG_RESEED_DEFAULT_TIMEOUT) override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
return m_rng->reseed(src, poll_bits, poll_timeout);
}
void add_entropy(const byte in[], size_t len) override
{
- std::lock_guard<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_type> lock(m_mutex);
m_rng->add_entropy(in, len);
}
- BOTAN_DEPRECATED("Create an AutoSeeded_RNG for other constructor") Serialized_RNG();
+ BOTAN_DEPRECATED("Use Serialized_RNG(new AutoSeeded_RNG)") Serialized_RNG();
explicit Serialized_RNG(RandomNumberGenerator* rng) : m_rng(rng) {}
private:
- mutable std::mutex m_mutex;
+ mutable mutex_type m_mutex;
std::unique_ptr<RandomNumberGenerator> m_rng;
};
+#endif
}