Skip to content

Commit 651a61b

Browse files
authored
replace winapi with windows-sys
1 parent 02e615a commit 651a61b

File tree

4 files changed

+46
-50
lines changed

4 files changed

+46
-50
lines changed

quiche/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ sfv = { version = "0.9", optional = true }
7878
smallvec = { version = "1.10", features = ["serde", "union"] }
7979

8080
[target."cfg(windows)".dependencies]
81-
winapi = { version = "0.3", features = ["wincrypt", "ws2def", "ws2ipdef", "ws2tcpip"] }
81+
windows-sys = { version = "0.59", features = ["Win32_Networking_WinSock", "Win32_Security_Cryptography"] }
8282

8383
[dev-dependencies]
8484
mio = { version = "0.8", features = ["net", "os-poll"] }

quiche/src/ffi.rs

+31-39
Original file line numberDiff line numberDiff line change
@@ -48,54 +48,54 @@ use libc::timespec;
4848
#[cfg(not(windows))]
4949
use libc::AF_INET;
5050
#[cfg(windows)]
51-
use winapi::shared::ws2def::AF_INET;
51+
use windows_sys::Win32::Networking::WinSock::AF_INET;
5252

5353
#[cfg(not(windows))]
5454
use libc::AF_INET6;
5555
#[cfg(windows)]
56-
use winapi::shared::ws2def::AF_INET6;
56+
use windows_sys::Win32::Networking::WinSock::AF_INET6;
5757

5858
#[cfg(not(windows))]
5959
use libc::in_addr;
6060
#[cfg(windows)]
61-
use winapi::shared::inaddr::IN_ADDR as in_addr;
61+
use windows_sys::Win32::Networking::WinSock::IN_ADDR as in_addr;
6262

6363
#[cfg(not(windows))]
6464
use libc::in6_addr;
6565
#[cfg(windows)]
66-
use winapi::shared::in6addr::IN6_ADDR as in6_addr;
66+
use windows_sys::Win32::Networking::WinSock::IN6_ADDR as in6_addr;
6767

6868
#[cfg(not(windows))]
6969
use libc::sa_family_t;
7070
#[cfg(windows)]
71-
use winapi::shared::ws2def::ADDRESS_FAMILY as sa_family_t;
71+
use windows_sys::Win32::Networking::WinSock::ADDRESS_FAMILY as sa_family_t;
7272

7373
#[cfg(not(windows))]
7474
use libc::sockaddr_in;
7575
#[cfg(windows)]
76-
use winapi::shared::ws2def::SOCKADDR_IN as sockaddr_in;
76+
use windows_sys::Win32::Networking::WinSock::SOCKADDR_IN as sockaddr_in;
7777

7878
#[cfg(not(windows))]
7979
use libc::sockaddr_in6;
8080
#[cfg(windows)]
81-
use winapi::shared::ws2ipdef::SOCKADDR_IN6_LH as sockaddr_in6;
81+
use windows_sys::Win32::Networking::WinSock::SOCKADDR_IN6 as sockaddr_in6;
8282

8383
#[cfg(not(windows))]
8484
use libc::sockaddr_storage;
8585
#[cfg(windows)]
86-
use winapi::shared::ws2def::SOCKADDR_STORAGE_LH as sockaddr_storage;
86+
use windows_sys::Win32::Networking::WinSock::SOCKADDR_STORAGE as sockaddr_storage;
8787

8888
#[cfg(windows)]
8989
use libc::c_int as socklen_t;
9090
#[cfg(not(windows))]
9191
use libc::socklen_t;
9292

9393
#[cfg(windows)]
94-
use winapi::shared::in6addr::in6_addr_u;
94+
use windows_sys::Win32::Networking::WinSock::IN6_ADDR_0;
9595
#[cfg(windows)]
96-
use winapi::shared::inaddr::in_addr_S_un;
96+
use windows_sys::Win32::Networking::WinSock::IN_ADDR_0;
9797
#[cfg(windows)]
98-
use winapi::shared::ws2ipdef::SOCKADDR_IN6_LH_u;
98+
use windows_sys::Win32::Networking::WinSock::SOCKADDR_IN6_0;
9999

100100
use crate::*;
101101

@@ -1851,7 +1851,7 @@ fn optional_std_addr_from_c(
18511851
}
18521852

18531853
fn std_addr_from_c(addr: &sockaddr, addr_len: socklen_t) -> SocketAddr {
1854-
match addr.sa_family as i32 {
1854+
match addr.sa_family as _ {
18551855
AF_INET => {
18561856
assert!(addr_len as usize == std::mem::size_of::<sockaddr_in>());
18571857

@@ -1861,7 +1861,7 @@ fn std_addr_from_c(addr: &sockaddr, addr_len: socklen_t) -> SocketAddr {
18611861
let ip_addr = Ipv4Addr::from(u32::from_be(in4.sin_addr.s_addr));
18621862
#[cfg(windows)]
18631863
let ip_addr = {
1864-
let ip_bytes = unsafe { in4.sin_addr.S_un.S_un_b() };
1864+
let ip_bytes = unsafe { in4.sin_addr.S_un.S_un_b };
18651865

18661866
Ipv4Addr::from([
18671867
ip_bytes.s_b1,
@@ -1887,15 +1887,17 @@ fn std_addr_from_c(addr: &sockaddr, addr_len: socklen_t) -> SocketAddr {
18871887
#[cfg(not(windows))]
18881888
in6.sin6_addr.s6_addr,
18891889
#[cfg(windows)]
1890-
*unsafe { in6.sin6_addr.u.Byte() },
1890+
unsafe {
1891+
in6.sin6_addr.u.Byte
1892+
},
18911893
);
18921894

18931895
let port = u16::from_be(in6.sin6_port);
18941896

18951897
#[cfg(not(windows))]
18961898
let scope_id = in6.sin6_scope_id;
18971899
#[cfg(windows)]
1898-
let scope_id = unsafe { *in6.u.sin6_scope_id() };
1900+
let scope_id = unsafe { in6.Anonymous.sin6_scope_id };
18991901

19001902
let out =
19011903
SocketAddrV6::new(ip_addr, port, in6.sin6_flowinfo, scope_id);
@@ -1920,10 +1922,8 @@ fn std_addr_to_c(addr: &SocketAddr, out: &mut sockaddr_storage) -> socklen_t {
19201922
#[cfg(not(windows))]
19211923
let sin_addr = in_addr { s_addr };
19221924
#[cfg(windows)]
1923-
let sin_addr = {
1924-
let mut s_un = std::mem::zeroed::<in_addr_S_un>();
1925-
*s_un.S_addr_mut() = s_addr;
1926-
in_addr { S_un: s_un }
1925+
let sin_addr = in_addr {
1926+
S_un: IN_ADDR_0 { S_addr: s_addr },
19271927
};
19281928

19291929
*out_in = sockaddr_in {
@@ -1959,17 +1959,10 @@ fn std_addr_to_c(addr: &SocketAddr, out: &mut sockaddr_storage) -> socklen_t {
19591959
s6_addr: addr.ip().octets(),
19601960
};
19611961
#[cfg(windows)]
1962-
let sin6_addr = {
1963-
let mut u = std::mem::zeroed::<in6_addr_u>();
1964-
*u.Byte_mut() = addr.ip().octets();
1965-
in6_addr { u }
1966-
};
1967-
1968-
#[cfg(windows)]
1969-
let u = {
1970-
let mut u = std::mem::zeroed::<SOCKADDR_IN6_LH_u>();
1971-
*u.sin6_scope_id_mut() = addr.scope_id();
1972-
u
1962+
let sin6_addr = in6_addr {
1963+
u: IN6_ADDR_0 {
1964+
Byte: addr.ip().octets(),
1965+
},
19731966
};
19741967

19751968
*out_in6 = sockaddr_in6 {
@@ -1995,7 +1988,9 @@ fn std_addr_to_c(addr: &SocketAddr, out: &mut sockaddr_storage) -> socklen_t {
19951988
#[cfg(not(windows))]
19961989
sin6_scope_id: addr.scope_id(),
19971990
#[cfg(windows)]
1998-
u,
1991+
Anonymous: SOCKADDR_IN6_0 {
1992+
sin6_scope_id: addr.scope_id(),
1993+
},
19991994
};
20001995

20011996
sa_len as socklen_t
@@ -2025,12 +2020,9 @@ fn std_time_to_c(_time: &std::time::Instant, out: &mut timespec) {
20252020
mod tests {
20262021
use super::*;
20272022

2028-
#[cfg(not(windows))]
20292023
use libc::c_void;
20302024
#[cfg(windows)]
2031-
use winapi::ctypes::c_void;
2032-
#[cfg(windows)]
2033-
use winapi::um::ws2tcpip::inet_ntop;
2025+
use windows_sys::Win32::Networking::WinSock::inet_ntop;
20342026

20352027
#[test]
20362028
fn addr_v4() {
@@ -2052,9 +2044,9 @@ mod tests {
20522044
let dst = s.into_raw();
20532045

20542046
inet_ntop(
2055-
AF_INET,
2047+
AF_INET as _,
20562048
&((*in_addr).sin_addr) as *const _ as *const c_void,
2057-
dst,
2049+
dst as _,
20582050
16,
20592051
);
20602052

@@ -2096,9 +2088,9 @@ mod tests {
20962088
let dst = s.into_raw();
20972089

20982090
inet_ntop(
2099-
AF_INET6,
2091+
AF_INET6 as _,
21002092
&((*in6_addr).sin6_addr) as *const _ as *const c_void,
2101-
dst,
2093+
dst as _,
21022094
45,
21032095
);
21042096

quiche/src/frame.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1012,14 +1012,15 @@ impl Frame {
10121012
trigger_frame_type: None, // don't know trigger type
10131013
},
10141014

1015-
Frame::ApplicationClose { error_code, reason } =>
1015+
Frame::ApplicationClose { error_code, reason } => {
10161016
QuicFrame::ConnectionClose {
10171017
error_space: Some(ErrorSpace::ApplicationError),
10181018
error_code: Some(*error_code),
10191019
error_code_value: None, // raw error is no different for us
10201020
reason: Some(String::from_utf8_lossy(reason).into_owned()),
10211021
trigger_frame_type: None, // don't know trigger type
1022-
},
1022+
}
1023+
},
10231024

10241025
Frame::HandshakeDone => QuicFrame::HandshakeDone,
10251026

quiche/src/tls/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ impl Context {
214214
fn load_ca_certs(&mut self) -> Result<()> {
215215
unsafe {
216216
let cstr = ffi::CString::new("Root").map_err(|_| Error::TlsFail)?;
217-
let sys_store = winapi::um::wincrypt::CertOpenSystemStoreA(
218-
0,
219-
cstr.as_ptr() as winapi::um::winnt::LPCSTR,
220-
);
217+
let sys_store =
218+
windows_sys::Win32::Security::Cryptography::CertOpenSystemStoreA(
219+
0,
220+
cstr.as_ptr() as windows_sys::core::PCSTR,
221+
);
221222
if sys_store.is_null() {
222223
return Err(Error::TlsFail);
223224
}
@@ -227,7 +228,7 @@ impl Context {
227228
return Err(Error::TlsFail);
228229
}
229230

230-
let mut ctx_p = winapi::um::wincrypt::CertEnumCertificatesInStore(
231+
let mut ctx_p = windows_sys::Win32::Security::Cryptography::CertEnumCertificatesInStore(
231232
sys_store,
232233
ptr::null(),
233234
);
@@ -246,14 +247,16 @@ impl Context {
246247

247248
X509_free(cert);
248249

249-
ctx_p = winapi::um::wincrypt::CertEnumCertificatesInStore(
250+
ctx_p = windows_sys::Win32::Security::Cryptography::CertEnumCertificatesInStore(
250251
sys_store, ctx_p,
251252
);
252253
}
253254

254255
// tidy up
255-
winapi::um::wincrypt::CertFreeCertificateContext(ctx_p);
256-
winapi::um::wincrypt::CertCloseStore(sys_store, 0);
256+
windows_sys::Win32::Security::Cryptography::CertFreeCertificateContext(ctx_p);
257+
windows_sys::Win32::Security::Cryptography::CertCloseStore(
258+
sys_store, 0,
259+
);
257260
}
258261

259262
Ok(())

0 commit comments

Comments
 (0)