bkcrack 1.7.1
Crack legacy zip encryption with Biham and Kocher's known plaintext attack.
Progress.hpp
1#ifndef BKCRACK_PROGRESS_HPP
2#define BKCRACK_PROGRESS_HPP
3
4#include <atomic>
5#include <iostream>
6#include <mutex>
7
10{
11public:
13 enum class State
14 {
18 };
19
21 explicit Progress(std::ostream& os);
22
25 template <typename F>
26 void log(F f)
27 {
28 const auto lock = std::scoped_lock{m_os_mutex};
29 f(m_os);
30 }
31
32 std::atomic<State> state = State::Normal;
33 std::atomic<int> done = 0;
34 std::atomic<int> total = 0;
35
36private:
37 std::mutex m_os_mutex;
38 std::ostream& m_os;
39};
40
41#endif // BKCRACK_PROGRESS_HPP
std::atomic< int > done
Number of steps already done.
Definition Progress.hpp:33
std::atomic< State > state
State of the long operation.
Definition Progress.hpp:32
void log(F f)
Definition Progress.hpp:26
std::atomic< int > total
Total number of steps.
Definition Progress.hpp:34
State
Possible states of a long operation.
Definition Progress.hpp:14
@ Canceled
The operation has been canceled externally.
Definition Progress.hpp:16
@ EarlyExit
The operation stopped after a partial result was found.
Definition Progress.hpp:17
@ Normal
The operation is ongoing or is fully completed.
Definition Progress.hpp:15
Progress(std::ostream &os)
Constructor.