pub struct Engine { /* private fields */ }Expand description
Engine used for scanning files
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn compile(&self) -> Result<(), ClamError>
pub fn compile(&self) -> Result<(), ClamError>
Compiles the loaded database definitions
This function will compile the database definitions loaded
in this engine using the [load_database] function.
§Examples
use clamav::{engine};
clamav::initialize().expect("failed to initialize");
let scanner = engine::Engine::new();
scanner.compile().expect("failed to compile");§Errors
This function will return an error if compliation fails.
The ClamError returned will contain the error code.
Sourcepub fn load_databases(
&self,
database_directory_path: &str,
) -> Result<DatabaseStats, ClamError>
pub fn load_databases( &self, database_directory_path: &str, ) -> Result<DatabaseStats, ClamError>
Loads all of the definition databases (*.{cud, cvd}) in the specified directory.
This function will load the definitions that can then be compiled with [compile].
§Examples
use clamav::{engine};
clamav::initialize().expect("failed to initialize");
let scanner = engine::Engine::new();
scanner.load_databases("test_data/database/").expect("failed to load");
scanner.compile().expect("failed to compile");§Errors
This function will return an error if compliation fails.
The ClamError returned will contain the error code.
Sourcepub fn scan_file(
&self,
path: &str,
settings: &ScanSettings,
) -> Result<ScanResult, ClamError>
pub fn scan_file( &self, path: &str, settings: &ScanSettings, ) -> Result<ScanResult, ClamError>
Scans a file with the previously loaded and compiled definitions.
This function will scan the given file with the the database definitions loaded and compiled.
§Examples
use clamav::{engine, engine::ScanResult, scan_settings::ScanSettings};
clamav::initialize().expect("failed to initialize");
let scanner = engine::Engine::new();
scanner.load_databases("test_data/database/").expect("failed to load");
scanner.compile().expect("failed to compile");
let settings: ScanSettings = Default::default();
let hit = scanner.scan_file("test_data/files/good_file", &settings).expect("expected scan to succeed");
match hit {
ScanResult::Virus(name) => println!("Virus {}", name),
ScanResult::Clean => println!("Clean"),
ScanResult::Whitelisted => println!("Whitelisted file")
}use clamav::{engine, engine::ScanResult, scan_settings::ScanSettingsBuilder};
clamav::initialize().expect("failed to initialize");
let scanner = engine::Engine::new();
scanner.load_databases("test_data/database/").expect("failed to load");
scanner.compile().expect("failed to compile");
let settings = ScanSettingsBuilder::new()
.enable_pdf()
.block_broken_executables()
.build();
println!("Using settings {}", settings);
let hit = scanner.scan_file("test_data/files/good_file", &settings).expect("expected scan to succeed");
match hit {
ScanResult::Virus(name) => println!("Virus {}", name),
ScanResult::Clean => println!("Clean"),
ScanResult::Whitelisted => println!("Whitelisted file")
}§Errors
This function will return an error if the scan fails.
The ClamError returned will contain the error code.
Sourcepub fn scan_descriptor(
&self,
descriptor: i32,
settings: &ScanSettings,
) -> Result<ScanResult, ClamError>
pub fn scan_descriptor( &self, descriptor: i32, settings: &ScanSettings, ) -> Result<ScanResult, ClamError>
Scans a descriptor with the previously loaded and compiled definitions.
This function will scan the given descriptor with the the database definitions loaded and compiled.