Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various minor code cleanups #47

Merged
merged 2 commits into from Jun 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 9 additions & 20 deletions src/lib.rs
Expand Up @@ -107,19 +107,11 @@ mod unix {
Source::Stdin(ref mut stdin) => stdin.read_line(&mut password),
};

// Check the response.
match input {
Ok(_) => {}
Err(err) => {
// Reset the terminal and quit.
io_result(unsafe { tcsetattr(tty_fd, TCSANOW, &term_orig) })?;

return Err(err);
}
};

// Reset the terminal.
io_result(unsafe { tcsetattr(tty_fd, TCSANOW, &term_orig) })?;

// Return if we have an error
input?;
} else {
// If we don't have a TTY, the input was piped so we bypass
// terminal hiding code
Expand Down Expand Up @@ -199,7 +191,7 @@ mod windows {
let handle = source.as_raw_handle();

// Check the response.
let _ = input?;
input?;

// Set the the mode back to normal
if unsafe { SetConsoleMode(handle, mode) } == 0 {
Expand All @@ -208,8 +200,8 @@ mod windows {

super::fixes_newline(&mut password);

// Newline for windows which otherwise prints on the same line.
println!();
// Newline for windows which otherwise prints on the same line.
println!();

Ok(password.into_inner())
}
Expand Down Expand Up @@ -248,12 +240,9 @@ pub fn read_password_with_reader<T>(source: Option<T>) -> ::std::io::Result<Stri
match source {
Some(mut reader) => {
let mut password = ZeroOnDrop::new();
if let Err(err) = reader.read_line(&mut password) {
Err(err)
} else {
fixes_newline(&mut password);
Ok(password.into_inner())
}
reader.read_line(&mut password)?;
fixes_newline(&mut password);
Ok(password.into_inner())
},
None => read_password_from_stdin(false),
}
Expand Down