From 85d784952f8a7c4d8c9e614663ebc5b1eb747384 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 21 May 2023 14:42:34 +0100 Subject: Globally replace 'this->m->' with 'm->' Using search and replace. --- libqpdf/QPDF_encryption.cc | 120 +++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 64 deletions(-) (limited to 'libqpdf/QPDF_encryption.cc') diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 64ca10f1..78b9da20 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -774,27 +774,27 @@ QPDF::interpretCF( void QPDF::initializeEncryption() { - if (this->m->encp->encryption_initialized) { + if (m->encp->encryption_initialized) { return; } - this->m->encp->encryption_initialized = true; + m->encp->encryption_initialized = true; // After we initialize encryption parameters, we must used stored // key information and never look at /Encrypt again. Otherwise, // things could go wrong if someone mutates the encryption // dictionary. - if (!this->m->trailer.hasKey("/Encrypt")) { + if (!m->trailer.hasKey("/Encrypt")) { return; } - // Go ahead and set this->m->encrypted here. That way, isEncrypted + // Go ahead and set m->encrypted here. That way, isEncrypted // will return true even if there were errors reading the // encryption dictionary. - this->m->encp->encrypted = true; + m->encp->encrypted = true; std::string id1; - QPDFObjectHandle id_obj = this->m->trailer.getKey("/ID"); + QPDFObjectHandle id_obj = m->trailer.getKey("/ID"); if ((id_obj.isArray() && (id_obj.getArrayNItems() == 2) && id_obj.getArrayItem(0).isString())) { id1 = id_obj.getArrayItem(0).getStringValue(); @@ -805,7 +805,7 @@ QPDF::initializeEncryption() warn(damagedPDF("trailer", "invalid /ID in trailer dictionary")); } - QPDFObjectHandle encryption_dict = this->m->trailer.getKey("/Encrypt"); + QPDFObjectHandle encryption_dict = m->trailer.getKey("/Encrypt"); if (!encryption_dict.isDictionary()) { throw damagedPDF("/Encrypt in trailer dictionary is not a dictionary"); } @@ -814,16 +814,16 @@ QPDF::initializeEncryption() (encryption_dict.getKey("/Filter").getName() == "/Standard"))) { throw QPDFExc( qpdf_e_unsupported, - this->m->file->getName(), + m->file->getName(), "encryption dictionary", - this->m->file->getLastOffset(), + m->file->getLastOffset(), "unsupported encryption filter"); } if (!encryption_dict.getKey("/SubFilter").isNull()) { warn( qpdf_e_unsupported, "encryption dictionary", - this->m->file->getLastOffset(), + m->file->getLastOffset(), "file uses encryption SubFilters, which qpdf does not support"); } @@ -850,16 +850,16 @@ QPDF::initializeEncryption() ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) { throw QPDFExc( qpdf_e_unsupported, - this->m->file->getName(), + m->file->getName(), "encryption dictionary", - this->m->file->getLastOffset(), + m->file->getLastOffset(), "Unsupported /R or /V in encryption dictionary; R = " + std::to_string(R) + " (max 6), V = " + std::to_string(V) + " (max 5)"); } - this->m->encp->encryption_V = V; - this->m->encp->encryption_R = R; + m->encp->encryption_V = V; + m->encp->encryption_R = R; // OE, UE, and Perms are only present if V >= 5. std::string OE; @@ -916,9 +916,9 @@ QPDF::initializeEncryption() Length = 128; } - this->m->encp->encrypt_metadata = true; + m->encp->encrypt_metadata = true; if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool())) { - this->m->encp->encrypt_metadata = + m->encp->encrypt_metadata = encryption_dict.getKey("/EncryptMetadata").getBoolValue(); } @@ -945,15 +945,15 @@ QPDF::initializeEncryption() method = e_unknown; } } - this->m->encp->crypt_filters[filter] = method; + m->encp->crypt_filters[filter] = method; } } QPDFObjectHandle StmF = encryption_dict.getKey("/StmF"); QPDFObjectHandle StrF = encryption_dict.getKey("/StrF"); QPDFObjectHandle EFF = encryption_dict.getKey("/EFF"); - this->m->encp->cf_stream = interpretCF(this->m->encp, StmF); - this->m->encp->cf_string = interpretCF(this->m->encp, StrF); + m->encp->cf_stream = interpretCF(m->encp, StmF); + m->encp->cf_string = interpretCF(m->encp, StrF); if (EFF.isName()) { // qpdf does not use this for anything other than // informational purposes. This is intended to instruct @@ -969,9 +969,9 @@ QPDF::initializeEncryption() // at a file generated by something else, such as Acrobat // when specifying that only attachments should be // encrypted. - this->m->encp->cf_file = interpretCF(this->m->encp, EFF); + m->encp->cf_file = interpretCF(m->encp, EFF); } else { - this->m->encp->cf_file = this->m->encp->cf_stream; + m->encp->cf_file = m->encp->cf_stream; } } @@ -986,59 +986,51 @@ QPDF::initializeEncryption() UE, Perms, id1, - this->m->encp->encrypt_metadata); - if (this->m->provided_password_is_hex_key) { + m->encp->encrypt_metadata); + if (m->provided_password_is_hex_key) { // ignore passwords in file } else { - this->m->encp->owner_password_matched = check_owner_password( - this->m->encp->user_password, - this->m->encp->provided_password, - data); - if (this->m->encp->owner_password_matched && (V < 5)) { + m->encp->owner_password_matched = check_owner_password( + m->encp->user_password, m->encp->provided_password, data); + if (m->encp->owner_password_matched && (V < 5)) { // password supplied was owner password; user_password has // been initialized for V < 5 - if (getTrimmedUserPassword() == this->m->encp->provided_password) { - this->m->encp->user_password_matched = true; + if (getTrimmedUserPassword() == m->encp->provided_password) { + m->encp->user_password_matched = true; QTC::TC("qpdf", "QPDF_encryption user matches owner V < 5"); } } else { - this->m->encp->user_password_matched = - check_user_password(this->m->encp->provided_password, data); - if (this->m->encp->user_password_matched) { - this->m->encp->user_password = this->m->encp->provided_password; + m->encp->user_password_matched = + check_user_password(m->encp->provided_password, data); + if (m->encp->user_password_matched) { + m->encp->user_password = m->encp->provided_password; } } - if (this->m->encp->user_password_matched && - this->m->encp->owner_password_matched) { + if (m->encp->user_password_matched && m->encp->owner_password_matched) { QTC::TC("qpdf", "QPDF_encryption same password", (V < 5) ? 0 : 1); } - if (!(this->m->encp->owner_password_matched || - this->m->encp->user_password_matched)) { + if (!(m->encp->owner_password_matched || + m->encp->user_password_matched)) { throw QPDFExc( - qpdf_e_password, - this->m->file->getName(), - "", - 0, - "invalid password"); + qpdf_e_password, m->file->getName(), "", 0, "invalid password"); } } - if (this->m->provided_password_is_hex_key) { - this->m->encp->encryption_key = - QUtil::hex_decode(this->m->encp->provided_password); + if (m->provided_password_is_hex_key) { + m->encp->encryption_key = QUtil::hex_decode(m->encp->provided_password); } else if (V < 5) { // For V < 5, the user password is encrypted with the owner // password, and the user password is always used for // computing the encryption key. - this->m->encp->encryption_key = - compute_encryption_key(this->m->encp->user_password, data); + m->encp->encryption_key = + compute_encryption_key(m->encp->user_password, data); } else { // For V >= 5, either password can be used independently to // compute the encryption key, and neither password can be // used to recover the other. bool perms_valid; - this->m->encp->encryption_key = recover_encryption_key_with_password( - this->m->encp->provided_password, data, perms_valid); + m->encp->encryption_key = recover_encryption_key_with_password( + m->encp->provided_password, data, perms_valid); if (!perms_valid) { warn(damagedPDF( "encryption dictionary", @@ -1080,8 +1072,8 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) return; } bool use_aes = false; - if (this->m->encp->encryption_V >= 4) { - switch (this->m->encp->cf_string) { + if (m->encp->encryption_V >= 4) { + switch (m->encp->cf_string) { case e_none: return; @@ -1102,13 +1094,13 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) "/Encrypt dictionary); strings may be decrypted improperly")); // To avoid repeated warnings, reset cf_string. Assume // we'd want to use AES if V == 4. - this->m->encp->cf_string = e_aes; + m->encp->cf_string = e_aes; use_aes = true; break; } } - std::string key = getKeyForObject(this->m->encp, og, use_aes); + std::string key = getKeyForObject(m->encp, og, use_aes); try { if (use_aes) { QTC::TC("qpdf", "QPDF_encryption aes decode string"); @@ -1320,13 +1312,13 @@ QPDF::compute_encryption_parameters_V5( std::string const& QPDF::getPaddedUserPassword() const { - return this->m->encp->user_password; + return m->encp->user_password; } std::string QPDF::getTrimmedUserPassword() const { - std::string result = this->m->encp->user_password; + std::string result = m->encp->user_password; trim_user_password(result); return result; } @@ -1334,13 +1326,13 @@ QPDF::getTrimmedUserPassword() const std::string QPDF::getEncryptionKey() const { - return this->m->encp->encryption_key; + return m->encp->encryption_key; } bool QPDF::isEncrypted() const { - return this->m->encp->encrypted; + return m->encp->encrypted; } bool @@ -1360,7 +1352,7 @@ QPDF::isEncrypted( encryption_method_e& string_method, encryption_method_e& file_method) { - if (this->m->encp->encrypted) { + if (m->encp->encrypted) { QPDFObjectHandle trailer = getTrailer(); QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); QPDFObjectHandle Pkey = encrypt.getKey("/P"); @@ -1369,9 +1361,9 @@ QPDF::isEncrypted( P = static_cast(Pkey.getIntValue()); R = Rkey.getIntValueAsInt(); V = Vkey.getIntValueAsInt(); - stream_method = this->m->encp->cf_stream; - string_method = this->m->encp->cf_string; - file_method = this->m->encp->cf_file; + stream_method = m->encp->cf_stream; + string_method = m->encp->cf_string; + file_method = m->encp->cf_file; return true; } else { return false; @@ -1381,13 +1373,13 @@ QPDF::isEncrypted( bool QPDF::ownerPasswordMatched() const { - return this->m->encp->owner_password_matched; + return m->encp->owner_password_matched; } bool QPDF::userPasswordMatched() const { - return this->m->encp->user_password_matched; + return m->encp->user_password_matched; } static bool -- cgit v1.2.3-54-g00ecf