From 9a0b88bf7777c153dc46ace22db74ef24d51583a Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 29 Apr 2008 12:55:25 +0000 Subject: update release date to actual date git-svn-id: svn+q:///qpdf/trunk@599 71b93d88-0707-0410-a8cf-f5a4172ac649 --- libqpdf/Pl_RC4.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 libqpdf/Pl_RC4.cc (limited to 'libqpdf/Pl_RC4.cc') diff --git a/libqpdf/Pl_RC4.cc b/libqpdf/Pl_RC4.cc new file mode 100644 index 00000000..74e53c8b --- /dev/null +++ b/libqpdf/Pl_RC4.cc @@ -0,0 +1,57 @@ + +#include + +#include + +Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next, + unsigned char const* key_data, int key_len, + int 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, int len) +{ + if (this->outbuf == 0) + { + throw Exception( + this->identifier + + ": Pl_RC4: write() called after finish() called"); + } + + int bytes_left = len; + unsigned char* p = data; + + while (bytes_left > 0) + { + int 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(); +} -- cgit v1.2.3-70-g09d2