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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//! # Interactive User Input Module
//!
//! This module provides a collection of user-friendly interactive prompts for
//! gathering input during cryptographic operations. It uses the `dialoguer` crate
//! to create polished command-line interfaces with validation and error handling.
//!
//! ## Features
//!
//! - **Text Input**: Standard text prompts with validation
//! - **Password Input**: Secure password entry with hidden input
//! - **Numeric Input**: Number prompts with range validation
//! - **Choice Selection**: Multiple choice menus with keyboard navigation
//!
//! ## Error Handling
//!
//! All functions return `Result<T>` to enable proper error propagation and
//! user-friendly error messages when input operations fail.
use ;
use ;
/// Prompt user for text input with validation
///
/// Displays a formatted prompt and waits for user input. The function handles
/// basic input validation and provides context for error messages.
///
/// # Arguments
///
/// * `prompt` - The message to display to the user
///
/// # Returns
///
/// Returns the user's input as a `String` wrapped in a `Result`.
///
/// # Examples
///
/// ```rust
/// use ruscrypt::interactive;
///
/// let text = interactive::prompt_for_input("Enter your message")?;
/// println!("You entered: {}", text);
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The input stream is interrupted (Ctrl+C)
/// - Terminal I/O fails
/// - The prompt cannot be displayed
/// Prompt user for password input with hidden characters
///
/// Displays a password prompt where user input is not echoed to the terminal
/// for security. This is ideal for sensitive information like encryption keys
/// and passwords.
///
/// # Arguments
///
/// * `prompt` - The message to display to the user
///
/// # Returns
///
/// Returns the user's password as a `String` wrapped in a `Result`.
///
/// # Security Features
///
/// - Input is not displayed on screen
/// - Password is not logged or stored in command history
/// - Memory is cleared after use (handled by dialoguer)
///
/// # Examples
///
/// ```rust
/// use ruscrypt::interactive;
///
/// let key = interactive::prompt_for_password("Enter encryption key")?;
/// // Use key for cryptographic operations
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The input stream is interrupted
/// - Terminal I/O fails
/// - The password prompt cannot be displayed
/// Prompt user for numeric input with range validation
///
/// Displays a numeric prompt and validates that the input falls within the
/// specified range. The function will continue prompting until valid input
/// is provided or the user cancels.
///
/// # Arguments
///
/// * `prompt` - The message to display to the user
/// * `min` - Minimum allowed value (inclusive)
/// * `max` - Maximum allowed value (inclusive)
///
/// # Returns
///
/// Returns the user's numeric input as a `u32` wrapped in a `Result`.
///
/// # Validation
///
/// The function automatically validates that:
/// - Input is a valid number
/// - Number is within the specified range [min, max]
/// - Provides helpful error messages for invalid input
///
/// # Examples
///
/// ```rust
/// use ruscrypt::interactive;
///
/// // Prompt for a shift value between 1 and 25
/// let shift = interactive::prompt_for_number("Enter shift value", 1, 25)?;
/// println!("Shift: {}", shift);
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The input stream is interrupted
/// - Terminal I/O fails
/// - The prompt cannot be displayed
/// - User provides non-numeric input repeatedly
/// Prompt user to select from a list of choices
///
/// Displays an interactive menu where users can navigate with arrow keys
/// and select an option with Enter. This provides a user-friendly alternative
/// to typing exact strings.
///
/// # Arguments
///
/// * `prompt` - The message to display above the choice list
/// * `choices` - Array of string slices representing the available options
///
/// # Returns
///
/// Returns the selected choice as a `String` wrapped in a `Result`.
///
/// # User Interface
///
/// - Arrow keys (↑/↓) navigate the list
/// - Enter key selects the highlighted option
/// - First option is selected by default
/// - Options are displayed with visual highlighting
///
/// # Examples
///
/// ```rust
/// use ruscrypt::interactive;
///
/// let encoding = interactive::prompt_for_choices(
/// "Select output encoding",
/// &["base64", "hex", "binary"]
/// )?;
/// println!("Selected: {}", encoding);
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The input stream is interrupted
/// - Terminal I/O fails
/// - The menu cannot be displayed
/// - No choices are provided (empty array)
/// Prompt user to select key output format for key generation
///
/// Returns either "n:e" or "PEM" as a string.
/// Prompt user for multi-line input (e.g., PEM keys)
///
/// Displays a prompt and reads lines until an empty line is entered.
/// Returns the concatenated input as a single String.
///
/// # Arguments
///
/// * `prompt` - The message to display to the user
///
/// # Returns
///
/// Returns the user's multi-line input as a `String` wrapped in a `Result`.
///
/// # Examples
///
/// ```rust
/// use ruscrypt::interactive;
/// let pem = interactive::prompt_for_multiline_input("Paste your PEM key (end with empty line):")?;
/// ```
/// Prompt user for encoding format selection
///
/// Returns either "base64" or "hex" as a string.