ssh_key/certificate/
field.rs
1use crate::Error;
4use core::fmt;
5
6#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
11pub enum Field {
12 PublicKey,
14
15 Nonce,
17
18 Serial,
20
21 Type,
23
24 KeyId,
26
27 ValidPrincipals,
29
30 ValidAfter,
32
33 ValidBefore,
35
36 CriticalOptions,
38
39 Extensions,
41
42 SignatureKey,
44
45 Signature,
47
48 Comment,
50}
51
52impl Field {
53 pub fn as_str(self) -> &'static str {
55 match self {
56 Self::PublicKey => "public key",
57 Self::Nonce => "nonce",
58 Self::Serial => "serial",
59 Self::Type => "type",
60 Self::KeyId => "key id",
61 Self::ValidPrincipals => "valid principals",
62 Self::ValidAfter => "valid after",
63 Self::ValidBefore => "valid before",
64 Self::CriticalOptions => "critical options",
65 Self::Extensions => "extensions",
66 Self::SignatureKey => "signature key",
67 Self::Signature => "signature",
68 Self::Comment => "comment",
69 }
70 }
71
72 pub fn invalid_error(self) -> Error {
74 Error::CertificateFieldInvalid(self)
75 }
76}
77
78impl AsRef<str> for Field {
79 fn as_ref(&self) -> &str {
80 self.as_str()
81 }
82}
83
84impl fmt::Display for Field {
85 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86 f.write_str(self.as_str())
87 }
88}