mirror of
https://github.com/elwrcl/pasx.git
synced 2026-10-31 19:08:04 +03:00
init
This commit is contained in:
22 files changed
+11922
No files matched your search
@@ -0,0 +1,42 @@
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod charset;
|
||||
pub mod entropy;
|
||||
pub mod passphrase;
|
||||
|
||||
pub const MIN_LENGTH: usize = 4;
|
||||
pub const MAX_LENGTH: usize = 128;
|
||||
pub const MIN_WORDS: usize = 3;
|
||||
pub const MAX_WORDS: usize = 12;
|
||||
pub const RETRY_LIMIT: usize = 1000;
|
||||
|
||||
#[derive(Debug, Error, PartialEq, Eq)]
|
||||
pub enum GenError {
|
||||
#[error("length {got} is out of range {min}..={max}")]
|
||||
InvalidLength { got: usize, min: usize, max: usize },
|
||||
#[error("at least one character class must be enabled")]
|
||||
NoCharacterClass,
|
||||
#[error("word count {got} is out of range {min}..={max}")]
|
||||
InvalidWordCount { got: usize, min: usize, max: usize },
|
||||
#[error("could not satisfy character class constraints after {0} attempts")]
|
||||
RetryLimitExceeded(usize),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn errors_render_readable_messages() {
|
||||
let err = GenError::InvalidLength {
|
||||
got: 2,
|
||||
min: MIN_LENGTH,
|
||||
max: MAX_LENGTH,
|
||||
};
|
||||
assert_eq!(err.to_string(), "length 2 is out of range 4..=128");
|
||||
assert_eq!(
|
||||
GenError::NoCharacterClass.to_string(),
|
||||
"at least one character class must be enabled"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user