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
use std::fmt;

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum CredFormat
{
	Krb,
	Ccache,
}

impl CredFormat
{
	pub fn contrary(&self) -> Self
	{
		match self
		{
			Self::Krb => Self::Ccache,
			Self::Ccache => Self::Krb,
		}
	}

	pub fn from_file_extension(filename: &str) -> Option<Self>
	{
		if filename.ends_with(".krb") || filename.ends_with(".kirbi")
		{
			return Some(Self::Krb);
		}

		if filename.ends_with(".ccache")
		{
			return Some(Self::Ccache);
		}

		None
	}
}

impl fmt::Display for CredFormat
{
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
	{
		match self
		{
			Self::Ccache => write!(f, "ccache"),
			Self::Krb => write!(f, "krb"),
		}
	}
}