Skip to content
Snippets Groups Projects
Commit f05a06d6 authored by Mathieu Valois's avatar Mathieu Valois
Browse files

more object-oriented code

parent 9387b23c
No related branches found
No related tags found
No related merge requests found
#ifndef THREAD_DATA_H
#define THREAD_DATA_H
#include <string>
#include <unordered_map>
#include <queue>
#include <climits>
#include <regex>
#include "Policy.h"
#include "SecurityRules.h"
typedef std::unordered_map<std::string, uint64_t> StringOccurrence;
typedef std::unordered_map<int, uint64_t> IntOccurrence;
/**
* @brief minimal number of digits of a password, etc.
*/
class minMax {
public:
void updateMinMax(const Policy& pol);
uint mindigit = UINT_MAX;
uint maxdigit = 0;
uint minlower = UINT_MAX;
uint maxlower = 0;
uint minupper = UINT_MAX;
uint maxupper = 0;
uint minspecial = UINT_MAX;
uint maxspecial = 0;
};
class ThreadData {
public:
ThreadData operator+(const ThreadData& other);
ThreadData operator+=(const ThreadData& other) const;
int thread_id;
std::string filename;
uint64_t lineBegin = 0;
uint64_t lineEnd = 0;
uint64_t total_counter = 0;
uint64_t total_filter = 0;
IntOccurrence length;
StringOccurrence simplemasks;
StringOccurrence advancedmasks;
StringOccurrence charactersets;
std::queue<std::string> password_queue;
minMax minMaxValue;
std::regex current_regex;
bool use_regex = false;
bool withcount = false;
uint limitSimplemask;
uint limitAdvancedmask;
SecurityRules sr;
bool finished = false;
};
#endif // THREAD_DATA_H
\ No newline at end of file
#include "ThreadData.h"
#include <iostream>
using namespace std;
void minMax::updateMinMax(const Policy& pol) {
mindigit = std::min(mindigit, pol.digit);
maxdigit = std::max(maxdigit, pol.digit);
minlower = std::min(minlower, pol.lower);
maxlower = std::max(maxlower, pol.lower);
minupper = std::min(minupper, pol.upper);
maxupper = std::max(maxupper, pol.upper);
minspecial = std::min(minspecial, pol.special);
maxspecial = std::max(maxspecial, pol.special);
}
ThreadData ThreadData::operator+=(const ThreadData& other) const{
return ThreadData(*this) + other;
}
ThreadData ThreadData::operator+(const ThreadData& other){
total_counter += other.total_counter;
total_filter += other.total_filter;
Policy min, max;
min.digit = other.minMaxValue.mindigit;
min.lower = other.minMaxValue.minlower;
min.upper = other.minMaxValue.minupper;
min.special = other.minMaxValue.minspecial;
max.digit = other.minMaxValue.maxdigit;
max.lower = other.minMaxValue.maxlower;
max.upper = other.minMaxValue.maxupper;
max.special = other.minMaxValue.maxspecial;
sr.nbSecurePassword += other.sr.nbSecurePassword;
minMaxValue.updateMinMax(min);
minMaxValue.updateMinMax(max);
for(std::pair<int, uint64_t> occ: other.length){
length[occ.first] += occ.second;
}
for(std::pair<std::string, int> occ : other.charactersets){
charactersets[occ.first] += occ.second;
}
for(std::pair<std::string, int> occ: other.simplemasks){
simplemasks[occ.first] += occ.second;
}
for(std::pair<std::string, int> occ: other.advancedmasks){
advancedmasks[occ.first] += occ.second;
}
return *this;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment