passforge/strength_evaluator.rs
1//! This module defines the interface for password strength evaluation.
2//!
3//! It provides a `StrengthEvaluator` trait that can be implemented by different
4//! strength evaluation algorithms, allowing for flexible and extensible password
5//! strength checking.
6
7use std::fmt::Display;
8
9use crate::PassForgeError;
10
11/// The `StrengthEvaluator` trait defines the interface for password strength evaluation.
12///
13/// This trait allows for a common interface across different types of strength evaluators,
14/// enabling easy swapping and extension of evaluation algorithms.
15pub trait StrengthEvaluator {
16 /// The input type for the strength evaluator.
17 type Input;
18 /// The output type produced by the strength evaluator, which must implement `Display`.
19 type Output: Display;
20
21 /// Checks if the input passes a predefined strength threshold.
22 ///
23 /// # Arguments
24 ///
25 /// * `input` - A reference to the input to evaluate.
26 ///
27 /// # Returns
28 ///
29 /// Returns a `Result` containing a boolean indicating whether the input passes the threshold,
30 /// or a `PassForgeError` if an error occurred during evaluation.
31 fn passes_threshold(input: &Self::Input) -> Result<bool, PassForgeError>;
32
33 /// Evaluates the strength of the input.
34 ///
35 /// # Arguments
36 ///
37 /// * `input` - A reference to the input to evaluate.
38 ///
39 /// # Returns
40 ///
41 /// Returns a `Result` containing the strength evaluation output if successful,
42 /// or a `PassForgeError` if an error occurred during evaluation.
43 fn evaluate(input: &Self::Input) -> Result<Self::Output, PassForgeError>;
44}
45
46pub mod zxcvbn_analysis;
47
48pub use zxcvbn_analysis::ZxcvbnAnalysis;