2008-04-29 12:55:25 +00:00
|
|
|
#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,
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t out_bufsize) :
|
2008-04-29 12:55:25 +00:00
|
|
|
Pipeline(identifier, next),
|
|
|
|
out_bufsize(out_bufsize),
|
|
|
|
rc4(key_data, key_len)
|
|
|
|
{
|
2019-06-22 18:24:49 +00:00
|
|
|
this->outbuf = PointerHolder<unsigned char>(
|
|
|
|
true, new unsigned char[out_bufsize]);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Pl_RC4::~Pl_RC4()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-20 15:20:57 +00:00
|
|
|
Pl_RC4::write(unsigned char* data, size_t len)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2019-06-22 18:24:49 +00:00
|
|
|
if (this->outbuf.getPointer() == 0)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2009-09-26 18:36:04 +00:00
|
|
|
throw std::logic_error(
|
2008-04-29 12:55:25 +00:00
|
|
|
this->identifier +
|
|
|
|
": Pl_RC4: write() called after finish() called");
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t bytes_left = len;
|
2008-04-29 12:55:25 +00:00
|
|
|
unsigned char* p = data;
|
|
|
|
|
|
|
|
while (bytes_left > 0)
|
|
|
|
{
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t bytes =
|
|
|
|
(bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
|
2008-04-29 12:55:25 +00:00
|
|
|
bytes_left -= bytes;
|
2019-06-22 18:24:49 +00:00
|
|
|
rc4.process(p, bytes, outbuf.getPointer());
|
2008-04-29 12:55:25 +00:00
|
|
|
p += bytes;
|
2019-06-22 18:24:49 +00:00
|
|
|
getNext()->write(outbuf.getPointer(), bytes);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_RC4::finish()
|
|
|
|
{
|
2018-08-12 16:58:39 +00:00
|
|
|
this->outbuf = 0;
|
2008-04-29 12:55:25 +00:00
|
|
|
this->getNext()->finish();
|
|
|
|
}
|