@@ -35,7 +35,7 @@ use rustls::{
35
35
} ;
36
36
use windows_sys:: Win32 :: {
37
37
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 ,
39
39
CERT_E_WRONG_USAGE , CRYPT_E_REVOKED , FILETIME , TRUE ,
40
40
} ,
41
41
Security :: Cryptography :: {
@@ -66,7 +66,7 @@ struct CERT_CHAIN_PARA {
66
66
pub RequestedUsage : CERT_USAGE_MATCH ,
67
67
pub RequestedIssuancePolicy : CERT_USAGE_MATCH ,
68
68
pub dwUrlRetrievalTimeout : u32 ,
69
- pub fCheckRevocationFreshnessTime : BOOL ,
69
+ pub fCheckRevocationFreshnessTime : i32 , // BOOL
70
70
pub dwRevocationFreshnessTime : u32 ,
71
71
pub pftCacheResync : * mut FILETIME ,
72
72
// XXX: `pStrongSignPara` and `dwStrongSignFlags` might or might not be defined on the current system. It started
@@ -230,7 +230,7 @@ impl CertEngine {
230
230
let mut config = CERT_CHAIN_ENGINE_CONFIG :: zeroed_with_size ( ) ;
231
231
config. hExclusiveRoot = exclusive_store. inner . as_ptr ( ) ;
232
232
233
- let mut engine = 0 ;
233
+ let mut engine = EnginePtr :: NULL ;
234
234
// SAFETY: `engine` is valid to be written to and the config is valid to be read.
235
235
let res = unsafe { CertCreateCertificateChainEngine ( & config, & mut engine) } ;
236
236
@@ -264,7 +264,7 @@ impl CertEngine {
264
264
config. dwFlags = CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL | CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE ;
265
265
config. hExclusiveRoot = root_store. inner . as_ptr ( ) ;
266
266
267
- let mut engine = 0 ;
267
+ let mut engine = EnginePtr :: NULL ;
268
268
// SAFETY: `engine` is valid to be written to and the config is valid to be read.
269
269
let res = unsafe { CertCreateCertificateChainEngine ( & config, & mut engine) } ;
270
270
@@ -276,17 +276,12 @@ impl CertEngine {
276
276
277
277
Ok ( Self { inner : engine } )
278
278
}
279
-
280
- #[ allow( clippy:: as_conversions) ]
281
- fn as_ptr ( & self ) -> isize {
282
- self . inner . as_ptr ( ) as isize
283
- }
284
279
}
285
280
286
281
impl Drop for CertEngine {
287
282
fn drop ( & mut self ) {
288
283
// SAFETY: The engine pointer is guaranteed to be non-null.
289
- unsafe { CertFreeCertificateChainEngine ( self . as_ptr ( ) ) } ;
284
+ unsafe { CertFreeCertificateChainEngine ( EnginePtr :: from_raw ( self . inner ) ) } ;
290
285
}
291
286
}
292
287
@@ -452,7 +447,10 @@ impl CertificateStore {
452
447
let parameters = NonNull :: from ( & parameters) . cast ( ) . as_ptr ( ) ;
453
448
454
449
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
+ } ,
456
454
certificate. inner . as_ptr ( ) ,
457
455
& time,
458
456
self . inner . as_ptr ( ) ,
@@ -472,6 +470,33 @@ impl CertificateStore {
472
470
}
473
471
}
474
472
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
+
475
500
fn call_with_last_error < T , F : FnMut ( ) -> Option < T > > ( mut call : F ) -> Result < T , TlsError > {
476
501
if let Some ( res) = call ( ) {
477
502
Ok ( res)
0 commit comments