@@ -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
@@ -213,6 +213,30 @@ impl Drop for Certificate {
213
213
}
214
214
}
215
215
216
+ /// An abstraction trait over the different ways various `windows-sys` versions represent
217
+ /// the type of `HCERTCHAINENGINE`.
218
+ trait EnginePtr : Sized {
219
+ const NULL : Self ;
220
+ fn from_raw ( val : NonNull < c_void > ) -> Self ;
221
+ }
222
+
223
+ // `windows-sys` >= 0.60
224
+ impl EnginePtr for * mut c_void {
225
+ const NULL : Self = ptr:: null_mut ( ) ;
226
+ fn from_raw ( val : NonNull < c_void > ) -> Self {
227
+ val. as_ptr ( )
228
+ }
229
+ }
230
+
231
+ // `windows-sys` 0.52-0.59
232
+ impl EnginePtr for isize {
233
+ const NULL : Self = 0 ;
234
+ #[ allow( clippy:: as_conversions) ]
235
+ fn from_raw ( val : NonNull < c_void > ) -> Self {
236
+ val. as_ptr ( ) as isize
237
+ }
238
+ }
239
+
216
240
#[ derive( Debug ) ]
217
241
struct CertEngine {
218
242
inner : NonNull < c_void > , // HCERTENGINECONTEXT
@@ -230,7 +254,7 @@ impl CertEngine {
230
254
let mut config = CERT_CHAIN_ENGINE_CONFIG :: zeroed_with_size ( ) ;
231
255
config. hExclusiveRoot = exclusive_store. inner . as_ptr ( ) ;
232
256
233
- let mut engine = 0 ;
257
+ let mut engine = EnginePtr :: NULL ;
234
258
// SAFETY: `engine` is valid to be written to and the config is valid to be read.
235
259
let res = unsafe { CertCreateCertificateChainEngine ( & config, & mut engine) } ;
236
260
@@ -264,7 +288,7 @@ impl CertEngine {
264
288
config. dwFlags = CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL | CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE ;
265
289
config. hExclusiveRoot = root_store. inner . as_ptr ( ) ;
266
290
267
- let mut engine = 0 ;
291
+ let mut engine = EnginePtr :: NULL ;
268
292
// SAFETY: `engine` is valid to be written to and the config is valid to be read.
269
293
let res = unsafe { CertCreateCertificateChainEngine ( & config, & mut engine) } ;
270
294
@@ -276,17 +300,12 @@ impl CertEngine {
276
300
277
301
Ok ( Self { inner : engine } )
278
302
}
279
-
280
- #[ allow( clippy:: as_conversions) ]
281
- fn as_ptr ( & self ) -> isize {
282
- self . inner . as_ptr ( ) as isize
283
- }
284
303
}
285
304
286
305
impl Drop for CertEngine {
287
306
fn drop ( & mut self ) {
288
307
// SAFETY: The engine pointer is guaranteed to be non-null.
289
- unsafe { CertFreeCertificateChainEngine ( self . as_ptr ( ) ) } ;
308
+ unsafe { CertFreeCertificateChainEngine ( EnginePtr :: from_raw ( self . inner ) ) } ;
290
309
}
291
310
}
292
311
@@ -452,7 +471,9 @@ impl CertificateStore {
452
471
let parameters = NonNull :: from ( & parameters) . cast ( ) . as_ptr ( ) ;
453
472
454
473
CertGetCertificateChain (
455
- engine. map ( CertEngine :: as_ptr) . unwrap_or ( 0 ) ,
474
+ engine
475
+ . map ( |eng| EnginePtr :: from_raw ( eng. inner ) )
476
+ . unwrap_or ( EnginePtr :: NULL ) ,
456
477
certificate. inner . as_ptr ( ) ,
457
478
& time,
458
479
self . inner . as_ptr ( ) ,
0 commit comments