diff --git a/Cargo.toml b/Cargo.toml index b54e92c..c3641f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.60" libc = "0.2" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3", features = ["std", "winnt", "fileapi", "processenv", "winbase", "handleapi", "consoleapi", "minwindef", "wincon"] } +windows-sys = { version = "0.42.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_Storage_FileSystem", "Win32_Security", "Win32_System_SystemServices"] } [dependencies] rtoolbox = { path = "../rtoolbox", version = "0.0" } diff --git a/src/lib.rs b/src/lib.rs index af4cd76..b321ebd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,17 +140,18 @@ mod unix { #[cfg(target_family = "windows")] mod windows { - use std::io::{self, BufReader}; use std::io::BufRead; + use std::io::{self, BufReader}; use std::os::windows::io::FromRawHandle; - use winapi::shared::minwindef::LPDWORD; - use winapi::um::consoleapi::{GetConsoleMode, SetConsoleMode}; - use winapi::um::fileapi::{CreateFileA, OPEN_EXISTING}; - use winapi::um::handleapi::INVALID_HANDLE_VALUE; - use winapi::um::wincon::{ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT}; - use winapi::um::winnt::{ - FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE, HANDLE, + use windows_sys::core::PCSTR; + use windows_sys::Win32::Foundation::{HANDLE, INVALID_HANDLE_VALUE}; + use windows_sys::Win32::Storage::FileSystem::{ + CreateFileA, FILE_SHARE_READ, FILE_SHARE_WRITE, OPEN_EXISTING, + }; + use windows_sys::Win32::System::Console::{ + GetConsoleMode, SetConsoleMode, CONSOLE_MODE, ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT, }; + use windows_sys::Win32::System::SystemServices::{GENERIC_READ, GENERIC_WRITE}; struct HiddenInput { mode: u32, @@ -162,7 +163,7 @@ mod windows { let mut mode = 0; // Get the old mode so we can reset back to it when we are done - if unsafe { GetConsoleMode(handle, &mut mode as LPDWORD) } == 0 { + if unsafe { GetConsoleMode(handle, &mut mode as *mut CONSOLE_MODE) } == 0 { return Err(std::io::Error::last_os_error()); } @@ -189,13 +190,13 @@ mod windows { pub fn read_password() -> std::io::Result { let handle = unsafe { CreateFileA( - b"CONIN$\x00".as_ptr() as *const i8, + b"CONIN$\x00".as_ptr() as PCSTR, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, - std::ptr::null_mut(), + std::ptr::null(), OPEN_EXISTING, 0, - std::ptr::null_mut(), + INVALID_HANDLE_VALUE, ) }; @@ -203,7 +204,7 @@ mod windows { return Err(std::io::Error::last_os_error()); } - let mut stream = BufReader::new(unsafe { std::fs::File::from_raw_handle(handle) }); + let mut stream = BufReader::new(unsafe { std::fs::File::from_raw_handle(handle as _) }); read_password_from_handle_with_hidden_input(&mut stream, handle) } diff --git a/tests/no-terminal.rs b/tests/no-terminal.rs index b7bd171..0055a93 100644 --- a/tests/no-terminal.rs +++ b/tests/no-terminal.rs @@ -5,7 +5,6 @@ use std::io::Cursor; use rpassword::read_password_from_bufread; -#[cfg(unix)] #[cfg(unix)] fn close_stdin() { unsafe { @@ -13,12 +12,10 @@ fn close_stdin() { } } -#[cfg(windows)] #[cfg(windows)] fn close_stdin() { - use winapi::um::handleapi::CloseHandle; - use winapi::um::processenv::GetStdHandle; - use winapi::um::winbase::STD_INPUT_HANDLE; + use windows_sys::Win32::Foundation::CloseHandle; + use windows_sys::Win32::System::Console::{GetStdHandle, STD_INPUT_HANDLE}; unsafe { CloseHandle(GetStdHandle(STD_INPUT_HANDLE));