summaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_Integer.cc
AgeCommit message (Expand)Author
2013-01-22Add getTypeCode() and getTypeName()Jay Berkenbilt
2012-06-24Change QPDF_Integer from int to long longJay Berkenbilt
2009-09-26removed qexc; non-compatible ABI changeJay Berkenbilt
2008-04-29update release date to actual daterelease-qpdf-2.0Jay Berkenbilt
a id='n46' href='#n46'>46 47 48 49 50 51 52 53 54 55 56
#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, bytes, outbuf);
	p += bytes;
	getNext()->write(outbuf, bytes);
    }
}

void
Pl_RC4::finish()
{
    if (this->outbuf)
    {
	delete [] this->outbuf;
	this->outbuf = 0;
    }
    this->getNext()->finish();
}