2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-11 15:40:58 +00:00
qpdf/libqpdf/Pl_RC4.cc
Jay Berkenbilt 5d4cad9c02 ABI change: fix use of off_t, size_t, and integer types
Significantly improve the code's use of off_t for file offsets, size_t
for memory sizes, and integer types in cases where there has to be
compatibility with external interfaces.  Rework sections of the code
that would have prevented qpdf from working on files larger than 2 (or
maybe 4) GB in size.
2012-06-20 15:20:26 -04:00

57 lines
1.0 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 = new unsigned char[out_bufsize];
}
Pl_RC4::~Pl_RC4()
{
if (this->outbuf)
{
delete [] this->outbuf;
this->outbuf = 0;
}
}
void
Pl_RC4::write(unsigned char* data, size_t len)
{
if (this->outbuf == 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;
rc4.process(p, (int)bytes, outbuf);
p += bytes;
getNext()->write(outbuf, bytes);
}
}
void
Pl_RC4::finish()
{
if (this->outbuf)
{
delete [] this->outbuf;
this->outbuf = 0;
}
this->getNext()->finish();
}