crab_gnupg/utils/
enums.rs

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
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, PartialEq)]
pub enum Operation {
    NotSet,
    Verify, // this means verify if gpg was installed and is working, gpg operation verify file was under another naming
    GenerateKey,
    ListKey,
    DeleteKey,
    SearchKey,
    ImportKey,
    TrustKey,
    SignKey,
    ExportPublicKey,
    ExportSecretKey,
    Encrypt,
    Decrypt,
    Sign,
    VerifyFile,
}

#[doc(hidden)]
impl Display for Operation {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Operation::NotSet => write!(f, "NotSet"),
            Operation::Verify => write!(f, "Verify"),
            Operation::GenerateKey => write!(f, "GenerateKey"),
            Operation::ListKey => write!(f, "ListKey"),
            Operation::DeleteKey => write!(f, "DeleteKey"),
            Operation::SearchKey => write!(f, "SearchKey"),
            Operation::ImportKey => write!(f, "ImportKey"),
            Operation::TrustKey => write!(f, "TrustKey"),
            Operation::SignKey => write!(f, "SignKey"),
            Operation::ExportPublicKey => write!(f, "ExportPublicKey"),
            Operation::ExportSecretKey => write!(f, "ExportSecretKey"),
            Operation::Encrypt => write!(f, "Encrypt"),
            Operation::Decrypt => write!(f, "Decrypt"),
            Operation::Sign => write!(f, "Sign"),
            Operation::VerifyFile => write!(f, "VerifyFile"),
        }
    }
}

#[derive(Debug, Clone)]
pub enum TrustLevel {
    Expired,
    Undefined,
    Never,
    Marginal,
    Fully,
    Ultimate,
}

#[doc(hidden)]
impl TrustLevel {
    pub fn value(&self) -> u8 {
        match &self {
            TrustLevel::Expired => 1,
            TrustLevel::Undefined => 2,
            TrustLevel::Never => 3,
            TrustLevel::Marginal => 4,
            TrustLevel::Fully => 5,
            TrustLevel::Ultimate => 6,
        }
    }
}

#[derive(Debug, Clone)]
pub enum DeleteProblem{
    NoKey = 1,
    SecretFirst = 2,
    AmbiguousSpecification = 3,
    KeyOnSmartCard = 4
}
#[doc(hidden)]
impl DeleteProblem {
    pub fn from_str(value: &str) -> String {
        match value {
            "1" => String::from("No Such Key"),
            "2" => String::from("Must delete secret key first"),
            "3" => String::from("Ambiguous specification"),
            "4" => String::from("Key is stored on a smartcard."),
            _ => format!("Unknown error: {}", value),  
        }
    }
}