Skip to content
API Documentation
BastionGuard™
LeakNormalizer.cpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#include "LeakNormalizer.hpp"
22
23#include <algorithm>
24
29{
30 return (static_cast<int>(a) > static_cast<int>(b)) ? a : b;
31}
32
33std::vector<LeakRecord>
34LeakNormalizer::normalize(const std::vector<LeakRecord>& input)
35{
36 std::vector<LeakRecord> out;
37
38 for (const auto& rec : input) {
39 auto it = std::find_if(
40 out.begin(), out.end(),
41 [&](const LeakRecord& r) {
42 return r.breachName == rec.breachName;
43 });
44
45 if (it == out.end()) {
46 out.push_back(rec);
47 } else {
48 it->severity = maxSeverity(it->severity, rec.severity);
49
50 it->dataClasses.insert(
51 it->dataClasses.end(),
52 rec.dataClasses.begin(),
53 rec.dataClasses.end()
54 );
55 }
56 }
57
58 return out;
59}
static LeakRecord::Severity maxSeverity(LeakRecord::Severity a, LeakRecord::Severity b)
static std::vector< LeakRecord > normalize(const std::vector< LeakRecord > &input)