Coverage Report

Created: 2026-11-12 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qpdf/libqpdf/Pl_RC4.cc
Line
Count
Source
1
#include <qpdf/Pl_RC4.hh>
2
3
#include <qpdf/QUtil.hh>
4
#include <qpdf/Util.hh>
5
6
using namespace qpdf;
7
8
Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next, std::string key, size_t out_bufsize) :
9
202
    Pipeline(identifier, next),
10
202
    out_bufsize(out_bufsize),
11
202
    rc4(reinterpret_cast<unsigned char const*>(key.data()), static_cast<int>(key.size()))
12
202
{
13
202
    util::assertion(next, "Attempt to create Pl_RC4 with nullptr as next");
14
202
    this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize);
15
202
}
16
17
void
18
Pl_RC4::write(unsigned char const* data, size_t len)
19
202
{
20
202
    util::assertion(outbuf.get(), "Pl_RC4: write() called after finish() called");
21
22
202
    size_t bytes_left = len;
23
202
    unsigned char const* p = data;
24
25
427
    while (bytes_left > 0) {
26
225
        size_t bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
27
225
        bytes_left -= bytes;
28
225
        rc4.process(p, bytes, outbuf.get());
29
225
        p += bytes;
30
225
        next()->write(outbuf.get(), bytes);
31
225
    }
32
202
}
33
34
void
35
Pl_RC4::finish()
36
202
{
37
202
    outbuf = nullptr;
38
202
    next()->finish();
39
202
}