2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-29 08:20:53 +00:00
qpdf/libqpdf/Pl_RC4.cc
Jay Berkenbilt cb769c62e5 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.
2022-02-08 11:51:15 -05:00

50 lines
1.1 KiB
C++

#include <qpdf/Pl_RC4.hh>
#include <qpdf/QUtil.hh>
Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next,
unsigned char const* key_data, int key_len,
size_t out_bufsize) :
Pipeline(identifier, next),
out_bufsize(out_bufsize),
rc4(key_data, key_len)
{
this->outbuf = make_array_pointer_holder<unsigned char>(out_bufsize);
}
Pl_RC4::~Pl_RC4()
{
}
void
Pl_RC4::write(unsigned char* data, size_t len)
{
if (this->outbuf.get() == 0)
{
throw std::logic_error(
this->identifier +
": Pl_RC4: write() called after finish() called");
}
size_t bytes_left = len;
unsigned char* p = data;
while (bytes_left > 0)
{
size_t bytes =
(bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
bytes_left -= bytes;
// lgtm[cpp/weak-cryptographic-algorithm]
rc4.process(p, bytes, outbuf.get());
p += bytes;
getNext()->write(outbuf.get(), bytes);
}
}
void
Pl_RC4::finish()
{
this->outbuf = 0;
this->getNext()->finish();
}