Skip to main content

cerbero_lib/core/
cred_format.rs

1use std::fmt;
2
3#[derive(Debug, PartialEq, Clone, Copy)]
4pub enum CredFormat
5{
6	Krb,
7	Ccache,
8}
9
10impl CredFormat
11{
12	pub fn contrary(&self) -> Self
13	{
14		match self
15		{
16			Self::Krb => Self::Ccache,
17			Self::Ccache => Self::Krb,
18		}
19	}
20
21	pub fn from_file_extension(filename: &str) -> Option<Self>
22	{
23		if filename.ends_with(".krb") || filename.ends_with(".kirbi")
24		{
25			return Some(Self::Krb);
26		}
27
28		if filename.ends_with(".ccache")
29		{
30			return Some(Self::Ccache);
31		}
32
33		None
34	}
35}
36
37impl fmt::Display for CredFormat
38{
39	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
40	{
41		match self
42		{
43			Self::Ccache => write!(f, "ccache"),
44			Self::Krb => write!(f, "krb"),
45		}
46	}
47}