Use Ref foreign type instead of forgetting

This commit is contained in:
Kornel 2025-10-01 03:38:59 +01:00 committed by Kornel
parent ab8513ef8f
commit 8773f0e1fa
5 changed files with 23 additions and 25 deletions

View File

@ -1,9 +1,7 @@
use crate::cvt; use crate::cvt;
use crate::error::ErrorStack; use crate::error::ErrorStack;
use crate::foreign_types::ForeignTypeRef;
use crate::hash::MessageDigest; use crate::hash::MessageDigest;
use std::ffi::c_void;
use foreign_types::ForeignType;
foreign_type_and_impl_send_sync! { foreign_type_and_impl_send_sync! {
type CType = ffi::HMAC_CTX; type CType = ffi::HMAC_CTX;
@ -12,7 +10,7 @@ foreign_type_and_impl_send_sync! {
pub struct HmacCtx; pub struct HmacCtx;
} }
impl HmacCtx { impl HmacCtxRef {
/// Configures HmacCtx to use `md` as the hash function and `key` as the key. /// Configures HmacCtx to use `md` as the hash function and `key` as the key.
/// ///
/// https://commondatastorage.googleapis.com/chromium-boringssl-docs/hmac.h.html#HMAC_Init_ex /// https://commondatastorage.googleapis.com/chromium-boringssl-docs/hmac.h.html#HMAC_Init_ex
@ -26,7 +24,7 @@ impl HmacCtx {
unsafe { unsafe {
cvt(ffi::HMAC_Init_ex( cvt(ffi::HMAC_Init_ex(
self.as_ptr(), self.as_ptr(),
key.as_ptr() as *const c_void, key.as_ptr().cast(),
key.len(), key.len(),
md.as_ptr(), md.as_ptr(),
// ENGINE api is deprecated // ENGINE api is deprecated

View File

@ -8,15 +8,15 @@ use super::{
}; };
use crate::error::ErrorStack; use crate::error::ErrorStack;
use crate::ffi; use crate::ffi;
use crate::hmac::HmacCtx; use crate::hmac::HmacCtxRef;
use crate::ssl::TicketKeyCallbackResult; use crate::ssl::TicketKeyCallbackResult;
use crate::symm::CipherCtx; use crate::symm::CipherCtxRef;
use crate::x509::{X509StoreContext, X509StoreContextRef}; use crate::x509::{X509StoreContext, X509StoreContextRef};
use foreign_types::ForeignType; use foreign_types::ForeignType;
use foreign_types::ForeignTypeRef; use foreign_types::ForeignTypeRef;
use libc::{c_char, c_int, c_uchar, c_uint, c_void}; use libc::{c_char, c_int, c_uchar, c_uint, c_void};
use std::ffi::CStr; use std::ffi::CStr;
use std::mem::{ManuallyDrop, MaybeUninit}; use std::mem::MaybeUninit;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
use std::str; use std::str;
@ -290,8 +290,8 @@ where
&SslRef, &SslRef,
&mut [u8; 16], &mut [u8; 16],
&mut [u8; ffi::EVP_MAX_IV_LENGTH as usize], &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
&mut CipherCtx, &mut CipherCtxRef,
&mut HmacCtx, &mut HmacCtxRef,
bool, bool,
) -> TicketKeyCallbackResult ) -> TicketKeyCallbackResult
+ 'static + 'static
@ -328,10 +328,10 @@ where
let iv = unsafe { iv.assume_init_mut() }; let iv = unsafe { iv.assume_init_mut() };
// The EVP_CIPHER_CTX and HMAC_CTX are owned by boringSSL. // The EVP_CIPHER_CTX and HMAC_CTX are owned by boringSSL.
let mut evp_ctx = ManuallyDrop::new(unsafe { CipherCtx::from_ptr(evp_ctx) }); let evp_ctx = unsafe { CipherCtxRef::from_ptr_mut(evp_ctx) };
let mut hmac_ctx = ManuallyDrop::new(unsafe { HmacCtx::from_ptr(hmac_ctx) }); let hmac_ctx = unsafe { HmacCtxRef::from_ptr_mut(hmac_ctx) };
callback(ssl, key_name, iv, &mut evp_ctx, &mut hmac_ctx, encrypt).into() callback(ssl, key_name, iv, evp_ctx, hmac_ctx, encrypt).into()
} }
pub(super) unsafe extern "C" fn raw_alpn_select<F>( pub(super) unsafe extern "C" fn raw_alpn_select<F>(

View File

@ -81,7 +81,7 @@ use crate::dh::DhRef;
use crate::ec::EcKeyRef; use crate::ec::EcKeyRef;
use crate::error::ErrorStack; use crate::error::ErrorStack;
use crate::ex_data::Index; use crate::ex_data::Index;
use crate::hmac::HmacCtx; use crate::hmac::HmacCtxRef;
use crate::nid::Nid; use crate::nid::Nid;
use crate::pkey::{HasPrivate, PKeyRef, Params, Private}; use crate::pkey::{HasPrivate, PKeyRef, Params, Private};
use crate::srtp::{SrtpProtectionProfile, SrtpProtectionProfileRef}; use crate::srtp::{SrtpProtectionProfile, SrtpProtectionProfileRef};
@ -89,7 +89,7 @@ use crate::ssl::bio::BioMethod;
use crate::ssl::callbacks::*; use crate::ssl::callbacks::*;
use crate::ssl::error::InnerError; use crate::ssl::error::InnerError;
use crate::stack::{Stack, StackRef, Stackable}; use crate::stack::{Stack, StackRef, Stackable};
use crate::symm::CipherCtx; use crate::symm::CipherCtxRef;
use crate::x509::store::{X509Store, X509StoreBuilder, X509StoreBuilderRef, X509StoreRef}; use crate::x509::store::{X509Store, X509StoreBuilder, X509StoreBuilderRef, X509StoreRef};
use crate::x509::verify::X509VerifyParamRef; use crate::x509::verify::X509VerifyParamRef;
use crate::x509::{ use crate::x509::{
@ -1158,8 +1158,8 @@ impl SslContextBuilder {
&SslRef, &SslRef,
&mut [u8; 16], &mut [u8; 16],
&mut [u8; ffi::EVP_MAX_IV_LENGTH as usize], &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
&mut CipherCtx, &mut CipherCtxRef,
&mut HmacCtx, &mut HmacCtxRef,
bool, bool,
) -> TicketKeyCallbackResult ) -> TicketKeyCallbackResult
+ 'static + 'static

View File

@ -1,12 +1,12 @@
use super::server::Server; use super::server::Server;
use crate::ssl::test::MessageDigest; use crate::ssl::test::MessageDigest;
use crate::ssl::HmacCtx; use crate::ssl::HmacCtxRef;
use crate::ssl::SslRef; use crate::ssl::SslRef;
use crate::ssl::SslSession; use crate::ssl::SslSession;
use crate::ssl::SslSessionCacheMode; use crate::ssl::SslSessionCacheMode;
use crate::ssl::TicketKeyCallbackResult; use crate::ssl::TicketKeyCallbackResult;
use crate::symm::Cipher; use crate::symm::Cipher;
use crate::symm::CipherCtx; use crate::symm::CipherCtxRef;
use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::OnceLock; use std::sync::OnceLock;
@ -148,8 +148,8 @@ fn test_noop_tickey_key_callback(
_ssl: &SslRef, _ssl: &SslRef,
key_name: &mut [u8; 16], key_name: &mut [u8; 16],
iv: &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize], iv: &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
evp_ctx: &mut CipherCtx, evp_ctx: &mut CipherCtxRef,
hmac_ctx: &mut HmacCtx, hmac_ctx: &mut HmacCtxRef,
encrypt: bool, encrypt: bool,
) -> TicketKeyCallbackResult { ) -> TicketKeyCallbackResult {
// These should only be used for testing purposes. // These should only be used for testing purposes.
@ -188,8 +188,8 @@ fn test_success_tickey_key_callback(
_ssl: &SslRef, _ssl: &SslRef,
key_name: &mut [u8; 16], key_name: &mut [u8; 16],
iv: &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize], iv: &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
evp_ctx: &mut CipherCtx, evp_ctx: &mut CipherCtxRef,
hmac_ctx: &mut HmacCtx, hmac_ctx: &mut HmacCtxRef,
encrypt: bool, encrypt: bool,
) -> TicketKeyCallbackResult { ) -> TicketKeyCallbackResult {
// These should only be used for testing purposes. // These should only be used for testing purposes.

View File

@ -53,7 +53,7 @@
//! ``` //! ```
use crate::ffi; use crate::ffi;
use foreign_types::ForeignType; use foreign_types::ForeignTypeRef;
use libc::{c_int, c_uint}; use libc::{c_int, c_uint};
use openssl_macros::corresponds; use openssl_macros::corresponds;
use std::cmp; use std::cmp;
@ -76,7 +76,7 @@ foreign_type_and_impl_send_sync! {
pub struct CipherCtx; pub struct CipherCtx;
} }
impl CipherCtx { impl CipherCtxRef {
/// Configures CipherCtx for a fresh encryption operation using `cipher`. /// Configures CipherCtx for a fresh encryption operation using `cipher`.
/// ///
/// https://commondatastorage.googleapis.com/chromium-boringssl-docs/cipher.h.html#EVP_EncryptInit_ex /// https://commondatastorage.googleapis.com/chromium-boringssl-docs/cipher.h.html#EVP_EncryptInit_ex