Mercurial > crates > nonstick
comparison src/conv.rs @ 63:a7aa5ca0d00d
Move MessageStyle to conv, the only place it is used.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 21 May 2025 23:19:43 -0400 |
parents | d83623951070 |
children | bbe84835d6db |
comparison
equal
deleted
inserted
replaced
62:d83623951070 | 63:a7aa5ca0d00d |
---|---|
4 //! to improve the interface for both PAM modules and clients. | 4 //! to improve the interface for both PAM modules and clients. |
5 | 5 |
6 use libc::{c_char, c_int}; | 6 use libc::{c_char, c_int}; |
7 use std::ffi::{CStr, CString}; | 7 use std::ffi::{CStr, CString}; |
8 use std::ptr; | 8 use std::ptr; |
9 | 9 use num_derive::FromPrimitive; |
10 use crate::constants::ErrorCode; | 10 use crate::constants::{ErrorCode, InvalidEnum}; |
11 use crate::constants::MessageStyle; | 11 use crate::constants::MessageStyle; |
12 use crate::constants::Result; | 12 use crate::constants::Result; |
13 use crate::items::Item; | 13 use crate::items::Item; |
14 | |
15 /// Styles of message that are shown to the user. | |
16 #[derive(Debug, PartialEq, FromPrimitive)] | |
17 #[non_exhaustive] // non-exhaustive because C might give us back anything! | |
18 pub enum MessageStyle { | |
19 /// Requests information from the user; will be masked when typing. | |
20 PromptEchoOff = 1, | |
21 /// Requests information from the user; will not be masked. | |
22 PromptEchoOn = 2, | |
23 /// An error message. | |
24 ErrorMsg = 3, | |
25 /// An informational message. | |
26 TextInfo = 4, | |
27 /// Yes/No/Maybe conditionals. Linux-PAM specific. | |
28 RadioType = 5, | |
29 /// For server–client non-human interaction. | |
30 /// NOT part of the X/Open PAM specification. | |
31 BinaryPrompt = 7, | |
32 } | |
33 | |
34 impl TryFrom<c_int> for MessageStyle { | |
35 type Error = InvalidEnum<Self>; | |
36 fn try_from(value: c_int) -> std::result::Result<Self, Self::Error> { | |
37 Self::from_i32(value).ok_or(value.into()) | |
38 } | |
39 } | |
40 | |
41 impl From<MessageStyle> for c_int { | |
42 fn from(val: MessageStyle) -> Self { | |
43 val as Self | |
44 } | |
45 } | |
46 | |
14 | 47 |
15 #[repr(C)] | 48 #[repr(C)] |
16 struct Message { | 49 struct Message { |
17 msg_style: MessageStyle, | 50 msg_style: MessageStyle, |
18 msg: *const c_char, | 51 msg: *const c_char, |