Skip to content
API Documentation
BastionGuard™
LeakCheckWorker.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 "LeakCheckWorker.hpp"
22
27#include "utils/HashUtil.hpp"
29#include <glib/gi18n.h>
30#include <memory>
31
33 const std::string& e,
34 LogFn logger)
35: email(e),
36 log(std::move(logger))
37{
38}
39
41{
42 log(_("Normalizzazione identità…"));
43
44
45 const std::string emailHash =
47
48 LeakDatabase db;
49 db.ensureIdentity(emailHash);
50
51 LeakAggregator aggregator;
52
53 const std::string hibpApiKey =
55
56 const bool hibpEnabled = !hibpApiKey.empty();
57
58 if (hibpEnabled) {
59 aggregator.addProvider(
60 std::make_unique<HibpProvider>(hibpApiKey));
61 log(_("Fonte attiva: HIBP (copertura completa)"));
62 } else {
63 log(_("⚠ HIBP non configurato"));
64 log(_(" Uso LeakCheck (copertura limitata)"));
65 }
66
67 aggregator.addProvider(
68 std::make_unique<LeakCheckProvider>());
69
70
71 std::vector<LeakRecord> results;
72
73 try {
74 results = aggregator.queryAll(email);
75 }
76 catch (const std::exception& ex) {
77 log(std::string(_("❌ Errore durante la verifica: ")) + ex.what());
78 return;
79 }
80
81 if (results.empty()) {
82 log(_("✔ Nessuna violazione rilevata."));
83 return;
84 }
85
86}
#define _(s)
static std::string sha256(const std::string &input)
Definition HashUtil.cpp:27
static std::string hibpApiKey()
void addProvider(std::unique_ptr< ILeakProvider > provider)
std::vector< LeakRecord > queryAll(const std::string &email)
std::function< void(const std::string &)> LogFn
LeakCheckWorker(const std::string &email, LogFn logger)
void ensureIdentity(const std::string &emailHash)