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