Coverage Report

Created: 2025-07-18 07:01

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