Home

rs-spectre @7af11f5d802df29de967361bd7cd5e89d641af3c - refs - log -
-
https://git.jolheiser.com/rs-spectre.git
Rust implementation for Spectre/Masterpassword
rs-spectre / spectre / src / template.rs
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#[derive(Debug)]
pub enum Template {
    Maximum,
    Long,
    Medium,
    Short,
    Pin,
    Name,
    Phrase,
    Basic,
}

#[derive(Debug)]
pub enum ParseTemplateError {
    Invalid,
}

impl std::str::FromStr for Template {
    type Err = ParseTemplateError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_uppercase().as_str() {
            "MAXIMUM" => Ok(Self::Maximum),
            "LONG" => Ok(Self::Long),
            "MEDIUM" => Ok(Self::Medium),
            "SHORT" => Ok(Self::Short),
            "PIN" => Ok(Self::Pin),
            "NAME" => Ok(Self::Name),
            "PHRASE" => Ok(Self::Phrase),
            "BASIC" => Ok(Self::Basic),
            _ => Err(ParseTemplateError::Invalid),
        }
    }
}

pub(crate) fn templates(t: Template) -> Vec<String> {
    match t {
        Template::Maximum => vec![
            "anoxxxxxxxxxxxxxxxxx".to_string(),
            "axxxxxxxxxxxxxxxxxno".to_string(),
        ],
        Template::Long => vec![
            "CvcvnoCvcvCvcv".to_string(),
            "CvcvCvcvnoCvcv".to_string(),
            "CvcvCvcvCvcvno".to_string(),
            "CvccnoCvcvCvcv".to_string(),
            "CvccCvcvnoCvcv".to_string(),
            "CvccCvcvCvcvno".to_string(),
            "CvcvnoCvccCvcv".to_string(),
            "CvcvCvccnoCvcv".to_string(),
            "CvcvCvccCvcvno".to_string(),
            "CvcvnoCvcvCvcc".to_string(),
            "CvcvCvcvnoCvcc".to_string(),
            "CvcvCvcvCvccno".to_string(),
            "CvccnoCvccCvcv".to_string(),
            "CvccCvccnoCvcv".to_string(),
            "CvccCvccCvcvno".to_string(),
            "CvcvnoCvccCvcc".to_string(),
            "CvcvCvccnoCvcc".to_string(),
            "CvcvCvccCvccno".to_string(),
            "CvccnoCvcvCvcc".to_string(),
            "CvccCvcvnoCvcc".to_string(),
            "CvccCvcvCvccno".to_string(),
        ],
        Template::Medium => vec!["CvcnoCvc".to_string(), "CvcCvcno".to_string()],
        Template::Short => vec!["Cvcn".to_string()],
        Template::Pin => vec!["nnnn".to_string()],
        Template::Name => vec!["cvccvcvcv".to_string()],
        Template::Phrase => vec![
            "cvcc cvc cvccvcv cvc".to_string(),
            "cvc cvccvcvcv cvcv".to_string(),
            "cv cvccv cvc cvcvccv".to_string(),
        ],
        Template::Basic => vec![
            "aaanaaan".to_string(),
            "aannaaan".to_string(),
            "aaannaaa".to_string(),
        ],
    }
}

pub(crate) fn chars(u: &u8) -> &str {
    match *u as char {
        'V' => "AEIOU",
        'C' => "BCDFGHJKLMNPQRSTVWXYZ",
        'v' => "aeiou",
        'c' => "bcdfghjklmnpqrstvwxyz",
        'A' => "AEIOUBCDFGHJKLMNPQRSTVWXYZ",
        'a' => "AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz",
        'n' => "0123456789",
        'o' => "@&%?,=[]_:-+*$#!'^~;()/.",
        'x' => "AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz0123456789!@#$%^&*()",
        ' ' => " ",
        _ => panic!("unexpected character"),
    }
}