pam_rs/
types.rs

1use crate::enums::PamReturnCode;
2
3/// Opaque PAM main structure. Used for nearly all application functions
4pub type PamHandle = pam_sys::pam_handle_t;
5/// PAM message that is passed to modules
6pub type PamMessage = pam_sys::pam_message;
7/// PAM response returned by modules
8pub type PamResponse = pam_sys::pam_response;
9
10/// PAM related error with `PamReturnCode` inside it
11pub struct PamError(pub PamReturnCode);
12
13/// Convenience type for functions that might fail with a `PamError`
14pub type PamResult<T> = std::result::Result<T, PamError>;
15
16impl std::fmt::Debug for PamError {
17    fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
18        self.0.fmt(fmt)
19    }
20}
21
22impl std::fmt::Display for PamError {
23    fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
24        self.0.fmt(fmt)
25    }
26}
27
28impl std::error::Error for PamError {
29    fn description(&self) -> &str {
30        "PAM returned an error code"
31    }
32}
33
34impl From<PamReturnCode> for PamError {
35    fn from(err: PamReturnCode) -> PamError {
36        PamError(err)
37    }
38}