mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 02:49:00 +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>
|
||||
|
||||
* Add methods to QPDFWriter and corresponding command line
|
||||
|
@ -108,17 +108,22 @@ Pl_AES_PDF::finish()
|
||||
void
|
||||
Pl_AES_PDF::initializeVector()
|
||||
{
|
||||
std::string seed_str;
|
||||
seed_str += QUtil::int_to_string((int)QUtil::get_current_time());
|
||||
seed_str += " QPDF aes random";
|
||||
MD5 m;
|
||||
m.encodeString(seed_str.c_str());
|
||||
MD5::Digest digest;
|
||||
m.digest(digest);
|
||||
assert(sizeof(digest) >= sizeof(unsigned int));
|
||||
unsigned int seed;
|
||||
memcpy((void*)(&seed), digest, sizeof(unsigned int));
|
||||
srandom(seed);
|
||||
static bool seeded_random = false;
|
||||
if (! seeded_random)
|
||||
{
|
||||
std::string seed_str;
|
||||
seed_str += QUtil::int_to_string((int)QUtil::get_current_time());
|
||||
seed_str += " QPDF aes random";
|
||||
MD5 m;
|
||||
m.encodeString(seed_str.c_str());
|
||||
MD5::Digest digest;
|
||||
m.digest(digest);
|
||||
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)
|
||||
{
|
||||
this->cbc_block[i] = (unsigned char)((random() & 0xff0) >> 4);
|
||||
|
@ -860,6 +860,12 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||
}
|
||||
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);
|
||||
if (this->stream_data_mode == s_compress)
|
||||
{
|
||||
@ -878,7 +884,14 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||
}
|
||||
bool normalize = 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;
|
||||
filter = true;
|
||||
@ -907,10 +920,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||
}
|
||||
|
||||
this->cur_stream_length = stream_data.getPointer()->getSize();
|
||||
if (this->encrypted &&
|
||||
stream_dict.getKey("/Type").isName() &&
|
||||
(stream_dict.getKey("/Type").getName() == "/Metadata") &&
|
||||
(! this->encrypt_metadata))
|
||||
if (is_metadata && this->encrypted && (! this->encrypt_metadata))
|
||||
{
|
||||
// Don't encrypt stream data for the metadata stream
|
||||
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_encryption rc4 decode string 0
|
||||
QPDF_encryption rc4 decode stream 0
|
||||
QPDFWriter not compressing metadata 0
|
||||
|
Loading…
Reference in New Issue
Block a user