Commit 26edf76767ab5cbf51972a02ed95d53223672398
1 parent
089b817b
Refactor `Config` and related methods: rename `provided_password_is_hex_key` and…
… `attempt_recovery` to `password_is_hex_key` and `suppress_recovery` to align with the CLI, update usage across the codebase, and streamline related logic.
Showing
6 changed files
with
23 additions
and
24 deletions
libqpdf/QPDF.cc
| @@ -231,7 +231,7 @@ QPDF::closeInputSource() | @@ -231,7 +231,7 @@ QPDF::closeInputSource() | ||
| 231 | void | 231 | void |
| 232 | QPDF::setPasswordIsHexKey(bool val) | 232 | QPDF::setPasswordIsHexKey(bool val) |
| 233 | { | 233 | { |
| 234 | - m->cf.provided_password_is_hex_key(val); | 234 | + m->cf.password_is_hex_key(val); |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | void | 237 | void |
| @@ -250,7 +250,7 @@ QPDF::registerStreamFilter( | @@ -250,7 +250,7 @@ QPDF::registerStreamFilter( | ||
| 250 | void | 250 | void |
| 251 | QPDF::setIgnoreXRefStreams(bool val) | 251 | QPDF::setIgnoreXRefStreams(bool val) |
| 252 | { | 252 | { |
| 253 | - m->cf.ignore_xref_streams(val); | 253 | + (void)m->cf.ignore_xref_streams(val); |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | std::shared_ptr<QPDFLogger> | 256 | std::shared_ptr<QPDFLogger> |
| @@ -275,19 +275,19 @@ QPDF::setOutputStreams(std::ostream* out, std::ostream* err) | @@ -275,19 +275,19 @@ QPDF::setOutputStreams(std::ostream* out, std::ostream* err) | ||
| 275 | void | 275 | void |
| 276 | QPDF::setSuppressWarnings(bool val) | 276 | QPDF::setSuppressWarnings(bool val) |
| 277 | { | 277 | { |
| 278 | - m->cf.suppress_warnings(val); | 278 | + (void)m->cf.suppress_warnings(val); |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | void | 281 | void |
| 282 | QPDF::setMaxWarnings(size_t val) | 282 | QPDF::setMaxWarnings(size_t val) |
| 283 | { | 283 | { |
| 284 | - m->cf.max_warnings(val); | 284 | + (void)m->cf.max_warnings(val); |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | void | 287 | void |
| 288 | QPDF::setAttemptRecovery(bool val) | 288 | QPDF::setAttemptRecovery(bool val) |
| 289 | { | 289 | { |
| 290 | - (void)m->cf.attempt_recovery(val); | 290 | + (void)m->cf.surpress_recovery(!val); |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | void | 293 | void |
libqpdf/QPDFJob.cc
| @@ -1739,7 +1739,7 @@ QPDFJob::doProcess( | @@ -1739,7 +1739,7 @@ QPDFJob::doProcess( | ||
| 1739 | // was incorrectly encoded, there's a good chance we'd succeed here. | 1739 | // was incorrectly encoded, there's a good chance we'd succeed here. |
| 1740 | 1740 | ||
| 1741 | std::string ptemp; | 1741 | std::string ptemp; |
| 1742 | - if (password && !m->qcf.provided_password_is_hex_key()) { | 1742 | + if (password && !m->qcf.password_is_hex_key()) { |
| 1743 | if (m->password_mode == QPDFJob::pm_hex_bytes) { | 1743 | if (m->password_mode == QPDFJob::pm_hex_bytes) { |
| 1744 | // Special case: handle --password-mode=hex-bytes for input password as well as output | 1744 | // Special case: handle --password-mode=hex-bytes for input password as well as output |
| 1745 | // password | 1745 | // password |
| @@ -1747,8 +1747,7 @@ QPDFJob::doProcess( | @@ -1747,8 +1747,7 @@ QPDFJob::doProcess( | ||
| 1747 | password = ptemp.c_str(); | 1747 | password = ptemp.c_str(); |
| 1748 | } | 1748 | } |
| 1749 | } | 1749 | } |
| 1750 | - if (!password || empty || m->qcf.provided_password_is_hex_key() || | ||
| 1751 | - m->suppress_password_recovery) { | 1750 | + if (!password || empty || m->qcf.password_is_hex_key() || m->suppress_password_recovery) { |
| 1752 | // There is no password, or we're not doing recovery, so just do the normal processing with | 1751 | // There is no password, or we're not doing recovery, so just do the normal processing with |
| 1753 | // the supplied password. | 1752 | // the supplied password. |
| 1754 | doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); | 1753 | doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); |
libqpdf/QPDFJob_config.cc
| @@ -466,7 +466,7 @@ QPDFJob::Config::password(std::string const& parameter) | @@ -466,7 +466,7 @@ QPDFJob::Config::password(std::string const& parameter) | ||
| 466 | QPDFJob::Config* | 466 | QPDFJob::Config* |
| 467 | QPDFJob::Config::passwordIsHexKey() | 467 | QPDFJob::Config::passwordIsHexKey() |
| 468 | { | 468 | { |
| 469 | - o.m->qcf.provided_password_is_hex_key(true); | 469 | + o.m->qcf.password_is_hex_key(true); |
| 470 | return this; | 470 | return this; |
| 471 | } | 471 | } |
| 472 | 472 | ||
| @@ -663,7 +663,7 @@ QPDFJob::Config::suppressPasswordRecovery() | @@ -663,7 +663,7 @@ QPDFJob::Config::suppressPasswordRecovery() | ||
| 663 | QPDFJob::Config* | 663 | QPDFJob::Config* |
| 664 | QPDFJob::Config::suppressRecovery() | 664 | QPDFJob::Config::suppressRecovery() |
| 665 | { | 665 | { |
| 666 | - o.m->qcf.attempt_recovery(false); | 666 | + o.m->qcf.surpress_recovery(true); |
| 667 | return this; | 667 | return this; |
| 668 | } | 668 | } |
| 669 | 669 |
libqpdf/QPDF_encryption.cc
| @@ -904,7 +904,7 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) | @@ -904,7 +904,7 @@ QPDF::EncryptionParameters::initialize(QPDF& qpdf) | ||
| 904 | } | 904 | } |
| 905 | 905 | ||
| 906 | Encryption data(V, R, Length / 8, p, O, U, OE, UE, Perms, id1, encrypt_metadata); | 906 | Encryption data(V, R, Length / 8, p, O, U, OE, UE, Perms, id1, encrypt_metadata); |
| 907 | - if (qm.cf.provided_password_is_hex_key()) { | 907 | + if (qm.cf.password_is_hex_key()) { |
| 908 | // ignore passwords in file | 908 | // ignore passwords in file |
| 909 | encryption_key = QUtil::hex_decode(provided_password); | 909 | encryption_key = QUtil::hex_decode(provided_password); |
| 910 | return; | 910 | return; |
libqpdf/QPDF_objects.cc
| @@ -157,7 +157,7 @@ Objects::parse(char const* password) | @@ -157,7 +157,7 @@ Objects::parse(char const* password) | ||
| 157 | throw damagedPDF("", -1, std::string("error reading xref: ") + e.what()); | 157 | throw damagedPDF("", -1, std::string("error reading xref: ") + e.what()); |
| 158 | } | 158 | } |
| 159 | } catch (QPDFExc& e) { | 159 | } catch (QPDFExc& e) { |
| 160 | - if (cf.attempt_recovery()) { | 160 | + if (!cf.surpress_recovery()) { |
| 161 | reconstruct_xref(e, xref_offset > 0); | 161 | reconstruct_xref(e, xref_offset > 0); |
| 162 | } else { | 162 | } else { |
| 163 | throw; | 163 | throw; |
| @@ -1248,7 +1248,7 @@ Objects::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offse | @@ -1248,7 +1248,7 @@ Objects::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offse | ||
| 1248 | throw damagedPDF("expected endstream"); | 1248 | throw damagedPDF("expected endstream"); |
| 1249 | } | 1249 | } |
| 1250 | } catch (QPDFExc& e) { | 1250 | } catch (QPDFExc& e) { |
| 1251 | - if (cf.attempt_recovery()) { | 1251 | + if (!cf.surpress_recovery()) { |
| 1252 | warn(e); | 1252 | warn(e); |
| 1253 | length = recoverStreamLength(m->file, og, stream_offset); | 1253 | length = recoverStreamLength(m->file, og, stream_offset); |
| 1254 | } else { | 1254 | } else { |
| @@ -1431,7 +1431,7 @@ Objects::readObjectAtOffset( | @@ -1431,7 +1431,7 @@ Objects::readObjectAtOffset( | ||
| 1431 | QPDFObjGen og; | 1431 | QPDFObjGen og; |
| 1432 | setLastObjectDescription(description, exp_og); | 1432 | setLastObjectDescription(description, exp_og); |
| 1433 | 1433 | ||
| 1434 | - if (!cf.attempt_recovery()) { | 1434 | + if (cf.surpress_recovery()) { |
| 1435 | try_recovery = false; | 1435 | try_recovery = false; |
| 1436 | } | 1436 | } |
| 1437 | 1437 |
libqpdf/qpdf/QPDF_private.hh
| @@ -34,15 +34,15 @@ namespace qpdf | @@ -34,15 +34,15 @@ namespace qpdf | ||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | bool | 36 | bool |
| 37 | - provided_password_is_hex_key() const | 37 | + password_is_hex_key() const |
| 38 | { | 38 | { |
| 39 | - return provided_password_is_hex_key_; | 39 | + return password_is_hex_key_; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | Config& | 42 | Config& |
| 43 | - provided_password_is_hex_key(bool val) | 43 | + password_is_hex_key(bool val) |
| 44 | { | 44 | { |
| 45 | - provided_password_is_hex_key_ = val; | 45 | + password_is_hex_key_ = val; |
| 46 | return *this; | 46 | return *this; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| @@ -99,15 +99,15 @@ namespace qpdf | @@ -99,15 +99,15 @@ namespace qpdf | ||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | bool | 101 | bool |
| 102 | - attempt_recovery() const | 102 | + surpress_recovery() const |
| 103 | { | 103 | { |
| 104 | - return attempt_recovery_; | 104 | + return surpress_recovery_; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | Config& | 107 | Config& |
| 108 | - attempt_recovery(bool val) | 108 | + surpress_recovery(bool val) |
| 109 | { | 109 | { |
| 110 | - attempt_recovery_ = val; | 110 | + surpress_recovery_ = val; |
| 111 | return *this; | 111 | return *this; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| @@ -142,10 +142,10 @@ namespace qpdf | @@ -142,10 +142,10 @@ namespace qpdf | ||
| 142 | 142 | ||
| 143 | size_t max_warnings_{0}; | 143 | size_t max_warnings_{0}; |
| 144 | 144 | ||
| 145 | - bool provided_password_is_hex_key_{false}; | 145 | + bool password_is_hex_key_{false}; |
| 146 | bool ignore_xref_streams_{false}; | 146 | bool ignore_xref_streams_{false}; |
| 147 | bool suppress_warnings_{false}; | 147 | bool suppress_warnings_{false}; |
| 148 | - bool attempt_recovery_{true}; | 148 | + bool surpress_recovery_{false}; |
| 149 | bool check_mode_{false}; | 149 | bool check_mode_{false}; |
| 150 | bool immediate_copy_from_{false}; | 150 | bool immediate_copy_from_{false}; |
| 151 | }; // Class Config | 151 | }; // Class Config |