Commit db95960ac16076030a840a1ae050eea35aa21ea2
1 parent
b5012512
Bug fix: preserve AES when copying encryption parameters
Showing
3 changed files
with
33 additions
and
2 deletions
ChangeLog
| 1 | +2012-07-15 Jay Berkenbilt <ejb@ql.org> | |
| 2 | + | |
| 3 | + * libqpdf/QPDFWriter.cc (copyEncryptionParameters): Bug fix: qpdf | |
| 4 | + was not preserving whether or not AES encryption was being used | |
| 5 | + when copying encryption parameters. | |
| 6 | + | |
| 1 | 7 | 2012-07-14 Jay Berkenbilt <ejb@ql.org> |
| 2 | 8 | |
| 3 | 9 | * QPDFWriter: add public copyEncryptionParameters to allow copying | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -409,10 +409,34 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) |
| 409 | 409 | this->encrypt_metadata = |
| 410 | 410 | encrypt.getKey("/EncryptMetadata").getBoolValue(); |
| 411 | 411 | } |
| 412 | + if (V >= 4) | |
| 413 | + { | |
| 414 | + if (encrypt.hasKey("/CF") && | |
| 415 | + encrypt.getKey("/CF").isDictionary() && | |
| 416 | + encrypt.hasKey("/StmF") && | |
| 417 | + encrypt.getKey("/StmF").isName()) | |
| 418 | + { | |
| 419 | + // Determine whether to use AES from StmF. QPDFWriter | |
| 420 | + // can't write files with different StrF and StmF. | |
| 421 | + QPDFObjectHandle CF = encrypt.getKey("/CF"); | |
| 422 | + QPDFObjectHandle StmF = encrypt.getKey("/StmF"); | |
| 423 | + if (CF.hasKey(StmF.getName()) && | |
| 424 | + CF.getKey(StmF.getName()).isDictionary()) | |
| 425 | + { | |
| 426 | + QPDFObjectHandle StmF_data = CF.getKey(StmF.getName()); | |
| 427 | + if (StmF_data.hasKey("/CFM") && | |
| 428 | + StmF_data.getKey("/CFM").isName() && | |
| 429 | + StmF_data.getKey("/CFM").getName() == "/AESV2") | |
| 430 | + { | |
| 431 | + this->encrypt_use_aes = true; | |
| 432 | + } | |
| 433 | + } | |
| 434 | + } | |
| 435 | + } | |
| 412 | 436 | QTC::TC("qpdf", "QPDFWriter copy encrypt metadata", |
| 413 | 437 | this->encrypt_metadata ? 0 : 1); |
| 414 | - this->id1 = | |
| 415 | - trailer.getKey("/ID").getArrayItem(0).getStringValue(); | |
| 438 | + QTC::TC("qpdf", "QPDFWriter copy use_aes", | |
| 439 | + this->encrypt_use_aes ? 0 : 1); | |
| 416 | 440 | setEncryptionParametersInternal( |
| 417 | 441 | V, |
| 418 | 442 | encrypt.getKey("/R").getIntValue(), | ... | ... |