2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Pl_RC4.hh>
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
Pl_RC4::Pl_RC4(
|
|
|
|
char const* identifier,
|
|
|
|
Pipeline* next,
|
|
|
|
unsigned char const* key_data,
|
|
|
|
int key_len,
|
|
|
|
size_t out_bufsize) :
|
2008-04-29 12:55:25 +00:00
|
|
|
Pipeline(identifier, next),
|
|
|
|
out_bufsize(out_bufsize),
|
|
|
|
rc4(key_data, key_len)
|
|
|
|
{
|
2022-04-09 18:35:56 +00:00
|
|
|
this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-05-03 21:43:07 +00:00
|
|
|
Pl_RC4::write(unsigned char const* data, size_t len)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2022-08-07 09:33:25 +00:00
|
|
|
if (this->outbuf == nullptr) {
|
2023-05-21 17:35:09 +00:00
|
|
|
throw std::logic_error(this->identifier + ": Pl_RC4: write() called after finish() called");
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t bytes_left = len;
|
2022-05-03 21:43:07 +00:00
|
|
|
unsigned char const* p = data;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
while (bytes_left > 0) {
|
2023-05-21 17:35:09 +00:00
|
|
|
size_t bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
|
2022-02-08 14:18:08 +00:00
|
|
|
bytes_left -= bytes;
|
2021-11-10 22:57:12 +00:00
|
|
|
// lgtm[cpp/weak-cryptographic-algorithm]
|
2022-02-08 14:18:08 +00:00
|
|
|
rc4.process(p, bytes, outbuf.get());
|
|
|
|
p += bytes;
|
|
|
|
getNext()->write(outbuf.get(), bytes);
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_RC4::finish()
|
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
this->outbuf = nullptr;
|
2008-04-29 12:55:25 +00:00
|
|
|
this->getNext()->finish();
|
|
|
|
}
|