Commit 34142a6c10fced8810385948174cbf48ce7117a4
1 parent
09df3969
Refactor `QPDF::isEncrypted` methods to simplify logic, reduce redundancy, and d…
…irectly access encryption parameters for improved clarity and maintainability.
Showing
1 changed file
with
14 additions
and
17 deletions
libqpdf/QPDF_encryption.cc
| ... | ... | @@ -1236,9 +1236,12 @@ QPDF::isEncrypted() const |
| 1236 | 1236 | bool |
| 1237 | 1237 | QPDF::isEncrypted(int& R, int& P) |
| 1238 | 1238 | { |
| 1239 | - int V; | |
| 1240 | - encryption_method_e stream, string, file; | |
| 1241 | - return isEncrypted(R, P, V, stream, string, file); | |
| 1239 | + if (!m->encp->encrypted) { | |
| 1240 | + return false; | |
| 1241 | + } | |
| 1242 | + P = m->encp->encryption_P; | |
| 1243 | + R = m->encp->encryption_R; | |
| 1244 | + return true; | |
| 1242 | 1245 | } |
| 1243 | 1246 | |
| 1244 | 1247 | bool |
| ... | ... | @@ -1250,22 +1253,16 @@ QPDF::isEncrypted( |
| 1250 | 1253 | encryption_method_e& string_method, |
| 1251 | 1254 | encryption_method_e& file_method) |
| 1252 | 1255 | { |
| 1253 | - if (m->encp->encrypted) { | |
| 1254 | - QPDFObjectHandle trailer = getTrailer(); | |
| 1255 | - QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); | |
| 1256 | - QPDFObjectHandle Pkey = encrypt.getKey("/P"); | |
| 1257 | - QPDFObjectHandle Rkey = encrypt.getKey("/R"); | |
| 1258 | - QPDFObjectHandle Vkey = encrypt.getKey("/V"); | |
| 1259 | - P = static_cast<int>(Pkey.getIntValue()); | |
| 1260 | - R = Rkey.getIntValueAsInt(); | |
| 1261 | - V = Vkey.getIntValueAsInt(); | |
| 1262 | - stream_method = m->encp->cf_stream; | |
| 1263 | - string_method = m->encp->cf_string; | |
| 1264 | - file_method = m->encp->cf_file; | |
| 1265 | - return true; | |
| 1266 | - } else { | |
| 1256 | + if (!m->encp->encrypted) { | |
| 1267 | 1257 | return false; |
| 1268 | 1258 | } |
| 1259 | + P = m->encp->encryption_P; | |
| 1260 | + R = m->encp->encryption_R; | |
| 1261 | + V = m->encp->encryption_V; | |
| 1262 | + stream_method = m->encp->cf_stream; | |
| 1263 | + string_method = m->encp->cf_string; | |
| 1264 | + file_method = m->encp->cf_file; | |
| 1265 | + return true; | |
| 1269 | 1266 | } |
| 1270 | 1267 | |
| 1271 | 1268 | bool | ... | ... |