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

Simplify merging

parent a7c9c31b
No related branches found
No related tags found
No related merge requests found
Pipeline #6301 failed
......@@ -4,6 +4,7 @@
#include <string>
#include <map>
#include "ThreadData.h"
#include "SecurityRules.h"
class Policy {
......@@ -13,6 +14,7 @@ public:
uint upper = 0;
uint special = 0;
operator std::string() const;
operator minMax() const;
static std::map<uint, std::string> charsetNames() {
std::map<uint, std::string> names;
names[1] = "numeric";
......
......@@ -7,7 +7,6 @@
#include <climits>
#include <regex>
#include "Policy.h"
#include "SecurityRules.h"
typedef std::unordered_map<std::string, uint64_t> StringOccurrence;
......@@ -16,9 +15,8 @@ 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);
struct minMax {
void updateMinMax(const minMax &m);
uint mindigit = UINT_MAX;
uint maxdigit = 0;
uint minlower = UINT_MAX;
......@@ -29,9 +27,8 @@ public:
uint maxspecial = 0;
};
class ThreadData {
public:
ThreadData operator+(const ThreadData& other);
struct ThreadData {
ThreadData operator+(const ThreadData& other) const;
void operator+=(const ThreadData& other);
int thread_id;
std::string filename;
......
......@@ -16,6 +16,15 @@ Policy::operator string() const {
return it->second;
}
Policy::operator minMax() const {
minMax m;
m.maxlower = lower;
m.maxupper = upper;
m.maxdigit = digit;
m.maxspecial = special;
return m;
}
bool Policy::satisfies(const SecurityRules& sr, const uint& pwd_size) const {
return pwd_size >= sr.minLength
&& digit >= sr.minDigit
......
......@@ -4,41 +4,29 @@
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);
void minMax::updateMinMax(const minMax &m){
mindigit = std::min(mindigit, m.mindigit);
minlower = std::min(minlower, m.minlower);
minupper = std::min(minupper, m.minupper);
minspecial = std::min(minspecial, m.minspecial);
maxdigit = std::max(maxdigit, m.maxdigit);
maxlower = std::max(maxlower, m.maxlower);
maxupper = std::max(maxupper, m.maxupper);
maxspecial = std::max(maxspecial, m.maxspecial);
}
void ThreadData::operator+=(const ThreadData& other){
*this = *this + other;
}
ThreadData ThreadData::operator+(const ThreadData& other){
ThreadData ThreadData::operator+(const ThreadData& other) const {
ThreadData td(*this);
td.total_counter = total_counter + other.total_counter;
td.total_filter = 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;
td.sr.nbSecurePassword += other.sr.nbSecurePassword;
td.minMaxValue.updateMinMax(min);
td.minMaxValue.updateMinMax(max);
td.minMaxValue.updateMinMax(other.minMaxValue);
for(std::pair<int, uint64_t> occ: other.length){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment