Skip to content

Commit

Permalink
Merge Windows helper module into the verifier impl
Browse files Browse the repository at this point in the history
There is no longer enough code to justify it being split up
  • Loading branch information
complexspaces committed Aug 24, 2024
1 parent 1a2da5f commit cab770c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
3 changes: 0 additions & 3 deletions rustls-platform-verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
31 changes: 30 additions & 1 deletion rustls-platform-verifier/src/verification/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! [Microsoft's Example]: <https://docs.microsoft.com/en-us/windows/win32/seccrypto/example-c-program-creating-a-certificate-chain>
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};
Expand Down Expand Up @@ -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::<Self>();

// 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<T>`, erasing its `const`-ness.
///
/// The conversion is done in the most type-safe way possible.
fn nonnull_from_const_ptr<T>(p: *const T) -> Option<NonNull<T>> {
NonNull::new(p as *mut T)
}
34 changes: 0 additions & 34 deletions rustls-platform-verifier/src/windows.rs

This file was deleted.

0 comments on commit cab770c

Please sign in to comment.