Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/pam/rpassword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,39 @@ impl Terminal<'_> {
pub fn read_password(&mut self, timeout: Option<Duration>) -> io::Result<PamBuffer> {
let mut input = self.source_timeout(timeout);
let _hide_input = HiddenInput::new(false)?;
read_unbuffered(&mut input)
let rslt = read_unbuffered(&mut input);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use ret as variable name?

if rslt.is_err() {
let _ = self.sink().write(b"\n");
}

rslt
}

/// Reads input with TTY echo disabled, but do provide visual feedback while typing.
pub fn read_password_with_feedback(
&mut self,
timeout: Option<Duration>,
) -> io::Result<PamBuffer> {
match (HiddenInput::new(true)?, self) {
(Some(hide_input), Terminal::StdIE(stdin, stdout)) => {
let mut reader = TimeoutRead::new(stdin.as_fd(), timeout);
read_unbuffered_with_feedback(&mut reader, stdout, &hide_input)
}
(Some(hide_input), Terminal::Tty(file)) => {
let mut reader = TimeoutRead::new(file.as_fd(), timeout);
read_unbuffered_with_feedback(&mut reader, &mut &*file, &hide_input)
let rslt = if let Some(hide_input) = HiddenInput::new(true)? {
match self {
Comment on lines +287 to +288
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can stay a single match, right? So let ret = match (HiddenInput::new(true)?, self) { ... };

Terminal::StdIE(stdin, stdout) => {
let mut reader = TimeoutRead::new(stdin.as_fd(), timeout);
read_unbuffered_with_feedback(&mut reader, stdout, &hide_input)
}
Terminal::Tty(file) => {
let mut reader = TimeoutRead::new(file.as_fd(), timeout);
read_unbuffered_with_feedback(&mut reader, &mut &*file, &hide_input)
}
}
(None, term) => read_unbuffered(&mut term.source_timeout(timeout)),
} else {
read_unbuffered(&mut self.source_timeout(timeout))
};

if rslt.is_err() {
let _ = self.sink().write(b"\n");
}

rslt
}

/// Reads input with TTY echo enabled
Expand Down
Loading