Coverage Report

Created: 2025-12-05 06:54

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
2.08k
    Pipeline(identifier, next),
10
2.08k
    out_bufsize(out_bufsize),
11
2.08k
    rc4(reinterpret_cast<unsigned char const*>(key.data()), static_cast<int>(key.size()))
12
2.08k
{
13
2.08k
    util::assertion(next, "Attempt to create Pl_RC4 with nullptr as next");
14
2.08k
    this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize);
15
2.08k
}
16
17
void
18
Pl_RC4::write(unsigned char const* data, size_t len)
19
2.08k
{
20
2.08k
    util::assertion(outbuf.get(), "Pl_RC4: write() called after finish() called");
21
22
2.08k
    size_t bytes_left = len;
23
2.08k
    unsigned char const* p = data;
24
25
4.29k
    while (bytes_left > 0) {
26
2.21k
        size_t bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
27
2.21k
        bytes_left -= bytes;
28
2.21k
        rc4.process(p, bytes, outbuf.get());
29
2.21k
        p += bytes;
30
2.21k
        next()->write(outbuf.get(), bytes);
31
2.21k
    }
32
2.08k
}
33
34
void
35
Pl_RC4::finish()
36
2.07k
{
37
2.07k
    outbuf = nullptr;
38
2.07k
    next()->finish();
39
2.07k
}