forked from fufesou/pam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.rs
38 lines (31 loc) · 1.04 KB
/
types.rs
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
use crate::enums::PamReturnCode;
/// Opaque PAM main structure. Used for nearly all application functions
pub type PamHandle = pam_sys::pam_handle_t;
/// PAM message that is passed to modules
pub type PamMessage = pam_sys::pam_message;
/// PAM response returned by modules
pub type PamResponse = pam_sys::pam_response;
/// PAM related error with `PamReturnCode` inside it
pub struct PamError(pub PamReturnCode);
/// Convenience type for functions that might fail with a `PamError`
pub type PamResult<T> = std::result::Result<T, PamError>;
impl std::fmt::Debug for PamError {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(fmt)
}
}
impl std::fmt::Display for PamError {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(fmt)
}
}
impl std::error::Error for PamError {
fn description(&self) -> &str {
"PAM returned an error code"
}
}
impl From<PamReturnCode> for PamError {
fn from(err: PamReturnCode) -> PamError {
PamError(err)
}
}