Botan  2.1.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | List of all members
Botan::Entropy_Sources Class Referencefinal

#include <entropy_src.h>

Public Member Functions

void add_source (std::unique_ptr< Entropy_Source > src)
 
std::vector< std::string > enabled_sources () const
 
 Entropy_Sources ()
 
 Entropy_Sources (const std::vector< std::string > &sources)
 
size_t poll (RandomNumberGenerator &rng, size_t bits, std::chrono::milliseconds timeout)
 
size_t poll_just (RandomNumberGenerator &rng, const std::string &src)
 
 ~Entropy_Sources ()
 

Static Public Member Functions

static Entropy_Sourcesglobal_sources ()
 

Detailed Description

Definition at line 51 of file entropy_src.h.

Constructor & Destructor Documentation

Botan::Entropy_Sources::Entropy_Sources ( )
inline

Definition at line 69 of file entropy_src.h.

69 {}
Botan::Entropy_Sources::Entropy_Sources ( const std::vector< std::string > &  sources)
explicit

Definition at line 160 of file entropy_srcs.cpp.

References add_source(), and Botan::Entropy_Source::create().

161  {
162  for(auto&& src_name : sources)
163  {
165  }
166  }
void add_source(std::unique_ptr< Entropy_Source > src)
static std::unique_ptr< Entropy_Source > create(const std::string &type)
Botan::Entropy_Sources::~Entropy_Sources ( )

Definition at line 168 of file entropy_srcs.cpp.

169  {
170  for(size_t i = 0; i != m_srcs.size(); ++i)
171  {
172  delete m_srcs[i];
173  m_srcs[i] = nullptr;
174  }
175  m_srcs.clear();
176  }

Member Function Documentation

void Botan::Entropy_Sources::add_source ( std::unique_ptr< Entropy_Source src)

Definition at line 108 of file entropy_srcs.cpp.

Referenced by Entropy_Sources().

109  {
110  if(src.get())
111  {
112  m_srcs.push_back(src.release());
113  }
114  }
std::vector< std::string > Botan::Entropy_Sources::enabled_sources ( ) const

Definition at line 116 of file entropy_srcs.cpp.

117  {
118  std::vector<std::string> sources;
119  for(size_t i = 0; i != m_srcs.size(); ++i)
120  {
121  sources.push_back(m_srcs[i]->name());
122  }
123  return sources;
124  }
Entropy_Sources & Botan::Entropy_Sources::global_sources ( )
static

Definition at line 178 of file entropy_srcs.cpp.

179  {
180  static Entropy_Sources global_entropy_sources(BOTAN_ENTROPY_DEFAULT_SOURCES);
181 
182  return global_entropy_sources;
183  }
size_t Botan::Entropy_Sources::poll ( RandomNumberGenerator rng,
size_t  bits,
std::chrono::milliseconds  timeout 
)

Definition at line 126 of file entropy_srcs.cpp.

Referenced by Botan::RandomNumberGenerator::reseed().

129  {
130  typedef std::chrono::system_clock clock;
131 
132  auto deadline = clock::now() + timeout;
133 
134  size_t bits_collected = 0;
135 
136  for(Entropy_Source* src : m_srcs)
137  {
138  bits_collected += src->poll(rng);
139 
140  if (bits_collected >= poll_bits || clock::now() > deadline)
141  break;
142  }
143 
144  return bits_collected;
145  }
size_t Botan::Entropy_Sources::poll_just ( RandomNumberGenerator rng,
const std::string &  src 
)

Poll just a single named source. Ordinally only used for testing

Definition at line 147 of file entropy_srcs.cpp.

148  {
149  for(size_t i = 0; i != m_srcs.size(); ++i)
150  {
151  if(m_srcs[i]->name() == the_src)
152  {
153  return m_srcs[i]->poll(rng);
154  }
155  }
156 
157  return 0;
158  }

The documentation for this class was generated from the following files: