changeset 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
files src/constants.rs src/conv.rs src/lib.rs
diffstat 3 files changed, 38 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/constants.rs	Wed May 21 23:10:09 2025 -0400
+++ b/src/constants.rs	Wed May 21 23:19:43 2025 -0400
@@ -35,38 +35,6 @@
     }
 }
 
-/// Styles of message that are shown to the user.
-#[derive(Debug, PartialEq, FromPrimitive)]
-#[non_exhaustive] // non-exhaustive because C might give us back anything!
-pub enum MessageStyle {
-    /// Requests information from the user; will be masked when typing.
-    PromptEchoOff = 1,
-    /// Requests information from the user; will not be masked.
-    PromptEchoOn = 2,
-    /// An error message.
-    ErrorMsg = 3,
-    /// An informational message.
-    TextInfo = 4,
-    /// Yes/No/Maybe conditionals. Linux-PAM specific.
-    RadioType = 5,
-    /// For server–client non-human interaction.
-    /// NOT part of the X/Open PAM specification.
-    BinaryPrompt = 7,
-}
-
-impl TryFrom<c_int> for MessageStyle {
-    type Error = InvalidEnum<Self>;
-    fn try_from(value: c_int) -> std::result::Result<Self, Self::Error> {
-        Self::from_i32(value).ok_or(value.into())
-    }
-}
-
-impl From<MessageStyle> for c_int {
-    fn from(val: MessageStyle) -> Self {
-        val as Self
-    }
-}
-
 /// The Linux-PAM error return values. Success is an Ok [Result].
 ///
 /// Most abbreviations (except `AuthTok` and `Max`) are now full words.
@@ -200,12 +168,12 @@
 
     #[test]
     fn test_enums() {
-        assert_eq!(Ok(MessageStyle::ErrorMsg), 3.try_into());
+        assert_eq!(Ok(ErrorCode::ServiceError), 3.try_into());
         assert_eq!(Err(InvalidEnum::from(999)), ErrorCode::try_from(999));
         assert_eq!(Ok(()), ErrorCode::result_from(0));
         assert_eq!(Err(ErrorCode::Abort), ErrorCode::result_from(26));
         assert_eq!(Err(ErrorCode::SystemError), ErrorCode::result_from(423));
-        assert!(InvalidEnum::<MessageStyle>(33, PhantomData)
+        assert!(InvalidEnum::<ErrorCode>(33, PhantomData)
             .to_string()
             .starts_with("33 is not a valid "));
     }
--- a/src/conv.rs	Wed May 21 23:10:09 2025 -0400
+++ b/src/conv.rs	Wed May 21 23:19:43 2025 -0400
@@ -6,12 +6,45 @@
 use libc::{c_char, c_int};
 use std::ffi::{CStr, CString};
 use std::ptr;
-
-use crate::constants::ErrorCode;
+use num_derive::FromPrimitive;
+use crate::constants::{ErrorCode, InvalidEnum};
 use crate::constants::MessageStyle;
 use crate::constants::Result;
 use crate::items::Item;
 
+/// Styles of message that are shown to the user.
+#[derive(Debug, PartialEq, FromPrimitive)]
+#[non_exhaustive] // non-exhaustive because C might give us back anything!
+pub enum MessageStyle {
+    /// Requests information from the user; will be masked when typing.
+    PromptEchoOff = 1,
+    /// Requests information from the user; will not be masked.
+    PromptEchoOn = 2,
+    /// An error message.
+    ErrorMsg = 3,
+    /// An informational message.
+    TextInfo = 4,
+    /// Yes/No/Maybe conditionals. Linux-PAM specific.
+    RadioType = 5,
+    /// For server–client non-human interaction.
+    /// NOT part of the X/Open PAM specification.
+    BinaryPrompt = 7,
+}
+
+impl TryFrom<c_int> for MessageStyle {
+    type Error = InvalidEnum<Self>;
+    fn try_from(value: c_int) -> std::result::Result<Self, Self::Error> {
+        Self::from_i32(value).ok_or(value.into())
+    }
+}
+
+impl From<MessageStyle> for c_int {
+    fn from(val: MessageStyle) -> Self {
+        val as Self
+    }
+}
+
+
 #[repr(C)]
 struct Message {
     msg_style: MessageStyle,
--- a/src/lib.rs	Wed May 21 23:10:09 2025 -0400
+++ b/src/lib.rs	Wed May 21 23:19:43 2025 -0400
@@ -33,6 +33,6 @@
 
 #[doc(inline)]
 pub use crate::{
-    constants::{ErrorCode, Flags, MessageStyle, Result},
+    constants::{ErrorCode, Flags, Result},
     module::{PamHandle, PamModule},
 };