From b3bffeff3553f4b609afe634c8c8b56ca0a2384c Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 18 Jan 2014 21:26:38 +0000 Subject: More unique_ptr, also cleanup MGF1 usage --- src/lib/entropy/proc_walk/proc_walk.cpp | 30 ++++-------------------------- src/lib/entropy/proc_walk/proc_walk.h | 10 ++++++++-- 2 files changed, 12 insertions(+), 28 deletions(-) (limited to 'src/lib/entropy') 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& 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 m_dir; }; } -- cgit v1.2.3