mk_pass/
helpers.rs

1/// The list of possible special characters used when generating a password.
2pub const SPECIAL_CHARACTERS: [char; 16] = [
3    '-', '.', '/', '\\', ':', '\'', '+', '&', ',', '@', '$', '!', '_', '#', '%', '~',
4];
5
6/// The list of possible decimal used when generating a password.
7pub const DECIMAL: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
8
9/// The list of possible uppercase letters used when generating a password.
10pub const UPPERCASE: [char; 26] = [
11    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
12    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
13];
14
15/// The list of possible lowercase letters used when generating a password.
16pub const LOWERCASE: [char; 26] = [
17    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
18    't', 'u', 'v', 'w', 'x', 'y', 'z',
19];
20
21#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
22pub enum CharKind {
23    Uppercase,
24    Lowercase,
25    Decimal,
26    Special,
27}
28
29impl CharKind {
30    pub fn into_sample(self) -> &'static [char] {
31        match self {
32            CharKind::Uppercase => &UPPERCASE,
33            CharKind::Lowercase => &LOWERCASE,
34            CharKind::Decimal => &DECIMAL,
35            CharKind::Special => &SPECIAL_CHARACTERS,
36        }
37    }
38
39    pub fn pop_kind(available: Vec<Self>, kind: &Self) -> Vec<Self> {
40        available
41            .iter()
42            .filter_map(|v| if *v == *kind { None } else { Some(*v) })
43            .collect::<Vec<CharKind>>()
44    }
45}
46
47#[derive(Debug, Default)]
48pub struct CountTypesUsed {
49    pub uppercase: u16,
50    pub lowercase: u16,
51    pub number: u16,
52    pub special: u16,
53}