pub struct Engine { /* private fields */ }Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new() -> Engine
pub fn new() -> Engine
Create a new engine
Create a new engine, using default values, and no scores or vulnerabilities.
Sourcepub fn add_file_vuln<F, S>(&mut self, name: S, f: F)
pub fn add_file_vuln<F, S>(&mut self, name: S, f: F)
Register a file vulnerability
Register a file vulnerability.
This takes the form of a function/closure that takes an &mut Engine, and a Option<&mut File>, 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
Sourcepub fn add_app_vuln<F, S>(
&mut self,
name: S,
install_method: InstallMethod,
f: F,
)
pub fn add_app_vuln<F, S>( &mut self, name: S, install_method: InstallMethod, f: F, )
Register a package/app vulnerability
Register a package/app vulnerability.
This takes the form of a function/closure that takes an &mut Engine, and an AppData, 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
Sourcepub fn add_user_vuln<F, S>(&mut self, name: S, f: F)
pub fn add_user_vuln<F, S>(&mut self, name: S, f: F)
Register a user vulnerability
Register a user vulnerability.
This takes the form of a function/closure that takes a &mut Engine, and a str, 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
Sourcepub fn add_misc_vuln<F>(&mut self, f: F)
pub fn add_misc_vuln<F>(&mut self, f: F)
Register a miscellaneous vulnerability
Register a miscellaneous vulnerability.
This takes the form of a function/closure that takes only a &mut Engine, 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
Sourcepub fn add_hook<F, T>(&mut self, f: F)
pub fn add_hook<F, T>(&mut self, f: F)
Register a hook vulnerability
Register a hook vulnerability, which takes the form of a closure that takes a &mut Engine as it’s only parameter.
In reality this registers a miscellaneous vulnerability (see Engine::add_misc_vuln).
This miscellaneous vulnerability is literally just a call to the hook that discards it’s return, and returns false.
Sourcepub fn set_freq(&mut self, frequency: u64)
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
Sourcepub fn set_completed_freq(&mut self, frequency: u64)
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
Sourcepub fn add_score(&mut self, id: u64, add: i32, reason: String)
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
Sourcepub fn generate_score_report(&mut self) -> Vec<(String, i32)>
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
Sourcepub fn update(&mut self)
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
Sourcepub fn enter(&mut self)
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.
Sourcepub fn stop(&mut self, blocking: bool)
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.
Sourcepub fn calc_total_score(&self) -> i32
pub fn calc_total_score(&self) -> i32
Calculate a total score
Calculate the total score for the current engine.
Sourcepub fn get_entry(&self, id: u64) -> Option<(u64, i32, String)>
pub fn get_entry(&self, id: u64) -> Option<(u64, i32, String)>
Get the entry identified by id, if it exists.
Sourcepub fn entry_exists(&self, id: u64) -> bool
pub fn entry_exists(&self, id: u64) -> bool
Checks if the entry identified by id exists