Commit 26edf76767ab5cbf51972a02ed95d53223672398

Authored by m-holger
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.
libqpdf/QPDF.cc
... ... @@ -231,7 +231,7 @@ QPDF::closeInputSource()
231 231 void
232 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 237 void
... ... @@ -250,7 +250,7 @@ QPDF::registerStreamFilter(
250 250 void
251 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 256 std::shared_ptr<QPDFLogger>
... ... @@ -275,19 +275,19 @@ QPDF::setOutputStreams(std::ostream* out, std::ostream* err)
275 275 void
276 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 281 void
282 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 287 void
288 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 293 void
... ...
libqpdf/QPDFJob.cc
... ... @@ -1739,7 +1739,7 @@ QPDFJob::doProcess(
1739 1739 // was incorrectly encoded, there's a good chance we'd succeed here.
1740 1740  
1741 1741 std::string ptemp;
1742   - if (password && !m->qcf.provided_password_is_hex_key()) {
  1742 + if (password && !m->qcf.password_is_hex_key()) {
1743 1743 if (m->password_mode == QPDFJob::pm_hex_bytes) {
1744 1744 // Special case: handle --password-mode=hex-bytes for input password as well as output
1745 1745 // password
... ... @@ -1747,8 +1747,7 @@ QPDFJob::doProcess(
1747 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 1751 // There is no password, or we're not doing recovery, so just do the normal processing with
1753 1752 // the supplied password.
1754 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&amp; parameter)
466 466 QPDFJob::Config*
467 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 470 return this;
471 471 }
472 472  
... ... @@ -663,7 +663,7 @@ QPDFJob::Config::suppressPasswordRecovery()
663 663 QPDFJob::Config*
664 664 QPDFJob::Config::suppressRecovery()
665 665 {
666   - o.m->qcf.attempt_recovery(false);
  666 + o.m->qcf.surpress_recovery(true);
667 667 return this;
668 668 }
669 669  
... ...
libqpdf/QPDF_encryption.cc
... ... @@ -904,7 +904,7 @@ QPDF::EncryptionParameters::initialize(QPDF&amp; qpdf)
904 904 }
905 905  
906 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 908 // ignore passwords in file
909 909 encryption_key = QUtil::hex_decode(provided_password);
910 910 return;
... ...
libqpdf/QPDF_objects.cc
... ... @@ -157,7 +157,7 @@ Objects::parse(char const* password)
157 157 throw damagedPDF("", -1, std::string("error reading xref: ") + e.what());
158 158 }
159 159 } catch (QPDFExc& e) {
160   - if (cf.attempt_recovery()) {
  160 + if (!cf.surpress_recovery()) {
161 161 reconstruct_xref(e, xref_offset > 0);
162 162 } else {
163 163 throw;
... ... @@ -1248,7 +1248,7 @@ Objects::readStream(QPDFObjectHandle&amp; object, QPDFObjGen og, qpdf_offset_t offse
1248 1248 throw damagedPDF("expected endstream");
1249 1249 }
1250 1250 } catch (QPDFExc& e) {
1251   - if (cf.attempt_recovery()) {
  1251 + if (!cf.surpress_recovery()) {
1252 1252 warn(e);
1253 1253 length = recoverStreamLength(m->file, og, stream_offset);
1254 1254 } else {
... ... @@ -1431,7 +1431,7 @@ Objects::readObjectAtOffset(
1431 1431 QPDFObjGen og;
1432 1432 setLastObjectDescription(description, exp_og);
1433 1433  
1434   - if (!cf.attempt_recovery()) {
  1434 + if (cf.surpress_recovery()) {
1435 1435 try_recovery = false;
1436 1436 }
1437 1437  
... ...
libqpdf/qpdf/QPDF_private.hh
... ... @@ -34,15 +34,15 @@ namespace qpdf
34 34 }
35 35  
36 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 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 46 return *this;
47 47 }
48 48  
... ... @@ -99,15 +99,15 @@ namespace qpdf
99 99 }
100 100  
101 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 107 Config&
108   - attempt_recovery(bool val)
  108 + surpress_recovery(bool val)
109 109 {
110   - attempt_recovery_ = val;
  110 + surpress_recovery_ = val;
111 111 return *this;
112 112 }
113 113  
... ... @@ -142,10 +142,10 @@ namespace qpdf
142 142  
143 143 size_t max_warnings_{0};
144 144  
145   - bool provided_password_is_hex_key_{false};
  145 + bool password_is_hex_key_{false};
146 146 bool ignore_xref_streams_{false};
147 147 bool suppress_warnings_{false};
148   - bool attempt_recovery_{true};
  148 + bool surpress_recovery_{false};
149 149 bool check_mode_{false};
150 150 bool immediate_copy_from_{false};
151 151 }; // Class Config
... ...