libcryfs/random/RandomGeneratorThread.h

35 lines
979 B
C
Raw Normal View History

#pragma once
#ifndef MESSMER_CPPUTILS_RANDOM_RANDOMGENERATORTHREAD_H
#define MESSMER_CPPUTILS_RANDOM_RANDOMGENERATORTHREAD_H
2015-11-07 09:00:25 +01:00
#include "../thread/LoopThread.h"
#include "ThreadsafeRandomDataBuffer.h"
#include <cryptopp/cryptopp/osrng.h>
namespace cpputils {
//TODO Test
2015-10-28 15:00:24 +01:00
class RandomGeneratorThread {
public:
RandomGeneratorThread(ThreadsafeRandomDataBuffer *buffer, size_t minSize, size_t maxSize);
2015-10-28 15:00:24 +01:00
void start();
private:
bool _loopIteration();
Data _generateRandomData(size_t size);
CryptoPP::AutoSeededRandomPool _randomGenerator;
ThreadsafeRandomDataBuffer *_buffer;
size_t _minSize;
size_t _maxSize;
2015-10-28 15:00:24 +01:00
//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