1use core::fmt::Debug;
2use core::fmt::Display;
3use core::fmt::Formatter;
4use core::fmt::Result;
5
6#[cfg(feature = "std")]
7use std::error::Error;
8
9#[allow(dead_code)]
11#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub enum KeyError {
13 AccessDenied,
15
16 QuotaExceeded,
19
20 BadAddress,
23
24 InvalidArguments,
26
27 KeyExpired,
29
30 KeyRevoked,
32
33 KeyRejected,
35
36 KeyringDoesNotExist,
38
39 KeyDoesNotExist,
41
42 OutOfMemory,
44
45 InvalidDescription,
47
48 InvalidIdentifier,
50
51 OperationNotSupported,
53
54 WriteError,
56
57 PermissionDenied,
59
60 MissingFileOrDirectory,
65
66 Unknown(i32),
68}
69
70impl Display for KeyError {
71 #[inline(always)]
72 fn fmt(&self, f: &mut Formatter) -> Result {
73 <KeyError as Debug>::fmt(self, f)
74 }
75}
76
77#[cfg(feature = "std")]
78impl Error for KeyError {}
79
80impl KeyError {
81 pub fn from_errno() -> KeyError {
83 match unsafe { *libc::__errno_location() } {
84 libc::ENOENT => KeyError::MissingFileOrDirectory,
86 libc::EPERM => KeyError::PermissionDenied,
87 libc::EACCES => KeyError::AccessDenied,
88 libc::EDQUOT => KeyError::QuotaExceeded,
89 libc::EFAULT => KeyError::BadAddress,
90 libc::EINVAL => KeyError::InvalidArguments,
91 libc::EKEYEXPIRED => KeyError::KeyExpired,
92 libc::EKEYREVOKED => KeyError::KeyRevoked,
93 libc::EKEYREJECTED => KeyError::KeyRejected,
94 libc::ENOMEM => KeyError::OutOfMemory,
95 libc::ENOKEY => KeyError::KeyDoesNotExist,
96 libc::ENOTSUP => KeyError::OperationNotSupported,
97
98 x => KeyError::Unknown(x),
100 }
101 }
102}