ssh_key/certificate/
field.rs1use 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 #[must_use]
55 pub fn as_str(self) -> &'static str {
56 match self {
57 Self::PublicKey => "public key",
58 Self::Nonce => "nonce",
59 Self::Serial => "serial",
60 Self::Type => "type",
61 Self::KeyId => "key id",
62 Self::ValidPrincipals => "valid principals",
63 Self::ValidAfter => "valid after",
64 Self::ValidBefore => "valid before",
65 Self::CriticalOptions => "critical options",
66 Self::Extensions => "extensions",
67 Self::SignatureKey => "signature key",
68 Self::Signature => "signature",
69 Self::Comment => "comment",
70 }
71 }
72
73 #[must_use]
75 pub fn invalid_error(self) -> Error {
76 Error::CertificateFieldInvalid(self)
77 }
78}
79
80impl AsRef<str> for Field {
81 fn as_ref(&self) -> &str {
82 self.as_str()
83 }
84}
85
86impl fmt::Display for Field {
87 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88 f.write_str(self.as_str())
89 }
90}