Coverage Report

Created: 2025-07-14 06:16

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