RandomPadding throws exception instead of ASSERT when data is too large
This commit is contained in:
parent
9c86b619a6
commit
71c808b229
@ -8,7 +8,9 @@ using namespace cpputils::logging;
|
||||
namespace cpputils {
|
||||
Data RandomPadding::add(const Data &data, size_t targetSize) {
|
||||
uint32_t size = data.size();
|
||||
ASSERT(size < targetSize - sizeof(size), "Config data too large. We should increase padding target size.");
|
||||
if (size >= targetSize - sizeof(size)) {
|
||||
throw std::runtime_error("Data too large. We should increase padding target size.");
|
||||
}
|
||||
Data randomData = Random::PseudoRandom().get(targetSize-sizeof(size)-size);
|
||||
ASSERT(sizeof(size) + size + randomData.size() == targetSize, "Calculated size of randomData incorrectly");
|
||||
Data result(targetSize);
|
||||
@ -29,4 +31,4 @@ namespace cpputils {
|
||||
std::memcpy(reinterpret_cast<char*>(result.data()), reinterpret_cast<const char*>(data.dataOffset(sizeof(size))), size);
|
||||
return std::move(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace cpputils {
|
||||
|
||||
//TODO Test Copy/move constructor and assignment
|
||||
//TODO Test operator==/!=
|
||||
//TODO Use SCryptSettings as a member here instead of storing _N, _r, _p.
|
||||
|
||||
class DerivedKeyConfig {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user