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