mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
only seed randon number generater once for aes-cbc, try to avoid compressing Metadata streams
git-svn-id: svn+q:///qpdf/trunk@818 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
parent
67e353e4e4
commit
4ccc9330a8
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
2009-10-18 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* libqpdf/QPDFWriter.cc (unparseObject): avoid compressing
|
||||||
|
Metadata streams if possible.
|
||||||
|
|
||||||
|
2009-10-04 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* Implement support AES encrypt and crypt filters. Implementation
|
||||||
|
is not fully tested due to lack of test data but has been tested
|
||||||
|
for several cases.
|
||||||
|
|
||||||
2009-10-04 Jay Berkenbilt <ejb@ql.org>
|
2009-10-04 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* Add methods to QPDFWriter and corresponding command line
|
* Add methods to QPDFWriter and corresponding command line
|
||||||
|
@ -108,17 +108,22 @@ Pl_AES_PDF::finish()
|
|||||||
void
|
void
|
||||||
Pl_AES_PDF::initializeVector()
|
Pl_AES_PDF::initializeVector()
|
||||||
{
|
{
|
||||||
std::string seed_str;
|
static bool seeded_random = false;
|
||||||
seed_str += QUtil::int_to_string((int)QUtil::get_current_time());
|
if (! seeded_random)
|
||||||
seed_str += " QPDF aes random";
|
{
|
||||||
MD5 m;
|
std::string seed_str;
|
||||||
m.encodeString(seed_str.c_str());
|
seed_str += QUtil::int_to_string((int)QUtil::get_current_time());
|
||||||
MD5::Digest digest;
|
seed_str += " QPDF aes random";
|
||||||
m.digest(digest);
|
MD5 m;
|
||||||
assert(sizeof(digest) >= sizeof(unsigned int));
|
m.encodeString(seed_str.c_str());
|
||||||
unsigned int seed;
|
MD5::Digest digest;
|
||||||
memcpy((void*)(&seed), digest, sizeof(unsigned int));
|
m.digest(digest);
|
||||||
srandom(seed);
|
assert(sizeof(digest) >= sizeof(unsigned int));
|
||||||
|
unsigned int seed;
|
||||||
|
memcpy((void*)(&seed), digest, sizeof(unsigned int));
|
||||||
|
srandom(seed);
|
||||||
|
seeded_random = true;
|
||||||
|
}
|
||||||
for (unsigned int i = 0; i < this->buf_size; ++i)
|
for (unsigned int i = 0; i < this->buf_size; ++i)
|
||||||
{
|
{
|
||||||
this->cbc_block[i] = (unsigned char)((random() & 0xff0) >> 4);
|
this->cbc_block[i] = (unsigned char)((random() & 0xff0) >> 4);
|
||||||
|
@ -860,6 +860,12 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
|||||||
}
|
}
|
||||||
QPDFObjectHandle stream_dict = object.getDict();
|
QPDFObjectHandle stream_dict = object.getDict();
|
||||||
|
|
||||||
|
bool is_metadata = false;
|
||||||
|
if (stream_dict.getKey("/Type").isName() &&
|
||||||
|
(stream_dict.getKey("/Type").getName() == "/Metadata"))
|
||||||
|
{
|
||||||
|
is_metadata = true;
|
||||||
|
}
|
||||||
bool filter = (this->stream_data_mode != s_preserve);
|
bool filter = (this->stream_data_mode != s_preserve);
|
||||||
if (this->stream_data_mode == s_compress)
|
if (this->stream_data_mode == s_compress)
|
||||||
{
|
{
|
||||||
@ -878,7 +884,14 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
|||||||
}
|
}
|
||||||
bool normalize = false;
|
bool normalize = false;
|
||||||
bool compress = false;
|
bool compress = false;
|
||||||
if (this->normalize_content && normalized_streams.count(old_id))
|
if (is_metadata &&
|
||||||
|
((! this->encrypted) || (this->encrypt_metadata == false)))
|
||||||
|
{
|
||||||
|
QTC::TC("qpdf", "QPDFWriter not compressing metadata");
|
||||||
|
filter = true;
|
||||||
|
compress = false;
|
||||||
|
}
|
||||||
|
else if (this->normalize_content && normalized_streams.count(old_id))
|
||||||
{
|
{
|
||||||
normalize = true;
|
normalize = true;
|
||||||
filter = true;
|
filter = true;
|
||||||
@ -907,10 +920,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->cur_stream_length = stream_data.getPointer()->getSize();
|
this->cur_stream_length = stream_data.getPointer()->getSize();
|
||||||
if (this->encrypted &&
|
if (is_metadata && this->encrypted && (! this->encrypt_metadata))
|
||||||
stream_dict.getKey("/Type").isName() &&
|
|
||||||
(stream_dict.getKey("/Type").getName() == "/Metadata") &&
|
|
||||||
(! this->encrypt_metadata))
|
|
||||||
{
|
{
|
||||||
// Don't encrypt stream data for the metadata stream
|
// Don't encrypt stream data for the metadata stream
|
||||||
this->cur_data_key.clear();
|
this->cur_data_key.clear();
|
||||||
|
@ -160,3 +160,4 @@ qpdf-c called qpdf_force_pdf_version 0
|
|||||||
qpdf-c called qpdf_init_write multiple times 0
|
qpdf-c called qpdf_init_write multiple times 0
|
||||||
QPDF_encryption rc4 decode string 0
|
QPDF_encryption rc4 decode string 0
|
||||||
QPDF_encryption rc4 decode stream 0
|
QPDF_encryption rc4 decode stream 0
|
||||||
|
QPDFWriter not compressing metadata 0
|
||||||
|
Loading…
Reference in New Issue
Block a user