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 Unknown(i32),
59}
60
61impl Display for KeyError {
62 #[inline(always)]
63 fn fmt(&self, f: &mut Formatter) -> Result {
64 <KeyError as Debug>::fmt(self, f)
65 }
66}
67
68#[cfg(feature = "std")]
69impl Error for KeyError {}
70
71impl KeyError {
72 pub fn from_errno() -> KeyError {
74 match unsafe { *libc::__errno_location() } {
75 libc::EACCES => KeyError::AccessDenied,
77 libc::EDQUOT => KeyError::QuotaExceeded,
78 libc::EFAULT => KeyError::BadAddress,
79 libc::EINVAL => KeyError::InvalidArguments,
80 libc::EKEYEXPIRED => KeyError::KeyExpired,
81 libc::EKEYREVOKED => KeyError::KeyRevoked,
82 libc::EKEYREJECTED => KeyError::KeyRejected,
83 libc::ENOMEM => KeyError::OutOfMemory,
84 libc::ENOKEY => KeyError::KeyDoesNotExist,
85 libc::ENOTSUP => KeyError::OperationNotSupported,
86
87 x => KeyError::Unknown(x),
89 }
90 }
91}