From cab770c71343ecce84e2b32e8185eca10d58c8a9 Mon Sep 17 00:00:00 2001 From: ComplexSpaces Date: Fri, 23 Aug 2024 19:59:29 -0500 Subject: [PATCH] Merge Windows helper module into the verifier impl There is no longer enough code to justify it being split up --- rustls-platform-verifier/src/lib.rs | 3 -- .../src/verification/windows.rs | 31 ++++++++++++++++- rustls-platform-verifier/src/windows.rs | 34 ------------------- 3 files changed, 30 insertions(+), 38 deletions(-) delete mode 100644 rustls-platform-verifier/src/windows.rs diff --git a/rustls-platform-verifier/src/lib.rs b/rustls-platform-verifier/src/lib.rs index 23a13e46..975ad0dc 100644 --- a/rustls-platform-verifier/src/lib.rs +++ b/rustls-platform-verifier/src/lib.rs @@ -15,9 +15,6 @@ pub use verification::Verifier; #[cfg_attr(docsrs, doc(cfg(target_os = "android")))] pub mod android; -#[cfg(windows)] -mod windows; - /// Fixures and data to support testing the server /// certificate verifier. #[cfg(any(test, feature = "ffi-testing"))] diff --git a/rustls-platform-verifier/src/verification/windows.rs b/rustls-platform-verifier/src/verification/windows.rs index 7a1d7145..3bdc73f9 100644 --- a/rustls-platform-verifier/src/verification/windows.rs +++ b/rustls-platform-verifier/src/verification/windows.rs @@ -19,7 +19,6 @@ //! [Microsoft's Example]: use super::{log_server_cert, ALLOWED_EKUS}; -use crate::windows::{nonnull_from_const_ptr, ZeroedWithSize}; use once_cell::sync::OnceCell; use rustls::client::danger::{HandshakeSignatureValid, ServerCertVerifier}; use rustls::crypto::{verify_tls12_signature, verify_tls13_signature, CryptoProvider}; @@ -630,3 +629,33 @@ impl Default for Verifier { Self::new() } } + +/// A trait to represent an object that can be safely created with all zero values +/// and have a size assigned to it. +/// +/// # Safety +/// +/// This has the same safety requirements as [std::mem::zeroed]. +unsafe trait ZeroedWithSize: Sized { + const SIZE: u32 = { + let size = core::mem::size_of::(); + + // NB: `TryInto` isn't stable in const yet. + #[allow(clippy::as_conversions)] + if size <= u32::MAX as usize { + size as u32 + } else { + panic!("structure was larger then DWORD") + } + }; + + /// Returns a zeroed structure with its structure size (`cbSize`) field set to the correct value. + fn zeroed_with_size() -> Self; +} + +/// Returns `p` as a `NonNull`, erasing its `const`-ness. +/// +/// The conversion is done in the most type-safe way possible. +fn nonnull_from_const_ptr(p: *const T) -> Option> { + NonNull::new(p as *mut T) +} diff --git a/rustls-platform-verifier/src/windows.rs b/rustls-platform-verifier/src/windows.rs deleted file mode 100644 index ab2f2cdb..00000000 --- a/rustls-platform-verifier/src/windows.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! Utilities to deal with weird aspects of interfacing with Windows through `winapi`. -#![allow(clippy::as_conversions)] - -use std::ptr::NonNull; - -/// A trait to represent an object that can be safely created with all zero values -/// and have a size assigned to it. -/// -/// # Safety -/// -/// This has the same safety requirements as [std::mem::zeroed]. -pub(crate) unsafe trait ZeroedWithSize: Sized { - const SIZE: u32 = { - let size = core::mem::size_of::(); - - // NB: `TryInto` isn't stable in const yet. - #[allow(clippy::as_conversions)] - if size <= u32::MAX as usize { - size as u32 - } else { - panic!("structure was larger then DWORD") - } - }; - - /// Returns a zeroed structure with its structure size (`cbsize`) field set to the correct value. - fn zeroed_with_size() -> Self; -} - -/// Returns `p` as a `NonNull`, erasing its `const`-ness. -/// -/// The conversion is done in the most type-safe way possible. -pub(crate) fn nonnull_from_const_ptr(p: *const T) -> Option> { - NonNull::new(p as *mut T) -}