diff --git a/Cargo.toml b/Cargo.toml index 8731eb7..473069e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rpassword" -version = "4.0.5" +version = "5.0.0" authors = ["Conrad Kleinespel "] description = "Read passwords in console applications." license = "Apache-2.0" @@ -15,7 +15,4 @@ keywords = ["read", "password", "security", "pass", "getpass"] libc = "0.2" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3", features = ["std", "winnt", "fileapi", "processenv", "winbase", "handleapi", "consoleapi", "minwindef", "wincon"] } - -[features] -enhanced_mock = [] +winapi = { version = "0.3", features = ["std", "winnt", "fileapi", "processenv", "winbase", "handleapi", "consoleapi", "minwindef", "wincon"] } \ No newline at end of file diff --git a/README.md b/README.md index c1644b5..0f41aa0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add `rpassword` as a dependency in Cargo.toml: ```toml [dependencies] -rpassword = "4.0" +rpassword = "5.0" ``` Use `rpassword` within your code: @@ -28,7 +28,7 @@ Use `rpassword` within your code: extern crate rpassword; fn main() { - // Prompt for a password on TTY (safest but not default for backwards compatibility) + // Prompt for a password on TTY (safest but not always most practical when integrating with other tools or unit testing) let pass = rpassword::read_password_from_tty(Some("Password: ")).unwrap(); println!("Your password is {}", pass); @@ -48,22 +48,6 @@ fn main() { The full API documentation is available at [https://docs.rs/rpassword](https://docs.rs/rpassword). -## Optional feature - -The optional feature **enhanced_mock** can be enabled to change `read_password_with_reader` signature from -``` -pub fn read_password_with_reader(source: Option) -> ::std::io::Result - where - T: ::std::io::BufRead -``` -to -``` -pub fn read_password_with_reader(source: Option<&mut T>) -> ::std::io::Result - where - T: ::std::io::BufRead -``` -allowing to call `read_password_with_reader` multiple times with the same reader. - ## Contributors We welcome contribution from everyone. Feel free to open an issue or a pull request at any time. @@ -75,10 +59,13 @@ Here's a list of existing `rpassword` contributors: * [@DaveLancaster](https://github.com/DaveLancaster) * [@dcuddeback](https://github.com/dcuddeback) * [@Draphar](https://github.com/Draphar) +* [@dvermd](https://github.com/dvermd) * [@equalsraf](https://github.com/equalsraf) +* [@Heliozoa](https://github.com/Heliozoa) * [@JanLikar](https://github.com/JanLikar) * [@joshuef](https://github.com/joshuef) * [@longshorej](https://github.com/longshorej) +* [@nicokoch](https://github.com/nicokoch) * [@petevine](https://github.com/petevine) * [@psych0d0g](https://github.com/psych0d0g) * [@retep998](https://github.com/retep998) diff --git a/src/lib.rs b/src/lib.rs index 59662e7..ddb89bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,55 +237,7 @@ use unix::{read_password_from_stdin, display_on_tty}; use windows::{read_password_from_stdin, display_on_tty}; /// Reads a password from anything that implements BufRead -#[cfg(not(feature = "enhanced_mock"))] -mod legacy_mock { - use super::*; - - /// Reads a password from STDIN - pub fn read_password() -> ::std::io::Result { - read_password_with_reader(None::<::std::io::Empty>) - } - - /// Reads a password from anything that implements BufRead - pub fn read_password_with_reader(source: Option) -> ::std::io::Result - where - T: ::std::io::BufRead, - { - match source { - Some(mut reader) => { - let mut password = ZeroOnDrop::new(); - reader.read_line(&mut password)?; - fixes_newline(&mut password); - Ok(password.into_inner()) - }, - None => read_password_from_stdin(false), - } - } - - #[cfg(test)] - mod tests { - use std::io::Cursor; - - fn mock_input_crlf() -> Cursor<&'static [u8]> { - Cursor::new(&b"A mocked response.\r\n\r\n"[..]) - } - - fn mock_input_lf() -> Cursor<&'static [u8]> { - Cursor::new(&b"A mocked response.\n"[..]) - } - - #[test] - fn can_read_from_redirected_input() { - let response = ::read_password_with_reader(Some(mock_input_crlf())).unwrap(); - assert_eq!(response, "A mocked response."); - let response = ::read_password_with_reader(Some(mock_input_lf())).unwrap(); - assert_eq!(response, "A mocked response."); - } - } -} - -#[cfg(feature = "enhanced_mock")] -mod enhanced_mock { +mod mock { use super::*; /// Reads a password from STDIN @@ -342,10 +294,7 @@ mod enhanced_mock { } } -#[cfg(feature = "enhanced_mock")] -pub use enhanced_mock::{read_password, read_password_with_reader}; -#[cfg(not(feature = "enhanced_mock"))] -pub use legacy_mock::{read_password, read_password_with_reader}; +pub use mock::{read_password, read_password_with_reader}; /// Reads a password from the terminal pub fn read_password_from_tty(prompt: Option<&str>) diff --git a/tests/no-terminal.rs b/tests/no-terminal.rs index 0084161..db94070 100644 --- a/tests/no-terminal.rs +++ b/tests/no-terminal.rs @@ -45,18 +45,6 @@ fn mock_input_lf() -> Cursor<&'static [u8]> { Cursor::new(&b"A mocked response.\nAnother mocked response.\n"[..]) } -#[cfg(not(feature = "enhanced_mock"))] -#[test] -fn can_read_from_redirected_input() { - close_stdin(); - - let response = ::read_password_with_reader(Some(mock_input_crlf())).unwrap(); - assert_eq!(response, "A mocked response."); - let response = ::read_password_with_reader(Some(mock_input_lf())).unwrap(); - assert_eq!(response, "A mocked response."); -} - -#[cfg(feature = "enhanced_mock")] #[test] fn can_read_from_redirected_input_many_times() { close_stdin();