File Scanner 1.0.0
A high-performance C++ malicious file scanner.
Loading...
Searching...
No Matches
scanner::CsvHashDatabase Class Referencefinal

An implementation of IHashDatabase that loads signatures from a CSV file. More...

#include <csv_hash_database.h>

Inheritance diagram for scanner::CsvHashDatabase:
Inheritance graph
Collaboration diagram for scanner::CsvHashDatabase:
Collaboration graph

Public Member Functions

std::size_t Load (const std::filesystem::path &source_path) override
 Loads malicious signatures from a specified CSV file.
 
std::optional< std::string > FindHash (const std::string &hash) const override
 Looks up a hash in the loaded database.
 
- Public Member Functions inherited from scanner::IHashDatabase
virtual ~IHashDatabase ()=default
 

Private Attributes

std::unordered_map< std::string, std::string > signatures_
 

Detailed Description

An implementation of IHashDatabase that loads signatures from a CSV file.

This class parses a semicolon-separated CSV file where each line contains a hash and its corresponding verdict. It stores these signatures in an unordered_map for efficient lookups. This class is an internal, non-exported component of the scanner library.

Member Function Documentation

◆ FindHash()

std::optional< std::string > scanner::CsvHashDatabase::FindHash ( const std::string &  hash) const
overridevirtual

Looks up a hash in the loaded database.

Parameters
hashThe hash string to look up.
Returns
An optional containing the verdict if the hash is found, otherwise std::nullopt.

Implements scanner::IHashDatabase.

◆ Load()

std::size_t scanner::CsvHashDatabase::Load ( const std::filesystem::path &  source_path)
overridevirtual

Loads malicious signatures from a specified CSV file.

Clears any existing data and reads the file line by line. Malformed lines are skipped, and a warning is printed to stderr.

Parameters
source_pathThe path to the CSV database file.
Returns
The total number of signatures successfully loaded.
Exceptions
std::runtime_errorif the file cannot be opened.

Implements scanner::IHashDatabase.

Member Data Documentation

◆ signatures_

std::unordered_map<std::string, std::string> scanner::CsvHashDatabase::signatures_
private

The documentation for this class was generated from the following files: