Allow calling RandomGenerator::get() on child classes (failed due to overridden overload)

This commit is contained in:
Sebastian Messmer 2015-10-23 20:21:17 +02:00
parent 233f1a2ecb
commit 6e4ecd6e19
3 changed files with 7 additions and 7 deletions

View File

@ -11,12 +11,12 @@ namespace cpputils {
OSRandomGenerator();
protected:
void get(void *target, size_t bytes) override;
void _get(void *target, size_t bytes) override;
};
inline OSRandomGenerator::OSRandomGenerator() {}
inline void OSRandomGenerator::get(void *target, size_t bytes) {
inline void OSRandomGenerator::_get(void *target, size_t bytes) {
CryptoPP::OS_GenerateRandomBlock(true, (byte*)target, bytes);
}
}

View File

@ -15,7 +15,7 @@ namespace cpputils {
PseudoRandomPool();
protected:
void get(void *target, size_t bytes) override;
void _get(void *target, size_t bytes) override;
private:
static constexpr size_t MIN_BUFFER_SIZE = 1*1024*1024; // 1MB
@ -27,7 +27,7 @@ namespace cpputils {
};
inline void PseudoRandomPool::get(void *target, size_t bytes) {
inline void PseudoRandomPool::_get(void *target, size_t bytes) {
_buffer.get(target, bytes);
}

View File

@ -11,20 +11,20 @@ namespace cpputils {
Data get(size_t size);
protected:
virtual void get(void *target, size_t bytes) = 0;
virtual void _get(void *target, size_t bytes) = 0;
private:
static std::mutex _mutex;
};
template<size_t SIZE> inline FixedSizeData<SIZE> RandomGenerator::getFixedSize() {
FixedSizeData<SIZE> result = FixedSizeData<SIZE>::Null();
get(result.data(), SIZE);
_get(result.data(), SIZE);
return result;
}
inline Data RandomGenerator::get(size_t size) {
Data result(size);
get(result.data(), size);
_get(result.data(), size);
return result;
}
}