aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/random.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libtests/random.cc')
-rw-r--r--libtests/random.cc41
1 files changed, 16 insertions, 25 deletions
diff --git a/libtests/random.cc b/libtests/random.cc
index 70e5135e..2148111c 100644
--- a/libtests/random.cc
+++ b/libtests/random.cc
@@ -1,7 +1,7 @@
-#include <qpdf/QUtil.hh>
-#include <qpdf/qpdf-config.h>
#include <qpdf/InsecureRandomDataProvider.hh>
+#include <qpdf/QUtil.hh>
#include <qpdf/SecureRandomDataProvider.hh>
+#include <qpdf/qpdf-config.h>
#include <iostream>
class BogusRandomDataProvider: public RandomDataProvider
@@ -13,67 +13,58 @@ class BogusRandomDataProvider: public RandomDataProvider
BogusRandomDataProvider()
{
}
- virtual void provideRandomData(unsigned char* data, size_t len)
+ virtual void
+ provideRandomData(unsigned char* data, size_t len)
{
- for (size_t i = 0; i < len; ++i)
- {
+ for (size_t i = 0; i < len; ++i) {
data[i] = static_cast<unsigned char>(i & 0xff);
}
}
};
-int main()
+int
+main()
{
RandomDataProvider* orig_rdp = QUtil::getRandomDataProvider();
long r1 = QUtil::random();
long r2 = QUtil::random();
- if (r1 == r2)
- {
+ if (r1 == r2) {
std::cout << "fail: two randoms were the same\n";
}
InsecureRandomDataProvider irdp;
irdp.provideRandomData(reinterpret_cast<unsigned char*>(&r1), 4);
irdp.provideRandomData(reinterpret_cast<unsigned char*>(&r2), 4);
- if (r1 == r2)
- {
+ if (r1 == r2) {
std::cout << "fail: two insecure randoms were the same\n";
}
#ifndef SKIP_OS_SECURE_RANDOM
SecureRandomDataProvider srdp;
srdp.provideRandomData(reinterpret_cast<unsigned char*>(&r1), 4);
srdp.provideRandomData(reinterpret_cast<unsigned char*>(&r2), 4);
- if (r1 == r2)
- {
+ if (r1 == r2) {
std::cout << "fail: two secure randoms were the same\n";
}
#endif
BogusRandomDataProvider brdp;
QUtil::setRandomDataProvider(&brdp);
- if (QUtil::getRandomDataProvider() != &brdp)
- {
+ if (QUtil::getRandomDataProvider() != &brdp) {
std::cout << "fail: getRandomDataProvider didn't"
- " return our provider\n";
+ " return our provider\n";
}
r1 = QUtil::random();
r2 = QUtil::random();
- if (r1 != r2)
- {
+ if (r1 != r2) {
std::cout << "fail: two bogus randoms were different\n";
}
unsigned char buf[4];
QUtil::initializeWithRandomBytes(buf, 4);
- if (! ((buf[0] == 0) &&
- (buf[1] == 1) &&
- (buf[2] == 2) &&
- (buf[3] == 3)))
- {
+ if (!((buf[0] == 0) && (buf[1] == 1) && (buf[2] == 2) && (buf[3] == 3))) {
std::cout << "fail: bogus random didn't provide correct bytes\n";
}
QUtil::setRandomDataProvider(0);
- if (QUtil::getRandomDataProvider() != orig_rdp)
- {
+ if (QUtil::getRandomDataProvider() != orig_rdp) {
std::cout << "fail: passing null to setRandomDataProvider "
- "didn't reset the random data provider\n";
+ "didn't reset the random data provider\n";
}
std::cout << "random: end of tests\n";
return 0;