Coverage Report

Created: 2025-08-03 06:15

/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
1.31k
    Pipeline(identifier, next),
7
1.31k
    out_bufsize(out_bufsize),
8
1.31k
    rc4(reinterpret_cast<unsigned char const*>(key.data()), static_cast<int>(key.size()))
9
1.31k
{
10
1.31k
    if (!next) {
11
0
        throw std::logic_error("Attempt to create Pl_RC4 with nullptr as next");
12
0
    }
13
1.31k
    this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize);
14
1.31k
}
15
16
void
17
Pl_RC4::write(unsigned char const* data, size_t len)
18
1.31k
{
19
1.31k
    if (this->outbuf == nullptr) {
20
0
        throw std::logic_error(this->identifier + ": Pl_RC4: write() called after finish() called");
21
0
    }
22
23
1.31k
    size_t bytes_left = len;
24
1.31k
    unsigned char const* p = data;
25
26
2.64k
    while (bytes_left > 0) {
27
1.33k
        size_t bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
28
1.33k
        bytes_left -= bytes;
29
        // lgtm[cpp/weak-cryptographic-algorithm]
30
1.33k
        rc4.process(p, bytes, outbuf.get());
31
1.33k
        p += bytes;
32
1.33k
        next()->write(outbuf.get(), bytes);
33
1.33k
    }
34
1.31k
}
35
36
void
37
Pl_RC4::finish()
38
1.31k
{
39
1.31k
    outbuf = nullptr;
40
1.31k
    next()->finish();
41
1.31k
}