use crate::{CrackTarget, InternalCrackParameter};
#[derive(Debug)]
pub struct CrackResult {
target: String,
solution: Option<String>,
thread_count: usize,
combinations_total: usize,
combinations_p_t: usize,
duration_in_seconds: f64,
}
impl CrackResult {
fn new<T: CrackTarget>(
cp: InternalCrackParameter<T>,
duration_in_seconds: f64,
solution: Option<String>,
) -> Self {
let th = cp.crack_param().target_hash_and_hash_fnc();
let target_hash_as_str = th.hash_type_to_str_repr(th.target_hash());
Self {
target: target_hash_as_str,
solution,
thread_count: cp.thread_count(),
combinations_total: cp.combinations_total(),
combinations_p_t: cp.combinations_p_t(),
duration_in_seconds,
}
}
pub(crate) fn new_failure<T: CrackTarget>(
cp: InternalCrackParameter<T>,
seconds_as_fraction: f64,
) -> Self {
Self::new(cp, seconds_as_fraction, None)
}
pub(crate) fn new_success<T: CrackTarget>(
cp: InternalCrackParameter<T>,
seconds_as_fraction: f64,
solution: String,
) -> Self {
Self::new(cp, seconds_as_fraction, Some(solution))
}
pub const fn is_failure(&self) -> bool {
self.solution.is_none()
}
pub const fn is_success(&self) -> bool {
self.solution.is_some()
}
pub const fn solution(&self) -> &Option<String> {
&self.solution
}
pub const fn thread_count(&self) -> usize {
self.thread_count
}
pub const fn combinations_total(&self) -> usize {
self.combinations_total
}
pub const fn combinations_p_t(&self) -> usize {
self.combinations_p_t
}
pub const fn duration_in_seconds(&self) -> f64 {
self.duration_in_seconds
}
pub fn target(&self) -> &str {
&self.target
}
}