Skip to content

Commit 0be2473

Browse files
committed
Allow use of windows-sys 0.61
1 parent 955e971 commit 0be2473

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

rustls-platform-verifier/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ security-framework = { version = "3", features = ["OSX_10_14"] }
5757
security-framework-sys = { version = "2.10", features = ["OSX_10_14"] }
5858

5959
[target.'cfg(windows)'.dependencies]
60-
windows-sys = { version = ">=0.52.0, <0.60.0", default-features = false, features = ["Win32_Foundation", "Win32_Security_Cryptography"] }
60+
windows-sys = { version = ">=0.52.0, <0.62.0", default-features = false, features = ["Win32_Foundation", "Win32_Security_Cryptography"] }
6161

6262
[dev-dependencies]
6363
rustls = { version = "0.23", default-features = false, features = ["ring"] }

rustls-platform-verifier/src/verification/windows.rs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustls::{
3535
};
3636
use windows_sys::Win32::{
3737
Foundation::{
38-
BOOL, CERT_E_CN_NO_MATCH, CERT_E_EXPIRED, CERT_E_INVALID_NAME, CERT_E_UNTRUSTEDROOT,
38+
CERT_E_CN_NO_MATCH, CERT_E_EXPIRED, CERT_E_INVALID_NAME, CERT_E_UNTRUSTEDROOT,
3939
CERT_E_WRONG_USAGE, CRYPT_E_REVOKED, FILETIME, TRUE,
4040
},
4141
Security::Cryptography::{
@@ -66,7 +66,7 @@ struct CERT_CHAIN_PARA {
6666
pub RequestedUsage: CERT_USAGE_MATCH,
6767
pub RequestedIssuancePolicy: CERT_USAGE_MATCH,
6868
pub dwUrlRetrievalTimeout: u32,
69-
pub fCheckRevocationFreshnessTime: BOOL,
69+
pub fCheckRevocationFreshnessTime: i32, // BOOL
7070
pub dwRevocationFreshnessTime: u32,
7171
pub pftCacheResync: *mut FILETIME,
7272
// XXX: `pStrongSignPara` and `dwStrongSignFlags` might or might not be defined on the current system. It started
@@ -230,7 +230,7 @@ impl CertEngine {
230230
let mut config = CERT_CHAIN_ENGINE_CONFIG::zeroed_with_size();
231231
config.hExclusiveRoot = exclusive_store.inner.as_ptr();
232232

233-
let mut engine = 0;
233+
let mut engine = EnginePtr::NULL;
234234
// SAFETY: `engine` is valid to be written to and the config is valid to be read.
235235
let res = unsafe { CertCreateCertificateChainEngine(&config, &mut engine) };
236236

@@ -264,7 +264,7 @@ impl CertEngine {
264264
config.dwFlags = CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL | CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE;
265265
config.hExclusiveRoot = root_store.inner.as_ptr();
266266

267-
let mut engine = 0;
267+
let mut engine = EnginePtr::NULL;
268268
// SAFETY: `engine` is valid to be written to and the config is valid to be read.
269269
let res = unsafe { CertCreateCertificateChainEngine(&config, &mut engine) };
270270

@@ -276,17 +276,12 @@ impl CertEngine {
276276

277277
Ok(Self { inner: engine })
278278
}
279-
280-
#[allow(clippy::as_conversions)]
281-
fn as_ptr(&self) -> isize {
282-
self.inner.as_ptr() as isize
283-
}
284279
}
285280

286281
impl Drop for CertEngine {
287282
fn drop(&mut self) {
288283
// SAFETY: The engine pointer is guaranteed to be non-null.
289-
unsafe { CertFreeCertificateChainEngine(self.as_ptr()) };
284+
unsafe { CertFreeCertificateChainEngine(EnginePtr::from_raw(self.inner)) };
290285
}
291286
}
292287

@@ -452,7 +447,10 @@ impl CertificateStore {
452447
let parameters = NonNull::from(&parameters).cast().as_ptr();
453448

454449
CertGetCertificateChain(
455-
engine.map(CertEngine::as_ptr).unwrap_or(0),
450+
match engine {
451+
Some(ptr) => EnginePtr::from_raw(eng.inner),
452+
None => EnginePtr::NULL,
453+
},
456454
certificate.inner.as_ptr(),
457455
&time,
458456
self.inner.as_ptr(),
@@ -472,6 +470,33 @@ impl CertificateStore {
472470
}
473471
}
474472

473+
// `windows-sys` >= 0.60
474+
impl EnginePtr for *mut c_void {
475+
fn from_raw(val: NonNull<c_void>) -> Self {
476+
val.as_ptr()
477+
}
478+
479+
const NULL: Self = ptr::null_mut();
480+
}
481+
482+
// `windows-sys` 0.52-0.59
483+
impl EnginePtr for isize {
484+
#[allow(clippy::as_conversions)]
485+
fn from_raw(val: NonNull<c_void>) -> Self {
486+
val.as_ptr() as isize
487+
}
488+
489+
const NULL: Self = 0;
490+
}
491+
492+
/// An abstraction trait over the different ways various `windows-sys` versions represent
493+
/// the type of `HCERTCHAINENGINE`.
494+
trait EnginePtr: Sized {
495+
fn from_raw(val: NonNull<c_void>) -> Self;
496+
497+
const NULL: Self;
498+
}
499+
475500
fn call_with_last_error<T, F: FnMut() -> Option<T>>(mut call: F) -> Result<T, TlsError> {
476501
if let Some(res) = call() {
477502
Ok(res)

0 commit comments

Comments
 (0)