Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

Engine used for scanning files

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Initialises the engine

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for Engine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Engine

Source§

impl Sync for Engine

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.