Struct cypat::Engine

source ·
pub struct Engine { /* private fields */ }

Implementations§

source§

impl Engine

source

pub fn new() -> Engine

Create a new engine

Create a new engine, using default values, and no scores or vulnerabilities.

source

pub fn add_file_vuln<F, S>(&mut self, name: S, f: F)
where F: FnMut(Option<&mut File>) -> bool + Send + Sync + 'static, S: ToString,

Register a file vulnerability

Register a file vulnerability. This takes the form of a function/closure that takes an Option<&mut File> as it’s only parameter, and returns a bool.

If the closure returns true, the vulnerability is interpreted as being completed, it is incomplete. More on that in Engine::update and Engine::enter

source

pub fn add_app_vuln<F, S>( &mut self, name: S, install_method: InstallMethod, f: F )
where F: FnMut(AppData) -> bool + Send + Sync + 'static, S: ToString,

Register a package/app vulnerability

Register a package/app vulnerability. This takes the form of a function/closure that takes an AppData as it’s only parameter, and returns a bool.

If the closure returns true, the vulnerability is interpreted as being completed, it is incomplete. More on that in Engine::update and Engine::enter

source

pub fn add_user_vuln<F, S>(&mut self, name: S, f: F)
where F: FnMut(&str) -> bool + Send + Sync + 'static, S: ToString,

Register a user vulnerability

Register a user vulnerability. This takes the form of a function/closure that takes an str as it’s only parameter, and returns a bool.

If the closure returns true, the vulnerability is interpreted as being completed, it is incomplete. More on that in Engine::update and Engine::enter

source

pub fn add_misc_vuln<F>(&mut self, f: F)
where F: FnMut(()) -> bool + Send + Sync + 'static,

Register a miscellaneous vulnerability

Register a miscellaneous vulnerability. This takes the form of a function/closure that takes no parameters, and returns a bool.

If the closure returns true, the vulnerability is interpreted as being completed, it is incomplete. More on that in Engine::update and Engine::enter

source

pub fn set_freq(&mut self, frequency: u64)

Sets the frequency in seconds at which the engine is updated.

Sets the frequency in seconds at which Engine::update is called, if using Engine::enter.

This is handled as a private variable called incomplete_freq

source

pub fn set_completed_freq(&mut self, frequency: u64)

Sets the frequency in iterations of engine updates that completed vulnerabilities are reviewed.

Sets the frequency in iterations of engine updates that completed vulnerabilities are re-executed. This value is important even if you don’t use Engine::enter because of the way it is interpreted by Engine::update

Internally this is handled as a variable called complete_freq

source

pub fn add_score(&mut self, id: u64, add: i32, reason: String)

Adds an entry to the score report, with an ID, a score value, and an explanation

Adds an entry to the score report, with an ID, a score value, and an explanation. If an entry exists with the same ID, it instead changes the score and explanation

source

pub fn remove_score(&mut self, id: u64) -> Result<(), ()>

Removes the entry identified

source

pub fn generate_score_report(&mut self) -> Vec<(String, i32)>

Generates a list of score entries Generates a vector containing the explanation and value of each score entry in order

source

pub fn update(&mut self)

Executes vulnerabilites

Incomplete vulnerabilites are excuted each time the function is executed. Complete vulnerabilites are excuted only if the number of iterations mod complete_freq is 0

source

pub fn enter(&mut self)

Start engine execution on this thread

This enters an loop that calls Engine::update incomplete_freq times per second.

This state of execution only takes control of one thread, and other threads can generally continue without issue, however, new vulnerabilities cannot be added.

source

pub fn stop(&mut self, blocking: bool)

Tells the engine to exit.

This stops engine execution if Engine::enter was called. Otherwise does nothing, unless if blocking is set to true. If blocking is set, it will wait until the current running update stops to return.

source

pub fn calc_total_score(&self) -> i32

Calculate a total score

Calculate the total score for the current engine.

source

pub fn get_entry(&self, id: u64) -> Option<(u64, i32, String)>

Get the entry identified by id, if it exists.

source

pub fn entry_exists(&self, id: u64) -> bool

Checks if the entry identified by id exists

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>,

§

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>,

§

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.