diff --git a/libqpdf/AES_PDF_native.cc b/libqpdf/AES_PDF_native.cc index 8808d20..0774eb4 100644 --- a/libqpdf/AES_PDF_native.cc +++ b/libqpdf/AES_PDF_native.cc @@ -11,7 +11,7 @@ AES_PDF_native::AES_PDF_native( bool encrypt, - unsigned char const* key, + unsigned char const* a_key, size_t key_bytes, bool cbc_mode, unsigned char* cbc_block) : @@ -20,38 +20,38 @@ AES_PDF_native::AES_PDF_native( cbc_block(cbc_block) { size_t keybits = 8 * key_bytes; - this->key = std::make_unique(key_bytes); - this->rk = std::make_unique(RKLENGTH(keybits)); + key = std::make_unique(key_bytes); + rk = std::make_unique(RKLENGTH(keybits)); size_t rk_bytes = RKLENGTH(keybits) * sizeof(uint32_t); - std::memcpy(this->key.get(), key, key_bytes); - std::memset(this->rk.get(), 0, rk_bytes); + std::memcpy(key.get(), a_key, key_bytes); + std::memset(rk.get(), 0, rk_bytes); if (encrypt) { - this->nrounds = rijndaelSetupEncrypt(this->rk.get(), this->key.get(), keybits); + nrounds = rijndaelSetupEncrypt(rk.get(), key.get(), keybits); } else { - this->nrounds = rijndaelSetupDecrypt(this->rk.get(), this->key.get(), keybits); + nrounds = rijndaelSetupDecrypt(rk.get(), key.get(), keybits); } } void AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data) { - if (this->encrypt) { - if (this->cbc_mode) { + if (encrypt) { + if (cbc_mode) { for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) { - in_data[i] ^= this->cbc_block[i]; + in_data[i] ^= cbc_block[i]; } } - rijndaelEncrypt(this->rk.get(), this->nrounds, in_data, out_data); - if (this->cbc_mode) { - memcpy(this->cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size); + rijndaelEncrypt(rk.get(), nrounds, in_data, out_data); + if (cbc_mode) { + memcpy(cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size); } } else { - rijndaelDecrypt(this->rk.get(), this->nrounds, in_data, out_data); - if (this->cbc_mode) { + rijndaelDecrypt(rk.get(), nrounds, in_data, out_data); + if (cbc_mode) { for (size_t i = 0; i < QPDFCryptoImpl::rijndael_buf_size; ++i) { - out_data[i] ^= this->cbc_block[i]; + out_data[i] ^= cbc_block[i]; } - memcpy(this->cbc_block, in_data, QPDFCryptoImpl::rijndael_buf_size); + memcpy(cbc_block, in_data, QPDFCryptoImpl::rijndael_buf_size); } } } diff --git a/libqpdf/BufferInputSource.cc b/libqpdf/BufferInputSource.cc index 4246016..dae96f8 100644 --- a/libqpdf/BufferInputSource.cc +++ b/libqpdf/BufferInputSource.cc @@ -26,42 +26,42 @@ BufferInputSource::BufferInputSource(std::string const& description, std::string BufferInputSource::~BufferInputSource() { - if (this->own_memory) { - delete this->buf; + if (own_memory) { + delete buf; } } qpdf_offset_t BufferInputSource::findAndSkipNextEOL() { - if (this->cur_offset < 0) { + if (cur_offset < 0) { throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); } - qpdf_offset_t end_pos = this->max_offset; - if (this->cur_offset >= end_pos) { - this->last_offset = end_pos; - this->cur_offset = end_pos; + qpdf_offset_t end_pos = max_offset; + if (cur_offset >= end_pos) { + last_offset = end_pos; + cur_offset = end_pos; return end_pos; } qpdf_offset_t result = 0; - unsigned char const* buffer = this->buf->getBuffer(); + unsigned char const* buffer = buf->getBuffer(); unsigned char const* end = buffer + end_pos; - unsigned char const* p = buffer + this->cur_offset; + unsigned char const* p = buffer + cur_offset; while ((p < end) && !((*p == '\r') || (*p == '\n'))) { ++p; } if (p < end) { result = p - buffer; - this->cur_offset = result + 1; + cur_offset = result + 1; ++p; - while ((this->cur_offset < end_pos) && ((*p == '\r') || (*p == '\n'))) { + while ((cur_offset < end_pos) && ((*p == '\r') || (*p == '\n'))) { ++p; - ++this->cur_offset; + ++cur_offset; } } else { - this->cur_offset = end_pos; + cur_offset = end_pos; result = end_pos; } return result; @@ -70,13 +70,13 @@ BufferInputSource::findAndSkipNextEOL() std::string const& BufferInputSource::getName() const { - return this->description; + return description; } qpdf_offset_t BufferInputSource::tell() { - return this->cur_offset; + return cur_offset; } void @@ -84,17 +84,17 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) { switch (whence) { case SEEK_SET: - this->cur_offset = offset; + cur_offset = offset; break; case SEEK_END: - QIntC::range_check(this->max_offset, offset); - this->cur_offset = this->max_offset + offset; + QIntC::range_check(max_offset, offset); + cur_offset = max_offset + offset; break; case SEEK_CUR: - QIntC::range_check(this->cur_offset, offset); - this->cur_offset += offset; + QIntC::range_check(cur_offset, offset); + cur_offset += offset; break; default: @@ -102,40 +102,40 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) break; } - if (this->cur_offset < 0) { - throw std::runtime_error(this->description + ": seek before beginning of buffer"); + if (cur_offset < 0) { + throw std::runtime_error(description + ": seek before beginning of buffer"); } } void BufferInputSource::rewind() { - this->cur_offset = 0; + cur_offset = 0; } size_t BufferInputSource::read(char* buffer, size_t length) { - if (this->cur_offset < 0) { + if (cur_offset < 0) { throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); } - qpdf_offset_t end_pos = this->max_offset; - if (this->cur_offset >= end_pos) { - this->last_offset = end_pos; + qpdf_offset_t end_pos = max_offset; + if (cur_offset >= end_pos) { + last_offset = end_pos; return 0; } - this->last_offset = this->cur_offset; - size_t len = std::min(QIntC::to_size(end_pos - this->cur_offset), length); - memcpy(buffer, this->buf->getBuffer() + this->cur_offset, len); - this->cur_offset += QIntC::to_offset(len); + last_offset = cur_offset; + size_t len = std::min(QIntC::to_size(end_pos - cur_offset), length); + memcpy(buffer, buf->getBuffer() + cur_offset, len); + cur_offset += QIntC::to_offset(len); return len; } void BufferInputSource::unreadCh(char ch) { - if (this->cur_offset > 0) { - --this->cur_offset; + if (cur_offset > 0) { + --cur_offset; } } diff --git a/libqpdf/MD5.cc b/libqpdf/MD5.cc index b8e07cf..694289e 100644 --- a/libqpdf/MD5.cc +++ b/libqpdf/MD5.cc @@ -14,14 +14,14 @@ MD5::MD5() void MD5::init() { - this->crypto = QPDFCryptoProvider::getImpl(); - this->crypto->MD5_init(); + crypto = QPDFCryptoProvider::getImpl(); + crypto->MD5_init(); } void MD5::finalize() { - this->crypto->MD5_finalize(); + crypto->MD5_finalize(); } void @@ -48,7 +48,7 @@ MD5::appendString(char const* input_string) void MD5::encodeDataIncrementally(char const* data, size_t len) { - this->crypto->MD5_update(QUtil::unsigned_char_pointer(data), len); + crypto->MD5_update(QUtil::unsigned_char_pointer(data), len); } void @@ -84,14 +84,14 @@ MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset) } (void)fclose(file); - this->crypto->MD5_finalize(); + crypto->MD5_finalize(); } void MD5::digest(Digest result) { - this->crypto->MD5_finalize(); - this->crypto->MD5_digest(result); + crypto->MD5_finalize(); + crypto->MD5_digest(result); } void @@ -110,7 +110,7 @@ MD5::print() std::string MD5::unparse() { - this->crypto->MD5_finalize(); + crypto->MD5_finalize(); Digest digest_val; digest(digest_val); return QUtil::hex_encode(std::string(reinterpret_cast(digest_val), 16)); diff --git a/libqpdf/NNTree.cc b/libqpdf/NNTree.cc index 210b8db..2c8fec7 100644 --- a/libqpdf/NNTree.cc +++ b/libqpdf/NNTree.cc @@ -49,12 +49,12 @@ NNTreeIterator::updateIValue(bool allow_invalid) // call updateIValue in operator* and operator->. bool okay = false; - if ((item_number >= 0) && this->node.isDictionary()) { - auto items = this->node.getKey(impl.details.itemsKey()); - if (this->item_number + 1 < items.getArrayNItems()) { + if (item_number >= 0 && node.isDictionary()) { + auto items = node.getKey(impl.details.itemsKey()); + if (item_number + 1 < items.getArrayNItems()) { okay = true; - this->ivalue.first = items.getArrayItem(this->item_number); - this->ivalue.second = items.getArrayItem(1 + this->item_number); + ivalue.first = items.getArrayItem(item_number); + ivalue.second = items.getArrayItem(1 + item_number); } else { error(impl.qpdf, node, "update ivalue: items array is too short"); } @@ -64,8 +64,8 @@ NNTreeIterator::updateIValue(bool allow_invalid) throw std::logic_error( "attempt made to dereference an invalid name/number tree iterator"); } - this->ivalue.first = QPDFObjectHandle(); - this->ivalue.second = QPDFObjectHandle(); + ivalue.first = QPDFObjectHandle(); + ivalue.second = QPDFObjectHandle(); } } @@ -106,45 +106,45 @@ NNTreeIterator::getNextKid(PathElement& pe, bool backward) bool NNTreeIterator::valid() const { - return this->item_number >= 0; + return item_number >= 0; } void NNTreeIterator::increment(bool backward) { - if (this->item_number < 0) { + if (item_number < 0) { QTC::TC("qpdf", "NNTree increment end()"); deepen(impl.oh, !backward, true); return; } bool found_valid_key = false; - while (valid() && (!found_valid_key)) { - this->item_number += backward ? -2 : 2; - auto items = this->node.getKey(impl.details.itemsKey()); - if ((this->item_number < 0) || (this->item_number >= items.getArrayNItems())) { + while (valid() && !found_valid_key) { + item_number += backward ? -2 : 2; + auto items = node.getKey(impl.details.itemsKey()); + if (item_number < 0 || item_number >= items.getArrayNItems()) { bool found = false; setItemNumber(QPDFObjectHandle(), -1); - while (!(found || this->path.empty())) { - auto& element = this->path.back(); + while (!(found || path.empty())) { + auto& element = path.back(); auto pe_node = getNextKid(element, backward); if (pe_node.isNull()) { - this->path.pop_back(); + path.pop_back(); } else { found = deepen(pe_node, !backward, false); } } } - if (this->item_number >= 0) { - items = this->node.getKey(impl.details.itemsKey()); - if (this->item_number + 1 >= items.getArrayNItems()) { + if (item_number >= 0) { + items = node.getKey(impl.details.itemsKey()); + if (item_number + 1 >= items.getArrayNItems()) { QTC::TC("qpdf", "NNTree skip item at end of short items"); - warn(impl.qpdf, this->node, "items array doesn't have enough elements"); - } else if (!impl.details.keyValid(items.getArrayItem(this->item_number))) { + warn(impl.qpdf, node, "items array doesn't have enough elements"); + } else if (!impl.details.keyValid(items.getArrayItem(item_number))) { QTC::TC("qpdf", "NNTree skip invalid key"); warn( impl.qpdf, - this->node, - ("item " + std::to_string(this->item_number) + " has the wrong type")); + node, + ("item " + std::to_string(item_number) + " has the wrong type")); } else { found_valid_key = true; } @@ -153,19 +153,19 @@ NNTreeIterator::increment(bool backward) } void -NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list::iterator parent) +NNTreeIterator::resetLimits(QPDFObjectHandle a_node, std::list::iterator parent) { bool done = false; while (!done) { - if (parent == this->path.end()) { + if (parent == path.end()) { QTC::TC("qpdf", "NNTree remove limits from root"); - node.removeKey("/Limits"); + a_node.removeKey("/Limits"); done = true; break; } - auto kids = node.getKey("/Kids"); + auto kids = a_node.getKey("/Kids"); int nkids = kids.isArray() ? kids.getArrayNItems() : 0; - auto items = node.getKey(impl.details.itemsKey()); + auto items = a_node.getKey(impl.details.itemsKey()); int nitems = items.isArray() ? items.getArrayNItems() : 0; bool changed = true; @@ -191,7 +191,7 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list::itera auto limits = QPDFObjectHandle::newArray(); limits.appendItem(first); limits.appendItem(last); - auto olimits = node.getKey("/Limits"); + auto olimits = a_node.getKey("/Limits"); if (olimits.isArray() && (olimits.getArrayNItems() == 2)) { auto ofirst = olimits.getArrayItem(0); auto olast = olimits.getArrayItem(1); @@ -202,18 +202,18 @@ NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list::itera changed = false; } } - if (changed && !node.isSameObjectAs(path.begin()->node)) { - node.replaceKey("/Limits", limits); + if (changed && !a_node.isSameObjectAs(path.begin()->node)) { + a_node.replaceKey("/Limits", limits); } } else { QTC::TC("qpdf", "NNTree unable to determine limits"); - warn(impl.qpdf, node, "unable to determine limits"); + warn(impl.qpdf, a_node, "unable to determine limits"); } - if ((!changed) || (parent == this->path.begin())) { + if (!changed || parent == path.begin()) { done = true; } else { - node = parent->node; + a_node = parent->node; --parent; } } @@ -283,7 +283,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list::iterato return; } - bool is_root = (parent == this->path.end()); + bool is_root = (parent == path.end()); bool is_leaf = (nitems > 0); // CURRENT STATE: tree is in original state; iterator is valid and unchanged. @@ -312,14 +312,14 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list::iterato to_split.replaceKey("/Kids", new_kids); if (is_leaf) { QTC::TC("qpdf", "NNTree split root + leaf"); - this->node = first_node; + node = first_node; } else { QTC::TC("qpdf", "NNTree split root + !leaf"); - auto next = this->path.begin(); + auto next = path.begin(); next->node = first_node; } this->path.emplace_front(to_split, 0); - parent = this->path.begin(); + parent = path.begin(); to_split = first_node; } @@ -353,12 +353,12 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list::iterato parent_kids.insertItem(parent->kid_number + 1, second_node); auto cur_elem = parent; ++cur_elem; // points to end() for leaf nodes - int old_idx = (is_leaf ? this->item_number : cur_elem->kid_number); + int old_idx = (is_leaf ? item_number : cur_elem->kid_number); if (old_idx >= start_idx) { ++parent->kid_number; if (is_leaf) { QTC::TC("qpdf", "NNTree split second half item"); - setItemNumber(second_node, this->item_number - start_idx); + setItemNumber(second_node, item_number - start_idx); } else { QTC::TC("qpdf", "NNTree split second half kid"); cur_elem->node = second_node; @@ -377,8 +377,8 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list::iterato std::list::iterator NNTreeIterator::lastPathElement() { - auto result = this->path.end(); - if (!this->path.empty()) { + auto result = path.end(); + if (!path.empty()) { --result; } return result; @@ -394,17 +394,17 @@ NNTreeIterator::insertAfter(QPDFObjectHandle key, QPDFObjectHandle value) return; } - auto items = this->node.getKey(impl.details.itemsKey()); + auto items = node.getKey(impl.details.itemsKey()); if (!items.isArray()) { error(impl.qpdf, node, "node contains no items array"); } - if (items.getArrayNItems() < this->item_number + 2) { + if (items.getArrayNItems() < item_number + 2) { error(impl.qpdf, node, "insert: items array is too short"); } - items.insertItem(this->item_number + 2, key); - items.insertItem(this->item_number + 3, value); - resetLimits(this->node, lastPathElement()); - split(this->node, lastPathElement()); + items.insertItem(item_number + 2, key); + items.insertItem(item_number + 3, value); + resetLimits(node, lastPathElement()); + split(node, lastPathElement()); increment(false); } @@ -416,33 +416,33 @@ NNTreeIterator::remove() if (!valid()) { throw std::logic_error("attempt made to remove an invalid iterator"); } - auto items = this->node.getKey(impl.details.itemsKey()); + auto items = node.getKey(impl.details.itemsKey()); int nitems = items.getArrayNItems(); - if (this->item_number + 2 > nitems) { - error(impl.qpdf, this->node, "found short items array while removing an item"); + if (item_number + 2 > nitems) { + error(impl.qpdf, node, "found short items array while removing an item"); } - items.eraseItem(this->item_number); - items.eraseItem(this->item_number); + items.eraseItem(item_number); + items.eraseItem(item_number); nitems -= 2; if (nitems > 0) { // There are still items left - if ((this->item_number == 0) || (this->item_number == nitems)) { + if (item_number == 0 || item_number == nitems) { // We removed either the first or last item of an items array that remains non-empty, so // we have to adjust limits. QTC::TC("qpdf", "NNTree remove reset limits"); - resetLimits(this->node, lastPathElement()); + resetLimits(node, lastPathElement()); } - if (this->item_number == nitems) { + if (item_number == nitems) { // We removed the last item of a non-empty items array, so advance to the successor of // the previous item. QTC::TC("qpdf", "NNTree erased last item"); - this->item_number -= 2; + item_number -= 2; increment(false); - } else if (this->item_number < nitems) { + } else if (item_number < nitems) { // We don't have to do anything since the removed item's successor now occupies its // former location. QTC::TC("qpdf", "NNTree erased non-last item"); @@ -454,7 +454,7 @@ NNTreeIterator::remove() return; } - if (this->path.empty()) { + if (path.empty()) { // Special case: if this is the root node, we can leave it empty. QTC::TC("qpdf", "NNTree erased all items on leaf/root"); setItemNumber(impl.oh, -1); @@ -498,18 +498,18 @@ NNTreeIterator::remove() deepen(kids.getArrayItem(element->kid_number), true, true); } done = true; - } else if (parent == this->path.end()) { + } else if (parent == path.end()) { // We erased the very last item. Convert the root to an empty items array. QTC::TC("qpdf", "NNTree non-flat tree is empty after remove"); element->node.removeKey("/Kids"); element->node.replaceKey(impl.details.itemsKey(), QPDFObjectHandle::newArray()); - this->path.clear(); + path.clear(); setItemNumber(impl.oh, -1); done = true; } else { // Walk up the tree and continue QTC::TC("qpdf", "NNTree remove walking up tree"); - this->path.pop_back(); + path.pop_back(); } } } @@ -532,99 +532,99 @@ NNTreeIterator::reference NNTreeIterator::operator*() { updateIValue(false); - return this->ivalue; + return ivalue; } NNTreeIterator::pointer NNTreeIterator::operator->() { updateIValue(false); - return &(this->ivalue); + return &ivalue; } bool NNTreeIterator::operator==(NNTreeIterator const& other) const { - if ((this->item_number == -1) && (other.item_number == -1)) { + if (item_number == -1 && other.item_number == -1) { return true; } - if (this->path.size() != other.path.size()) { + if (path.size() != other.path.size()) { return false; } - auto tpi = this->path.begin(); + auto tpi = path.begin(); auto opi = other.path.begin(); - while (tpi != this->path.end()) { + while (tpi != path.end()) { if (tpi->kid_number != opi->kid_number) { return false; } ++tpi; ++opi; } - if (this->item_number != other.item_number) { + if (item_number != other.item_number) { return false; } return true; } void -NNTreeIterator::setItemNumber(QPDFObjectHandle const& node, int n) +NNTreeIterator::setItemNumber(QPDFObjectHandle const& a_node, int n) { - this->node = node; - this->item_number = n; + node = a_node; + item_number = n; updateIValue(); } void -NNTreeIterator::addPathElement(QPDFObjectHandle const& node, int kid_number) +NNTreeIterator::addPathElement(QPDFObjectHandle const& a_node, int kid_number) { - this->path.emplace_back(node, kid_number); + path.emplace_back(a_node, kid_number); } bool -NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) +NNTreeIterator::deepen(QPDFObjectHandle a_node, bool first, bool allow_empty) { // Starting at this node, descend through the first or last kid until we reach a node with // items. If we succeed, return true; otherwise return false and leave path alone. - auto opath = this->path; + auto opath = path; bool failed = false; QPDFObjGen::set seen; - for (auto const& i: this->path) { + for (auto const& i: path) { seen.add(i.node); } while (!failed) { - if (!seen.add(node)) { + if (!seen.add(a_node)) { QTC::TC("qpdf", "NNTree deepen: loop"); - warn(impl.qpdf, node, "loop detected while traversing name/number tree"); + warn(impl.qpdf, a_node, "loop detected while traversing name/number tree"); failed = true; break; } - if (!node.isDictionary()) { + if (!a_node.isDictionary()) { QTC::TC("qpdf", "NNTree node is not a dictionary"); - warn(impl.qpdf, node, "non-dictionary node while traversing name/number tree"); + warn(impl.qpdf, a_node, "non-dictionary node while traversing name/number tree"); failed = true; break; } - auto kids = node.getKey("/Kids"); + auto kids = a_node.getKey("/Kids"); int nkids = kids.isArray() ? kids.getArrayNItems() : 0; - auto items = node.getKey(impl.details.itemsKey()); + auto items = a_node.getKey(impl.details.itemsKey()); int nitems = items.isArray() ? items.getArrayNItems() : 0; if (nitems > 0) { - setItemNumber(node, first ? 0 : nitems - 2); + setItemNumber(a_node, first ? 0 : nitems - 2); break; } else if (nkids > 0) { int kid_number = first ? 0 : nkids - 1; - addPathElement(node, kid_number); + addPathElement(a_node, kid_number); auto next = kids.getArrayItem(kid_number); if (!next.isIndirect()) { if (impl.auto_repair) { QTC::TC("qpdf", "NNTree fix indirect kid"); warn( impl.qpdf, - node, + a_node, ("converting kid number " + std::to_string(kid_number) + " to an indirect object")); next = impl.qpdf.makeIndirectObject(next); @@ -633,21 +633,21 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) QTC::TC("qpdf", "NNTree warn indirect kid"); warn( impl.qpdf, - node, + a_node, ("kid number " + std::to_string(kid_number) + " is not an indirect object")); } } - node = next; + a_node = next; } else if (allow_empty && items.isArray()) { QTC::TC("qpdf", "NNTree deepen found empty"); - setItemNumber(node, -1); + setItemNumber(a_node, -1); break; } else { QTC::TC("qpdf", "NNTree deepen: invalid node"); warn( impl.qpdf, - node, + a_node, ("name/number tree node has neither non-empty " + impl.details.itemsKey() + " nor /Kids")); failed = true; @@ -655,7 +655,7 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) } } if (failed) { - this->path = opath; + path = opath; return false; } return true; @@ -671,16 +671,16 @@ NNTreeImpl::NNTreeImpl( } void -NNTreeImpl::setSplitThreshold(int split_threshold) +NNTreeImpl::setSplitThreshold(int threshold) { - this->split_threshold = split_threshold; + split_threshold = threshold; } NNTreeImpl::iterator NNTreeImpl::begin() { iterator result(*this); - result.deepen(this->oh, true, true); + result.deepen(oh, true, true); return result; } @@ -694,7 +694,7 @@ NNTreeImpl::iterator NNTreeImpl::last() { iterator result(*this); - result.deepen(this->oh, false, true); + result.deepen(oh, false, true); return result; } @@ -782,10 +782,7 @@ NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int i if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) && details.keyValid(items.getArrayItem(2 * idx))))) { QTC::TC("qpdf", "NNTree item is wrong type"); - error( - qpdf, - this->oh, - ("item at index " + std::to_string(2 * idx) + " is not the right type")); + error(qpdf, oh, ("item at index " + std::to_string(2 * idx) + " is not the right type")); } return details.compareKeys(key, items.getArrayItem(2 * idx)); } @@ -796,7 +793,7 @@ NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx if (!(kids.isArray() && (idx < kids.getArrayNItems()) && kids.getArrayItem(idx).isDictionary())) { QTC::TC("qpdf", "NNTree kid is invalid"); - error(qpdf, this->oh, "invalid kid at index " + std::to_string(idx)); + error(qpdf, oh, "invalid kid at index " + std::to_string(idx)); } return withinLimits(key, kids.getArrayItem(idx)); } @@ -810,8 +807,8 @@ NNTreeImpl::repair() for (auto const& i: *this) { repl.insert(i.first, i.second); } - this->oh.replaceKey("/Kids", new_node.getKey("/Kids")); - this->oh.replaceKey(details.itemsKey(), new_node.getKey(details.itemsKey())); + oh.replaceKey("/Kids", new_node.getKey("/Kids")); + oh.replaceKey(details.itemsKey(), new_node.getKey(details.itemsKey())); } NNTreeImpl::iterator @@ -820,9 +817,9 @@ NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found) try { return findInternal(key, return_prev_if_not_found); } catch (QPDFExc& e) { - if (this->auto_repair) { + if (auto_repair) { QTC::TC("qpdf", "NNTree repair"); - warn(qpdf, this->oh, std::string("attempting to repair after error: ") + e.what()); + warn(qpdf, oh, std::string("attempting to repair after error: ") + e.what()); repair(); return findInternal(key, return_prev_if_not_found); } else { @@ -856,7 +853,7 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) } QPDFObjGen::set seen; - auto node = this->oh; + auto node = oh; iterator result(*this); while (true) { @@ -907,7 +904,7 @@ NNTreeImpl::insertFirst(QPDFObjectHandle key, QPDFObjectHandle value) } if (!(items.isArray())) { QTC::TC("qpdf", "NNTree no valid items node in insertFirst"); - error(qpdf, this->oh, "unable to find a valid items node"); + error(qpdf, oh, "unable to find a valid items node"); } items.insertItem(0, key); items.insertItem(1, value); diff --git a/libqpdf/Pl_ASCII85Decoder.cc b/libqpdf/Pl_ASCII85Decoder.cc index 7c526b1..28905ec 100644 --- a/libqpdf/Pl_ASCII85Decoder.cc +++ b/libqpdf/Pl_ASCII85Decoder.cc @@ -57,7 +57,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) break; default: - if ((buf[i] < 33) || (buf[i] > 117)) { + if (buf[i] < 33 || buf[i] > 117) { error = true; throw std::runtime_error("character out of range during base 85 decode"); } else { diff --git a/libqpdf/Pl_ASCIIHexDecoder.cc b/libqpdf/Pl_ASCIIHexDecoder.cc index 3f80cf4..795dfc0 100644 --- a/libqpdf/Pl_ASCIIHexDecoder.cc +++ b/libqpdf/Pl_ASCIIHexDecoder.cc @@ -17,7 +17,7 @@ Pl_ASCIIHexDecoder::Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next) : void Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) { - if (this->eod) { + if (eod) { return; } for (size_t i = 0; i < len; ++i) { @@ -34,14 +34,14 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) break; case '>': - this->eod = true; + eod = true; flush(); break; default: - if (((ch >= '0') && (ch <= '9')) || ((ch >= 'A') && (ch <= 'F'))) { - this->inbuf[this->pos++] = ch; - if (this->pos == 2) { + if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) { + inbuf[pos++] = ch; + if (pos == 2) { flush(); } } else { @@ -52,7 +52,7 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) } break; } - if (this->eod) { + if (eod) { break; } } @@ -61,26 +61,26 @@ Pl_ASCIIHexDecoder::write(unsigned char const* buf, size_t len) void Pl_ASCIIHexDecoder::flush() { - if (this->pos == 0) { + if (pos == 0) { QTC::TC("libtests", "Pl_ASCIIHexDecoder no-op flush"); return; } int b[2]; for (int i = 0; i < 2; ++i) { - if (this->inbuf[i] >= 'A') { - b[i] = this->inbuf[i] - 'A' + 10; + if (inbuf[i] >= 'A') { + b[i] = inbuf[i] - 'A' + 10; } else { - b[i] = this->inbuf[i] - '0'; + b[i] = inbuf[i] - '0'; } } auto ch = static_cast((b[0] << 4) + b[1]); - QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (this->pos == 2) ? 0 : 1); + QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (pos == 2) ? 0 : 1); // Reset before calling getNext()->write in case that throws an exception. - this->pos = 0; - this->inbuf[0] = '0'; - this->inbuf[1] = '0'; - this->inbuf[2] = '\0'; + pos = 0; + inbuf[0] = '0'; + inbuf[1] = '0'; + inbuf[2] = '\0'; next()->write(&ch, 1); } diff --git a/libqpdf/Pl_Base64.cc b/libqpdf/Pl_Base64.cc index 6eab2be..c9edc42 100644 --- a/libqpdf/Pl_Base64.cc +++ b/libqpdf/Pl_Base64.cc @@ -102,17 +102,17 @@ Pl_Base64::flush_decode() for (size_t i = 0; i < 4; ++i) { int v = 0; char ch = to_c(buf[i]); - if ((ch >= 'A') && (ch <= 'Z')) { + if (ch >= 'A' && ch <= 'Z') { v = ch - 'A'; - } else if ((ch >= 'a') && (ch <= 'z')) { + } else if (ch >= 'a' && ch <= 'z') { v = ch - 'a' + 26; - } else if ((ch >= '0') && (ch <= '9')) { + } else if (ch >= '0' && ch <= '9') { v = ch - '0' + 52; - } else if ((ch == '+') || (ch == '-')) { + } else if (ch == '+' || ch == '-') { v = 62; - } else if ((ch == '/') || (ch == '_')) { + } else if (ch == '/' || ch == '_') { v = 63; - } else if ((ch == '=') && ((i == 3) || ((i == 2) && (buf[3] == '=')))) { + } else if (ch == '=' && (i == 3 || (i == 2 && buf[3] == '='))) { ++pad; end_of_data = true; v = 0; @@ -134,7 +134,7 @@ Pl_Base64::flush_decode() void Pl_Base64::flush_encode() { - int outval = ((buf[0] << 16) | (buf[1] << 8) | (buf[2])); + int outval = ((buf[0] << 16) | (buf[1] << 8) | buf[2]); unsigned char out[4] = { to_uc(outval >> 18), to_uc(0x3f & (outval >> 12)), diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc index 9691500..cdb4d4d 100644 --- a/libqpdf/Pl_LZWDecoder.cc +++ b/libqpdf/Pl_LZWDecoder.cc @@ -23,8 +23,8 @@ Pl_LZWDecoder::write(unsigned char const* bytes, size_t len) if (next_char_ == 3) { next_char_ = 0; } - this->bits_available += 8; - if (this->bits_available >= this->code_size) { + bits_available += 8; + if (bits_available >= code_size) { sendNextCode(); } } @@ -39,12 +39,12 @@ Pl_LZWDecoder::finish() void Pl_LZWDecoder::sendNextCode() { - unsigned int high = this->byte_pos; - unsigned int med = (this->byte_pos + 1) % 3; - unsigned int low = (this->byte_pos + 2) % 3; + unsigned int high = byte_pos; + unsigned int med = (byte_pos + 1) % 3; + unsigned int low = (byte_pos + 2) % 3; - unsigned int bits_from_high = 8 - this->bit_pos; - unsigned int bits_from_med = this->code_size - bits_from_high; + unsigned int bits_from_high = 8 - bit_pos; + unsigned int bits_from_med = code_size - bits_from_high; unsigned int bits_from_low = 0; if (bits_from_med > 8) { bits_from_low = bits_from_med - 8; @@ -54,23 +54,23 @@ Pl_LZWDecoder::sendNextCode() unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U); unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U); unsigned int code = 0; - code += (this->buf[high] & high_mask) << bits_from_med; - code += ((this->buf[med] & med_mask) >> (8 - bits_from_med)); + code += (buf[high] & high_mask) << bits_from_med; + code += ((buf[med] & med_mask) >> (8 - bits_from_med)); if (bits_from_low) { code <<= bits_from_low; - code += ((this->buf[low] & low_mask) >> (8 - bits_from_low)); - this->byte_pos = low; - this->bit_pos = bits_from_low; + code += ((buf[low] & low_mask) >> (8 - bits_from_low)); + byte_pos = low; + bit_pos = bits_from_low; } else { - this->byte_pos = med; - this->bit_pos = bits_from_med; + byte_pos = med; + bit_pos = bits_from_med; } - if (this->bit_pos == 8) { - this->bit_pos = 0; - ++this->byte_pos; - this->byte_pos %= 3; + if (bit_pos == 8) { + bit_pos = 0; + ++byte_pos; + byte_pos %= 3; } - this->bits_available -= this->code_size; + bits_available -= code_size; handleCode(code); } @@ -102,12 +102,12 @@ Pl_LZWDecoder::addToTable(unsigned char c) unsigned char const* last_data = nullptr; unsigned char tmp[1]; - if (this->last_code < 256) { - tmp[0] = static_cast(this->last_code); + if (last_code < 256) { + tmp[0] = static_cast(last_code); last_data = tmp; last_size = 1; - } else if (this->last_code > 257) { - unsigned int idx = this->last_code - 258; + } else if (last_code > 257) { + unsigned int idx = last_code - 258; if (idx >= table.size()) { throw std::runtime_error("Pl_LZWDecoder::addToTable: table overflow"); } @@ -116,34 +116,34 @@ Pl_LZWDecoder::addToTable(unsigned char c) last_size = QIntC::to_uint(b.getSize()); } else { throw std::runtime_error( - "Pl_LZWDecoder::addToTable called with invalid code (" + - std::to_string(this->last_code) + ")"); + "Pl_LZWDecoder::addToTable called with invalid code (" + std::to_string(last_code) + + ")"); } Buffer entry(1 + last_size); unsigned char* new_data = entry.getBuffer(); memcpy(new_data, last_data, last_size); new_data[last_size] = c; - this->table.push_back(std::move(entry)); + table.push_back(std::move(entry)); } void Pl_LZWDecoder::handleCode(unsigned int code) { - if (this->eod) { + if (eod) { return; } if (code == 256) { - if (!this->table.empty()) { + if (!table.empty()) { QTC::TC("libtests", "Pl_LZWDecoder intermediate reset"); } - this->table.clear(); - this->code_size = 9; + table.clear(); + code_size = 9; } else if (code == 257) { - this->eod = true; + eod = true; } else { - if (this->last_code != 256) { + if (last_code != 256) { // Add to the table from last time. New table entry would be what we read last plus the // first character of what we're reading now. unsigned char next_c = '\0'; @@ -159,7 +159,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) // The encoder would have just created this entry, so the first character of // this entry would have been the same as the first character of the last entry. QTC::TC("libtests", "Pl_LZWDecoder last was table size"); - next_c = getFirstChar(this->last_code); + next_c = getFirstChar(last_code); } else { next_c = getFirstChar(code); } @@ -171,7 +171,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) addToTable(next_c); unsigned int change_idx = new_idx + code_change_delta; if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) { - ++this->code_size; + ++code_size; } } @@ -188,5 +188,5 @@ Pl_LZWDecoder::handleCode(unsigned int code) } } - this->last_code = code; + last_code = code; } diff --git a/libqpdf/Pl_MD5.cc b/libqpdf/Pl_MD5.cc index 616d15b..a5985a9 100644 --- a/libqpdf/Pl_MD5.cc +++ b/libqpdf/Pl_MD5.cc @@ -13,10 +13,10 @@ Pl_MD5::Pl_MD5(char const* identifier, Pipeline* next) : void Pl_MD5::write(unsigned char const* buf, size_t len) { - if (this->enabled) { - if (!this->in_progress) { - this->md5.reset(); - this->in_progress = true; + if (enabled) { + if (!in_progress) { + md5.reset(); + in_progress = true; } // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. @@ -25,7 +25,7 @@ Pl_MD5::write(unsigned char const* buf, size_t len) unsigned char const* data = buf; while (bytes_left > 0) { size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); - this->md5.encodeDataIncrementally(reinterpret_cast(data), bytes); + md5.encodeDataIncrementally(reinterpret_cast(data), bytes); bytes_left -= bytes; data += bytes; } @@ -38,29 +38,29 @@ void Pl_MD5::finish() { next()->finish(); - if (!this->persist_across_finish) { - this->in_progress = false; + if (!persist_across_finish) { + in_progress = false; } } void -Pl_MD5::enable(bool enabled) +Pl_MD5::enable(bool is_enabled) { - this->enabled = enabled; + enabled = is_enabled; } void Pl_MD5::persistAcrossFinish(bool persist) { - this->persist_across_finish = persist; + persist_across_finish = persist; } std::string Pl_MD5::getHexDigest() { - if (!this->enabled) { + if (!enabled) { throw std::logic_error("digest requested for a disabled MD5 Pipeline"); } - this->in_progress = false; - return this->md5.unparse(); + in_progress = false; + return md5.unparse(); } diff --git a/libqpdf/Pl_SHA2.cc b/libqpdf/Pl_SHA2.cc index 9514d1c..546ff63 100644 --- a/libqpdf/Pl_SHA2.cc +++ b/libqpdf/Pl_SHA2.cc @@ -2,6 +2,7 @@ #include #include + #include Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : @@ -15,8 +16,8 @@ Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) : void Pl_SHA2::write(unsigned char const* buf, size_t len) { - if (!this->in_progress) { - this->in_progress = true; + if (!in_progress) { + in_progress = true; } // Write in chunks in case len is too big to fit in an int. Assume int is at least 32 bits. @@ -25,7 +26,7 @@ Pl_SHA2::write(unsigned char const* buf, size_t len) unsigned char const* data = buf; while (bytes_left > 0) { size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); - this->crypto->SHA2_update(data, bytes); + crypto->SHA2_update(data, bytes); bytes_left -= bytes; data += bytes; } @@ -41,33 +42,33 @@ Pl_SHA2::finish() if (next()) { next()->finish(); } - this->crypto->SHA2_finalize(); - this->in_progress = false; + crypto->SHA2_finalize(); + in_progress = false; } void Pl_SHA2::resetBits(int bits) { - if (this->in_progress) { + if (in_progress) { throw std::logic_error("bit reset requested for in-progress SHA2 Pipeline"); } - this->crypto = QPDFCryptoProvider::getImpl(); - this->crypto->SHA2_init(bits); + crypto = QPDFCryptoProvider::getImpl(); + crypto->SHA2_init(bits); } std::string Pl_SHA2::getRawDigest() { - if (this->in_progress) { + if (in_progress) { throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); } - return this->crypto->SHA2_digest(); + return crypto->SHA2_digest(); } std::string Pl_SHA2::getHexDigest() { - if (this->in_progress) { + if (in_progress) { throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); } return QUtil::hex_encode(getRawDigest()); diff --git a/libqpdf/QPDFCrypto_gnutls.cc b/libqpdf/QPDFCrypto_gnutls.cc index ee46041..ce38095 100644 --- a/libqpdf/QPDFCrypto_gnutls.cc +++ b/libqpdf/QPDFCrypto_gnutls.cc @@ -18,14 +18,14 @@ QPDFCrypto_gnutls::QPDFCrypto_gnutls() : QPDFCrypto_gnutls::~QPDFCrypto_gnutls() { - if (this->hash_ctx) { - gnutls_hash_deinit(this->hash_ctx, digest); + if (hash_ctx) { + gnutls_hash_deinit(hash_ctx, digest); } if (cipher_ctx) { - gnutls_cipher_deinit(this->cipher_ctx); + gnutls_cipher_deinit(cipher_ctx); } - this->aes_key_data = nullptr; - this->aes_key_len = 0; + aes_key_data = nullptr; + aes_key_len = 0; } void @@ -43,9 +43,9 @@ void QPDFCrypto_gnutls::MD5_init() { MD5_finalize(); - int code = gnutls_hash_init(&this->hash_ctx, GNUTLS_DIG_MD5); + int code = gnutls_hash_init(&hash_ctx, GNUTLS_DIG_MD5); if (code < 0) { - this->hash_ctx = nullptr; + hash_ctx = nullptr; throw std::runtime_error( std::string("gnutls: MD5 error: ") + std::string(gnutls_strerror(code))); } @@ -54,22 +54,22 @@ QPDFCrypto_gnutls::MD5_init() void QPDFCrypto_gnutls::MD5_update(unsigned char const* data, size_t len) { - gnutls_hash(this->hash_ctx, data, len); + gnutls_hash(hash_ctx, data, len); } void QPDFCrypto_gnutls::MD5_finalize() { - if (this->hash_ctx) { - gnutls_hash_deinit(this->hash_ctx, this->digest); - this->hash_ctx = nullptr; + if (hash_ctx) { + gnutls_hash_deinit(hash_ctx, digest); + hash_ctx = nullptr; } } void QPDFCrypto_gnutls::MD5_digest(MD5_Digest d) { - memcpy(d, this->digest, sizeof(MD5_Digest)); + memcpy(d, digest, sizeof(MD5_Digest)); } void @@ -83,9 +83,9 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) key.data = const_cast(key_data); key.size = QIntC::to_uint(key_len); - int code = gnutls_cipher_init(&this->cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr); + int code = gnutls_cipher_init(&cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr); if (code < 0) { - this->cipher_ctx = nullptr; + cipher_ctx = nullptr; throw std::runtime_error( std::string("gnutls: RC4 error: ") + std::string(gnutls_strerror(code))); } @@ -94,15 +94,15 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) void QPDFCrypto_gnutls::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) { - gnutls_cipher_encrypt2(this->cipher_ctx, in_data, len, out_data, len); + gnutls_cipher_encrypt2(cipher_ctx, in_data, len, out_data, len); } void QPDFCrypto_gnutls::RC4_finalize() { - if (this->cipher_ctx) { - gnutls_cipher_deinit(this->cipher_ctx); - this->cipher_ctx = nullptr; + if (cipher_ctx) { + gnutls_cipher_deinit(cipher_ctx); + cipher_ctx = nullptr; } } @@ -125,10 +125,10 @@ QPDFCrypto_gnutls::SHA2_init(int bits) badBits(); break; } - this->sha2_bits = bits; - int code = gnutls_hash_init(&this->hash_ctx, alg); + sha2_bits = bits; + int code = gnutls_hash_init(&hash_ctx, alg); if (code < 0) { - this->hash_ctx = nullptr; + hash_ctx = nullptr; throw std::runtime_error( std::string("gnutls: SHA") + std::to_string(bits) + " error: " + std::string(gnutls_strerror(code))); @@ -138,15 +138,15 @@ QPDFCrypto_gnutls::SHA2_init(int bits) void QPDFCrypto_gnutls::SHA2_update(unsigned char const* data, size_t len) { - gnutls_hash(this->hash_ctx, data, len); + gnutls_hash(hash_ctx, data, len); } void QPDFCrypto_gnutls::SHA2_finalize() { - if (this->hash_ctx) { - gnutls_hash_deinit(this->hash_ctx, this->digest); - this->hash_ctx = nullptr; + if (hash_ctx) { + gnutls_hash_deinit(hash_ctx, digest); + hash_ctx = nullptr; } } @@ -154,15 +154,15 @@ std::string QPDFCrypto_gnutls::SHA2_digest() { std::string result; - switch (this->sha2_bits) { + switch (sha2_bits) { case 256: - result = std::string(reinterpret_cast(this->digest), 32); + result = std::string(reinterpret_cast(digest), 32); break; case 384: - result = std::string(reinterpret_cast(this->digest), 48); + result = std::string(reinterpret_cast(digest), 48); break; case 512: - result = std::string(reinterpret_cast(this->digest), 64); + result = std::string(reinterpret_cast(digest), 64); break; default: badBits(); @@ -184,8 +184,8 @@ QPDFCrypto_gnutls::rijndael_init( this->cbc_mode = cbc_mode; if (!cbc_mode) { // Save the key so we can re-initialize. - this->aes_key_data = key_data; - this->aes_key_len = key_len; + aes_key_data = key_data; + aes_key_len = key_len; } gnutls_cipher_algorithm_t alg = GNUTLS_CIPHER_UNKNOWN; @@ -214,9 +214,9 @@ QPDFCrypto_gnutls::rijndael_init( iv.data = cbc_block; iv.size = rijndael_buf_size; - int code = gnutls_cipher_init(&this->cipher_ctx, alg, &cipher_key, &iv); + int code = gnutls_cipher_init(&cipher_ctx, alg, &cipher_key, &iv); if (code < 0) { - this->cipher_ctx = nullptr; + cipher_ctx = nullptr; throw std::runtime_error( std::string("gnutls: AES error: ") + std::string(gnutls_strerror(code))); } @@ -225,29 +225,27 @@ QPDFCrypto_gnutls::rijndael_init( void QPDFCrypto_gnutls::rijndael_process(unsigned char* in_data, unsigned char* out_data) { - if (this->encrypt) { - gnutls_cipher_encrypt2( - this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); + if (encrypt) { + gnutls_cipher_encrypt2(cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); } else { - gnutls_cipher_decrypt2( - this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); + gnutls_cipher_decrypt2(cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); } // Gnutls doesn't support AES in ECB (non-CBC) mode, but the result is the same as if you just // reset the cbc block to all zeroes each time. We jump through a few hoops here to make this // work. - if (!this->cbc_mode) { + if (!cbc_mode) { static unsigned char zeroes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - rijndael_init(this->encrypt, this->aes_key_data, this->aes_key_len, false, zeroes); + rijndael_init(encrypt, aes_key_data, aes_key_len, false, zeroes); } } void QPDFCrypto_gnutls::rijndael_finalize() { - if (this->cipher_ctx) { - gnutls_cipher_deinit(this->cipher_ctx); - this->cipher_ctx = nullptr; + if (cipher_ctx) { + gnutls_cipher_deinit(cipher_ctx); + cipher_ctx = nullptr; } } diff --git a/libqpdf/QPDFCrypto_native.cc b/libqpdf/QPDFCrypto_native.cc index 9e9cba5..6a38ad1 100644 --- a/libqpdf/QPDFCrypto_native.cc +++ b/libqpdf/QPDFCrypto_native.cc @@ -40,37 +40,37 @@ QPDFCrypto_native::provideRandomData(unsigned char* data, size_t len) void QPDFCrypto_native::MD5_init() { - this->md5 = std::make_shared(); + md5 = std::make_shared(); } void QPDFCrypto_native::MD5_update(unsigned char const* data, size_t len) { - this->md5->update(const_cast(data), len); + md5->update(const_cast(data), len); } void QPDFCrypto_native::MD5_finalize() { - this->md5->finalize(); + md5->finalize(); } void QPDFCrypto_native::MD5_digest(MD5_Digest d) { - this->md5->digest(d); + md5->digest(d); } void QPDFCrypto_native::RC4_init(unsigned char const* key_data, int key_len) { - this->rc4 = std::make_shared(key_data, key_len); + rc4 = std::make_shared(key_data, key_len); } void QPDFCrypto_native::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) { - this->rc4->process(in_data, len, out_data); + rc4->process(in_data, len, out_data); } void @@ -81,25 +81,25 @@ QPDFCrypto_native::RC4_finalize() void QPDFCrypto_native::SHA2_init(int bits) { - this->sha2 = std::make_shared(bits); + sha2 = std::make_shared(bits); } void QPDFCrypto_native::SHA2_update(unsigned char const* data, size_t len) { - this->sha2->update(data, len); + sha2->update(data, len); } void QPDFCrypto_native::SHA2_finalize() { - this->sha2->finalize(); + sha2->finalize(); } std::string QPDFCrypto_native::SHA2_digest() { - return this->sha2->getRawDigest(); + return sha2->getRawDigest(); } void @@ -111,14 +111,13 @@ QPDFCrypto_native::rijndael_init( unsigned char* cbc_block) { - this->aes_pdf = - std::make_shared(encrypt, key_data, key_len, cbc_mode, cbc_block); + aes_pdf = std::make_shared(encrypt, key_data, key_len, cbc_mode, cbc_block); } void QPDFCrypto_native::rijndael_process(unsigned char* in_data, unsigned char* out_data) { - this->aes_pdf->update(in_data, out_data); + aes_pdf->update(in_data, out_data); } void diff --git a/libqpdf/QPDFCrypto_openssl.cc b/libqpdf/QPDFCrypto_openssl.cc index 92125b4..667b82c 100644 --- a/libqpdf/QPDFCrypto_openssl.cc +++ b/libqpdf/QPDFCrypto_openssl.cc @@ -236,9 +236,7 @@ QPDFCrypto_openssl::rijndael_init( } check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx)); - check_openssl( - // line-break - EVP_CipherInit_ex(cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt)); + check_openssl(EVP_CipherInit_ex(cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt)); check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0)); } diff --git a/libqpdf/QPDFEmbeddedFileDocumentHelper.cc b/libqpdf/QPDFEmbeddedFileDocumentHelper.cc index fd735e7..6d1653d 100644 --- a/libqpdf/QPDFEmbeddedFileDocumentHelper.cc +++ b/libqpdf/QPDFEmbeddedFileDocumentHelper.cc @@ -63,7 +63,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() } auto embedded_files = names.getKey("/EmbeddedFiles"); if (!embedded_files.isDictionary()) { - auto nth = QPDFNameTreeObjectHelper::newEmpty(this->qpdf); + auto nth = QPDFNameTreeObjectHelper::newEmpty(qpdf); names.replaceKey("/EmbeddedFiles", nth.getObjectHandle()); m->embedded_files = std::make_shared(nth); } @@ -115,7 +115,7 @@ QPDFEmbeddedFileDocumentHelper::removeEmbeddedFile(std::string const& name) auto oh = iter->second; iter.remove(); if (oh.isIndirect()) { - this->qpdf.replaceObject(oh.getObjGen(), QPDFObjectHandle::newNull()); + qpdf.replaceObject(oh.getObjGen(), QPDFObjectHandle::newNull()); } return true; diff --git a/libqpdf/QPDFNameTreeObjectHelper.cc b/libqpdf/QPDFNameTreeObjectHelper.cc index 9a2a628..16c0822 100644 --- a/libqpdf/QPDFNameTreeObjectHelper.cc +++ b/libqpdf/QPDFNameTreeObjectHelper.cc @@ -89,11 +89,11 @@ QPDFNameTreeObjectHelper::iterator::updateIValue() { if (impl->valid()) { auto p = *impl; - this->ivalue.first = p->first.getUTF8Value(); - this->ivalue.second = p->second; + ivalue.first = p->first.getUTF8Value(); + ivalue.second = p->second; } else { - this->ivalue.first = ""; - this->ivalue.second = QPDFObjectHandle(); + ivalue.first = ""; + ivalue.second = QPDFObjectHandle(); } } @@ -101,14 +101,14 @@ QPDFNameTreeObjectHelper::iterator::reference QPDFNameTreeObjectHelper::iterator::operator*() { updateIValue(); - return this->ivalue; + return ivalue; } QPDFNameTreeObjectHelper::iterator::pointer QPDFNameTreeObjectHelper::iterator::operator->() { updateIValue(); - return &this->ivalue; + return &ivalue; } bool diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index 51d32f0..4591677 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -1169,8 +1169,8 @@ QPDFObjectHandle QPDF::readTrailer() { qpdf_offset_t offset = m->file->tell(); - auto [object, empty] = QPDFParser::parse( - *m->file, "trailer", m->tokenizer, nullptr, *this, m->reconstructed_xref); + auto [object, empty] = + QPDFParser::parse(*m->file, "trailer", m->tokenizer, nullptr, *this, m->reconstructed_xref); if (empty) { // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in // actual PDF files and Adobe Reader appears to ignore them. diff --git a/libqpdf/RC4.cc b/libqpdf/RC4.cc index c903fc1..43b1644 100644 --- a/libqpdf/RC4.cc +++ b/libqpdf/RC4.cc @@ -5,11 +5,11 @@ RC4::RC4(unsigned char const* key_data, int key_len) : crypto(QPDFCryptoProvider::getImpl()) { - this->crypto->RC4_init(key_data, key_len); + crypto->RC4_init(key_data, key_len); } void RC4::process(unsigned char const* in_data, size_t len, unsigned char* out_data) { - this->crypto->RC4_process(in_data, len, out_data); + crypto->RC4_process(in_data, len, out_data); } diff --git a/libqpdf/qpdf/QPDFCrypto_native.hh b/libqpdf/qpdf/QPDFCrypto_native.hh index 0ca4b37..7e558fc 100644 --- a/libqpdf/qpdf/QPDFCrypto_native.hh +++ b/libqpdf/qpdf/QPDFCrypto_native.hh @@ -6,6 +6,7 @@ #include #include #include + #include class QPDFCrypto_native final: public QPDFCryptoImpl