mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-01 09:50:54 +00:00
Increase random data provider support
Add a method to get the current random data provider, and document and test the method for resetting it.
This commit is contained in:
parent
b8b273d14d
commit
235d8f28f8
|
@ -1,3 +1,10 @@
|
||||||
|
2013-12-16 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* Document and make explicit that passing null to
|
||||||
|
QUtil::setRandomDataProvider() resets the random data provider.
|
||||||
|
|
||||||
|
* Provide QUtil::getRandomDataProvider().
|
||||||
|
|
||||||
2013-12-14 Jay Berkenbilt <ejb@ql.org>
|
2013-12-14 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* Allow anyspace rather than just newline to follow xref header.
|
* Allow anyspace rather than just newline to follow xref header.
|
||||||
|
|
|
@ -142,9 +142,20 @@ namespace QUtil
|
||||||
// memory for the RandomDataProvider. This method modifies a
|
// memory for the RandomDataProvider. This method modifies a
|
||||||
// static variable. If you are providing your own random data
|
// static variable. If you are providing your own random data
|
||||||
// provider, you should call this at the beginning of your program
|
// provider, you should call this at the beginning of your program
|
||||||
// before creating any QPDF objects.
|
// before creating any QPDF objects. Passing a null to this
|
||||||
|
// method will reset the library back to whichever of the built-in
|
||||||
|
// random data handlers is appropriate basedon how qpdf was
|
||||||
|
// compiled.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
void setRandomDataProvider(RandomDataProvider*);
|
void setRandomDataProvider(RandomDataProvider*);
|
||||||
|
|
||||||
|
// This returns the random data provider that would be used the
|
||||||
|
// next time qpdf needs random data. It will never return null.
|
||||||
|
// If no random data provider has been provided and the library
|
||||||
|
// was not compiled with any random data provider available, an
|
||||||
|
// exception will be thrown.
|
||||||
|
QPDF_DLL
|
||||||
|
RandomDataProvider* getRandomDataProvider();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __QUTIL_HH__
|
#endif // __QUTIL_HH__
|
||||||
|
|
|
@ -423,6 +423,8 @@ initialize_random_data_provider()
|
||||||
random_data_provider = insecure_random_data_provider;
|
random_data_provider = insecure_random_data_provider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// QUtil.hh has comments indicating that getRandomDataProvider(),
|
||||||
|
// which calls this method, never returns null.
|
||||||
if (random_data_provider == 0)
|
if (random_data_provider == 0)
|
||||||
{
|
{
|
||||||
throw std::logic_error("QPDF has no random data provider");
|
throw std::logic_error("QPDF has no random data provider");
|
||||||
|
@ -435,6 +437,13 @@ QUtil::setRandomDataProvider(RandomDataProvider* p)
|
||||||
random_data_provider = p;
|
random_data_provider = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomDataProvider*
|
||||||
|
QUtil::getRandomDataProvider()
|
||||||
|
{
|
||||||
|
initialize_random_data_provider();
|
||||||
|
return random_data_provider;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QUtil::initializeWithRandomBytes(unsigned char* data, size_t len)
|
QUtil::initializeWithRandomBytes(unsigned char* data, size_t len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@ class BogusRandomDataProvider: public RandomDataProvider
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
RandomDataProvider* orig_rdp = QUtil::getRandomDataProvider();
|
||||||
long r1 = QUtil::random();
|
long r1 = QUtil::random();
|
||||||
long r2 = QUtil::random();
|
long r2 = QUtil::random();
|
||||||
if (r1 == r2)
|
if (r1 == r2)
|
||||||
|
@ -48,6 +49,11 @@ int main()
|
||||||
#endif
|
#endif
|
||||||
BogusRandomDataProvider brdp;
|
BogusRandomDataProvider brdp;
|
||||||
QUtil::setRandomDataProvider(&brdp);
|
QUtil::setRandomDataProvider(&brdp);
|
||||||
|
if (QUtil::getRandomDataProvider() != &brdp)
|
||||||
|
{
|
||||||
|
std::cout << "fail: getRandomDataProvider didn't"
|
||||||
|
" return our provider\n";
|
||||||
|
}
|
||||||
r1 = QUtil::random();
|
r1 = QUtil::random();
|
||||||
r2 = QUtil::random();
|
r2 = QUtil::random();
|
||||||
if (r1 != r2)
|
if (r1 != r2)
|
||||||
|
@ -63,6 +69,12 @@ int main()
|
||||||
{
|
{
|
||||||
std::cout << "fail: bogus random didn't provide correct bytes\n";
|
std::cout << "fail: bogus random didn't provide correct bytes\n";
|
||||||
}
|
}
|
||||||
|
QUtil::setRandomDataProvider(0);
|
||||||
|
if (QUtil::getRandomDataProvider() != orig_rdp)
|
||||||
|
{
|
||||||
|
std::cout << "fail: passing null to setRandomDataProvider "
|
||||||
|
"didn't reset the random data provider\n";
|
||||||
|
}
|
||||||
std::cout << "random: end of tests\n";
|
std::cout << "random: end of tests\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user