Coverage Report

Created: 2025-08-26 07:07

/src/qpdf/libqpdf/Pl_RC4.cc
Line
Count
Source (jump to first uncovered line)
1
#include <qpdf/Pl_RC4.hh>
2
3
#include <qpdf/QUtil.hh>
4
5
Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next, std::string key, size_t out_bufsize) :
6
0
    Pipeline(identifier, next),
7
0
    out_bufsize(out_bufsize),
8
0
    rc4(reinterpret_cast<unsigned char const*>(key.data()), static_cast<int>(key.size()))
9
0
{
10
0
    if (!next) {
11
0
        throw std::logic_error("Attempt to create Pl_RC4 with nullptr as next");
12
0
    }
13
0
    this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize);
14
0
}
15
16
void
17
Pl_RC4::write(unsigned char const* data, size_t len)
18
0
{
19
0
    if (this->outbuf == nullptr) {
20
0
        throw std::logic_error(this->identifier + ": Pl_RC4: write() called after finish() called");
21
0
    }
22
23
0
    size_t bytes_left = len;
24
0
    unsigned char const* p = data;
25
26
0
    while (bytes_left > 0) {
27
0
        size_t bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
28
0
        bytes_left -= bytes;
29
        // lgtm[cpp/weak-cryptographic-algorithm]
30
0
        rc4.process(p, bytes, outbuf.get());
31
0
        p += bytes;
32
0
        next()->write(outbuf.get(), bytes);
33
0
    }
34
0
}
35
36
void
37
Pl_RC4::finish()
38
0
{
39
0
    outbuf = nullptr;
40
0
    next()->finish();
41
0
}