diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-02-08 15:18:08 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-02-08 17:51:15 +0100 |
commit | cb769c62e55599e9f980001830bc61d9fcaa64a9 (patch) | |
tree | 0bf980c385a61cbc8720cf990762ffc1200f9d6a /libqpdf/Pl_AES_PDF.cc | |
parent | 716381f65a2b2dc72f8da2426ba71aeab02c507f (diff) | |
download | qpdf-cb769c62e55599e9f980001830bc61d9fcaa64a9.tar.zst |
WHITESPACE ONLY -- expand tabs in source code
This comment expands all tabs using an 8-character tab-width. You
should ignore this commit when using git blame or use git blame -w.
In the early days, I used to use tabs where possible for indentation,
since emacs did this automatically. In recent years, I have switched
to only using spaces, which means qpdf source code has been a mixture
of spaces and tabs. I have avoided cleaning this up because of not
wanting gratuitous whitespaces change to cloud the output of git
blame, but I changed my mind after discussing with users who view qpdf
source code in editors/IDEs that have other tab widths by default and
in light of the fact that I am planning to start applying automatic
code formatting soon.
Diffstat (limited to 'libqpdf/Pl_AES_PDF.cc')
-rw-r--r-- | libqpdf/Pl_AES_PDF.cc | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc index de1f666f..581ca9ab 100644 --- a/libqpdf/Pl_AES_PDF.cc +++ b/libqpdf/Pl_AES_PDF.cc @@ -12,7 +12,7 @@ bool Pl_AES_PDF::use_static_iv = false; Pl_AES_PDF::Pl_AES_PDF(char const* identifier, Pipeline* next, - bool encrypt, unsigned char const* key, + bool encrypt, unsigned char const* key, size_t key_bytes) : Pipeline(identifier, next), crypto(QPDFCryptoProvider::getImpl()), @@ -81,17 +81,17 @@ Pl_AES_PDF::write(unsigned char* data, size_t len) while (bytes_left > 0) { - if (this->offset == this->buf_size) - { - flush(false); - } - - size_t available = this->buf_size - this->offset; - size_t bytes = (bytes_left < available ? bytes_left : available); - bytes_left -= bytes; - std::memcpy(this->inbuf + this->offset, p, bytes); - this->offset += bytes; - p += bytes; + if (this->offset == this->buf_size) + { + flush(false); + } + + size_t available = this->buf_size - this->offset; + size_t bytes = (bytes_left < available ? bytes_left : available); + bytes_left -= bytes; + std::memcpy(this->inbuf + this->offset, p, bytes); + this->offset += bytes; + p += bytes; } } @@ -100,10 +100,10 @@ Pl_AES_PDF::finish() { if (this->encrypt) { - if (this->offset == this->buf_size) - { - flush(false); - } + if (this->offset == this->buf_size) + { + flush(false); + } if (! this->disable_padding) { // Pad as described in section 3.5.1 of version 1.7 of the PDF @@ -118,19 +118,19 @@ Pl_AES_PDF::finish() } else { - if (this->offset != this->buf_size) - { - // This is never supposed to happen as the output is - // always supposed to be padded. However, we have - // encountered files for which the output is not a - // multiple of the block size. In this case, pad with - // zeroes and hope for the best. - assert(this->buf_size > this->offset); - std::memset(this->inbuf + this->offset, 0, - this->buf_size - this->offset); - this->offset = this->buf_size; - } - flush(! this->disable_padding); + if (this->offset != this->buf_size) + { + // This is never supposed to happen as the output is + // always supposed to be padded. However, we have + // encountered files for which the output is not a + // multiple of the block size. In this case, pad with + // zeroes and hope for the best. + assert(this->buf_size > this->offset); + std::memset(this->inbuf + this->offset, 0, + this->buf_size - this->offset); + this->offset = this->buf_size; + } + flush(! this->disable_padding); } this->crypto->rijndael_finalize(); getNext()->finish(); @@ -141,10 +141,10 @@ Pl_AES_PDF::initializeVector() { if (use_zero_iv) { - for (unsigned int i = 0; i < this->buf_size; ++i) - { - this->cbc_block[i] = 0; - } + for (unsigned int i = 0; i < this->buf_size; ++i) + { + this->cbc_block[i] = 0; + } } else if (use_specified_iv) { @@ -152,10 +152,10 @@ Pl_AES_PDF::initializeVector() } else if (use_static_iv) { - for (unsigned int i = 0; i < this->buf_size; ++i) - { - this->cbc_block[i] = static_cast<unsigned char>(14U * (1U + i)); - } + for (unsigned int i = 0; i < this->buf_size; ++i) + { + this->cbc_block[i] = static_cast<unsigned char>(14U * (1U + i)); + } } else { @@ -170,35 +170,35 @@ Pl_AES_PDF::flush(bool strip_padding) if (first) { - first = false; + first = false; bool return_after_init = false; - if (this->cbc_mode) - { - if (encrypt) - { - // Set cbc_block to the initialization vector, and if - // not zero, write it to the output stream. - initializeVector(); + if (this->cbc_mode) + { + if (encrypt) + { + // Set cbc_block to the initialization vector, and if + // not zero, write it to the output stream. + initializeVector(); if (! (this->use_zero_iv || this->use_specified_iv)) { getNext()->write(this->cbc_block, this->buf_size); } - } - else if (this->use_zero_iv || this->use_specified_iv) + } + else if (this->use_zero_iv || this->use_specified_iv) { // Initialize vector with zeroes; zero vector was not // written to the beginning of the input file. initializeVector(); } else - { - // Take the first block of input as the initialization - // vector. There's nothing to write at this time. - memcpy(this->cbc_block, this->inbuf, this->buf_size); - this->offset = 0; + { + // Take the first block of input as the initialization + // vector. There's nothing to write at this time. + memcpy(this->cbc_block, this->inbuf, this->buf_size); + this->offset = 0; return_after_init = true; - } - } + } + } this->crypto->rijndael_init( encrypt, this->key.get(), key_bytes, this->cbc_mode, this->cbc_block); @@ -212,23 +212,23 @@ Pl_AES_PDF::flush(bool strip_padding) unsigned int bytes = this->buf_size; if (strip_padding) { - unsigned char last = this->outbuf[this->buf_size - 1]; - if (last <= this->buf_size) - { - bool strip = true; - for (unsigned int i = 1; i <= last; ++i) - { - if (this->outbuf[this->buf_size - i] != last) - { - strip = false; - break; - } - } - if (strip) - { - bytes -= last; - } - } + unsigned char last = this->outbuf[this->buf_size - 1]; + if (last <= this->buf_size) + { + bool strip = true; + for (unsigned int i = 1; i <= last; ++i) + { + if (this->outbuf[this->buf_size - i] != last) + { + strip = false; + break; + } + } + if (strip) + { + bytes -= last; + } + } } this->offset = 0; getNext()->write(this->outbuf, bytes); |