Coverage Report

Created: 2025-10-10 06:17

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