From f799eabf3b16e002113fa7a151eadec1ee6eb9bb Mon Sep 17 00:00:00 2001 From: Eyob Date: Sun, 8 Sep 2024 23:35:32 +0300 Subject: [PATCH] Fix windows api --- Cargo.toml | 10 ++++++++-- src/lib.rs | 14 +++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fdc06e8..10493db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,12 @@ zeroize = "1.8.1" libc = "0.2.158" errno = "0.3.9" - [target.'cfg(windows)'.dependencies] -windows-sys = "0.59.0" +windows-sys = { version = "0.59.0", default-features = false, features = [ + "Win32_System_SystemInformation", + "Win32_System_Memory", + "Win32_Foundation", + "Win32_System_Diagnostics_Debug", + "Win32_System", + "Win32_System_Diagnostics_Debug_Extensions", +], optional = true } diff --git a/src/lib.rs b/src/lib.rs index fbc7a08..53b4942 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,6 @@ impl Zeroize for SecretBox { impl Drop for SecretBox { fn drop(&mut self) { let len = size_of_val(&*self.inner_secret); - let secret_ptr = self.inner_secret.as_ref() as *const S; #[cfg(unix)] @@ -66,12 +65,8 @@ impl Drop for SecretBox { #[cfg(windows)] unsafe { - #[cfg(feature = "Win32")] if windows_sys::Win32::System::Memory::VirtualUnlock(secret_ptr.cast(), len) == 0 { - panic!( - "VirtualUnlock failed: {:?}", - windows_sys::core::HRESULT_FROM_WIN32(windows_sys::core::GetLastError()) - ); + panic!("VirtualUnlock failed",); } } @@ -91,6 +86,7 @@ impl SecretBox { /// Create a secret value using a pre-boxed value. pub fn new(boxed_secret: Box) -> Self { let len = size_of_val(&*boxed_secret); + let secret_ptr = Box::into_raw(boxed_secret); #[cfg(unix)] @@ -115,12 +111,8 @@ impl SecretBox { #[cfg(windows)] unsafe { - #[cfg(feature = "Win32")] if windows_sys::Win32::System::Memory::VirtualLock(secret_ptr.cast(), len) == 0 { - panic!( - "VirtualLock failed: {:?}", - windows_sys::core::HRESULT_FROM_WIN32(windows_sys::core::GetLastError()) - ); + panic!("VirtualLock failed",); } }