ssh_key/certificate/
cert_type.rs1use crate::{Error, Result};
4use encoding::{Decode, Decoder, Encode, Reader};
5
6#[derive(Copy, Clone, Debug, Encode, Eq, Hash, PartialEq, PartialOrd, Ord)]
8#[repr(u32)]
9#[derive(Default)]
10pub enum CertType {
11 #[default]
13 User = 1,
14
15 Host = 2,
17}
18
19impl CertType {
20 #[must_use]
22 pub fn is_host(self) -> bool {
23 self == CertType::Host
24 }
25
26 #[must_use]
28 pub fn is_user(self) -> bool {
29 self == CertType::User
30 }
31}
32
33impl Decode for CertType {
34 type Error = Error;
35
36 fn decode(reader: &mut Decoder<impl Reader>) -> Result<Self> {
37 u32::decode(reader)?.try_into()
38 }
39}
40
41impl From<CertType> for u32 {
42 #[allow(clippy::as_conversions, reason = "repr(u32) enum")]
43 fn from(cert_type: CertType) -> u32 {
44 cert_type as u32
45 }
46}
47
48impl TryFrom<u32> for CertType {
49 type Error = Error;
50
51 fn try_from(n: u32) -> Result<CertType> {
52 match n {
53 1 => Ok(CertType::User),
54 2 => Ok(CertType::Host),
55 _ => Err(Error::FormatEncoding),
56 }
57 }
58}