aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/entropy
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-18 21:26:38 +0000
committerlloyd <[email protected]>2014-01-18 21:26:38 +0000
commitb3bffeff3553f4b609afe634c8c8b56ca0a2384c (patch)
treee81f39a9f86fcefffdf9e7704dd0b7a7c337edb7 /src/lib/entropy
parentef465af87d61c0cfbba17b86a3e1cc48b90ab391 (diff)
More unique_ptr, also cleanup MGF1 usage
Diffstat (limited to 'src/lib/entropy')
-rw-r--r--src/lib/entropy/proc_walk/proc_walk.cpp30
-rw-r--r--src/lib/entropy/proc_walk/proc_walk.h10
2 files changed, 12 insertions, 28 deletions
diff --git a/src/lib/entropy/proc_walk/proc_walk.cpp b/src/lib/entropy/proc_walk/proc_walk.cpp
index 050d9dcf7..5a72f46e5 100644
--- a/src/lib/entropy/proc_walk/proc_walk.cpp
+++ b/src/lib/entropy/proc_walk/proc_walk.cpp
@@ -24,20 +24,6 @@
namespace Botan {
-/**
-* Returns file descriptors. Until it doesn't
-*/
-class File_Descriptor_Source
- {
- public:
- /**
- * @return next file descriptor, or -1 if done
- */
- virtual int next_fd() = 0;
-
- virtual ~File_Descriptor_Source() {}
- };
-
namespace {
class Directory_Walker : public File_Descriptor_Source
@@ -130,20 +116,13 @@ int Directory_Walker::next_fd()
}
-/**
-* ProcWalking_EntropySource Destructor
-*/
-ProcWalking_EntropySource::~ProcWalking_EntropySource()
- {
- // for ~unique_ptr
- }
-
void ProcWalking_EntropySource::poll(Entropy_Accumulator& accum)
{
const size_t MAX_FILES_READ_PER_POLL = 2048;
+ const double ENTROPY_ESTIMATE = 1.0 / (8*1024);
if(!m_dir)
- m_dir = new Directory_Walker(m_path);
+ m_dir.reset(new Directory_Walker(m_path));
secure_vector<byte>& io_buffer = accum.get_io_buffer(4096);
@@ -154,8 +133,7 @@ void ProcWalking_EntropySource::poll(Entropy_Accumulator& accum)
// If we've exhaused this walk of the directory, halt the poll
if(fd == -1)
{
- delete m_dir;
- m_dir = nullptr;
+ m_dir.reset();
break;
}
@@ -163,7 +141,7 @@ void ProcWalking_EntropySource::poll(Entropy_Accumulator& accum)
::close(fd);
if(got > 0)
- accum.add(&io_buffer[0], got, .001);
+ accum.add(&io_buffer[0], got, ENTROPY_ESTIMATE);
if(accum.polling_goal_achieved())
break;
diff --git a/src/lib/entropy/proc_walk/proc_walk.h b/src/lib/entropy/proc_walk/proc_walk.h
index 04c3b1bba..3d4c4e4da 100644
--- a/src/lib/entropy/proc_walk/proc_walk.h
+++ b/src/lib/entropy/proc_walk/proc_walk.h
@@ -13,6 +13,13 @@
namespace Botan {
+class File_Descriptor_Source
+ {
+ public:
+ virtual int next_fd() = 0;
+ virtual ~File_Descriptor_Source() {}
+ };
+
/**
* File Tree Walking Entropy Source
*/
@@ -26,10 +33,9 @@ class ProcWalking_EntropySource : public EntropySource
ProcWalking_EntropySource(const std::string& root_dir) :
m_path(root_dir), m_dir(nullptr) {}
- ~ProcWalking_EntropySource();
private:
const std::string m_path;
- class File_Descriptor_Source* m_dir;
+ std::unique_ptr<File_Descriptor_Source> m_dir;
};
}