libcryfs/random/Random.h

34 lines
775 B
C
Raw Normal View History

2015-10-22 17:36:03 +02:00
#pragma once
#ifndef MESSMER_CPPUTILS_RANDOM_RANDOM_H
#define MESSMER_CPPUTILS_RANDOM_RANDOM_H
#include "PseudoRandomPool.h"
#include "OSRandomGenerator.h"
#include "../data/FixedSizeData.h"
#include "../data/Data.h"
#include <mutex>
namespace cpputils {
class Random final {
2015-10-22 17:36:03 +02:00
public:
static PseudoRandomPool &PseudoRandom() {
std::unique_lock <std::mutex> lock(_mutex);
static PseudoRandomPool random;
return random;
}
static OSRandomGenerator &OSRandom() {
std::unique_lock <std::mutex> lock(_mutex);
static OSRandomGenerator random;
return random;
}
private:
static std::mutex _mutex;
DISALLOW_COPY_AND_ASSIGN(Random);
2015-10-22 17:36:03 +02:00
};
}
#endif