This commit is contained in:
elwrcl committed 2026-09-26 17:09:38 +03:00
commit 6df73cc246
22 files changed
+11922

No files matched your search

+42
View File
@@ -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"
);
}
}