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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#![allow(clippy::should_implement_trait)]

#[derive(PartialEq)]
pub enum EncryptionAlg {
    AesGcm,
    ChaCha20Poly1305,
}

impl EncryptionAlg {
    pub fn value(&self) -> u8 {
        match *self {
            EncryptionAlg::AesGcm => 1,
            EncryptionAlg::ChaCha20Poly1305 => 2,
        }
    }

    pub fn from_str(input: &str) -> EncryptionAlg {
        match input {
            "aes-gcm" => EncryptionAlg::AesGcm,
            "chacha20-poly1305" => EncryptionAlg::ChaCha20Poly1305,
            _ => EncryptionAlg::AesGcm,
        }
    }

    pub fn from_u8(input: u8) -> EncryptionAlg {
        match input {
            1 => EncryptionAlg::AesGcm,
            2 => EncryptionAlg::ChaCha20Poly1305,
            _ => EncryptionAlg::AesGcm,
        }
    }

    pub fn to_str(&self) -> &str {
        match *self {
            EncryptionAlg::AesGcm => "aes-gcm",
            EncryptionAlg::ChaCha20Poly1305 => "chacha20-poly1305",
        }
    }
}

#[derive(PartialEq)]
pub enum HashAlg {
    Sha256,
}

impl HashAlg {
    pub fn value(&self) -> u8 {
        match *self {
            HashAlg::Sha256 => 1,
        }
    }

    pub fn from_str(input: &str) -> HashAlg {
        match input {
            "sha-256" => HashAlg::Sha256,
            _ => HashAlg::Sha256,
        }
    }

    pub fn from_u8(input: u8) -> HashAlg {
        match input {
            1 => HashAlg::Sha256,
            _ => HashAlg::Sha256,
        }
    }

    pub fn to_str(&self) -> &str {
        match *self {
            HashAlg::Sha256 => "sha-256",
        }
    }
}

#[derive(PartialEq)]
pub enum KdfAlg {
    Argon2d,
    Argon2id,
}

impl KdfAlg {
    pub fn value(&self) -> u8 {
        match *self {
            KdfAlg::Argon2d => 1,
            KdfAlg::Argon2id => 2,
        }
    }

    pub fn from_u8(input: u8) -> KdfAlg {
        match input {
            1 => KdfAlg::Argon2d,
            2 => KdfAlg::Argon2id,
            _ => KdfAlg::Argon2d,
        }
    }

    pub fn from_str(input: &str) -> KdfAlg {
        match input {
            "argon2d" => KdfAlg::Argon2d,
            "argon2id" => KdfAlg::Argon2id,
            _ => KdfAlg::Argon2d,
        }
    }

    pub fn to_str(&self) -> &str {
        match *self {
            KdfAlg::Argon2d => "argon2d",
            KdfAlg::Argon2id => "argon2id",
        }
    }
}

#[derive(PartialEq)]
pub enum CompressionAlg {
    None,
    Gzip,
}

impl CompressionAlg {
    pub fn value(&self) -> u8 {
        match *self {
            CompressionAlg::None => 0,
            CompressionAlg::Gzip => 1,
        }
    }

    pub fn from_bool(input: bool) -> CompressionAlg {
        match input {
            true => CompressionAlg::Gzip,
            false => CompressionAlg::None,
        }
    }

    pub fn from_u8(input: u8) -> CompressionAlg {
        match input {
            0 => CompressionAlg::None,
            1 => CompressionAlg::Gzip,
            _ => CompressionAlg::Gzip,
        }
    }

    pub fn to_bool(&self) -> bool {
        match *self {
            CompressionAlg::Gzip => true,
            CompressionAlg::None => false,
        }
    }
}