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
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Status {
/// Indicates that the key is active and the primary key in the keyring. It
/// will be used, by default, for encryption.
///
/// The key will be used for decryption when aplicable (i.e. ciphertext
/// encrypted with it).
Primary,
/// Indicates that the key is active and can be used for cryptographic
/// purposes.
///
/// The key will be used for verification or decryption when applicable
/// but will not be used for signing or encryption.
Enabled,
/// A disabled key is not active and cannot be used for cryptographic purposes.
///
/// While disabled keys are present in the keyring, they are effectively deleted
/// but remain in a recoverable state.
Disabled,
}
impl Default for Status {
fn default() -> Self {
Self::Enabled
}
}
impl Status {
/// Returns `true` if `Primary`.
pub fn is_primary(&self) -> bool {
*self == Self::Primary
}
pub fn is_secondary(&self) -> bool {
*self == Self::Enabled
}
/// Returns `true` if the `Status` is `Primary` or `Secondary`.
pub fn is_enabled(&self) -> bool {
!self.is_disabled()
}
/// Returns `true` if `Disabled`.
pub fn is_disabled(&self) -> bool {
matches!(self, Self::Disabled)
}
}
impl From<Status> for i8 {
fn from(s: Status) -> Self {
s as i8
}
}