libcryfs/random/RandomGeneratorThread.h
2015-11-12 13:07:20 -08:00

35 lines
979 B
C++

#pragma once
#ifndef MESSMER_CPPUTILS_RANDOM_RANDOMGENERATORTHREAD_H
#define MESSMER_CPPUTILS_RANDOM_RANDOMGENERATORTHREAD_H
#include "../thread/LoopThread.h"
#include "ThreadsafeRandomDataBuffer.h"
#include <cryptopp/cryptopp/osrng.h>
namespace cpputils {
//TODO Test
class RandomGeneratorThread {
public:
RandomGeneratorThread(ThreadsafeRandomDataBuffer *buffer, size_t minSize, size_t maxSize);
void start();
private:
bool _loopIteration();
Data _generateRandomData(size_t size);
CryptoPP::AutoSeededRandomPool _randomGenerator;
ThreadsafeRandomDataBuffer *_buffer;
size_t _minSize;
size_t _maxSize;
//This has to be the last member, because it has to be destructed first - otherwise the thread could still be
//running while the RandomGeneratorThread object is invalid.
LoopThread _thread;
DISALLOW_COPY_AND_ASSIGN(RandomGeneratorThread);
};
}
#endif