Skip to content

Commit b4c73ab

Browse files
committed
Use Ref foreign type instead of forgetting
1 parent 8c3bca2 commit b4c73ab

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

boring/src/hmac.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::cvt;
22
use crate::error::ErrorStack;
3+
use crate::foreign_types::ForeignTypeRef;
34
use crate::hash::MessageDigest;
4-
use std::ffi::c_void;
5-
6-
use foreign_types::ForeignType;
75

86
foreign_type_and_impl_send_sync! {
97
type CType = ffi::HMAC_CTX;
@@ -12,7 +10,7 @@ foreign_type_and_impl_send_sync! {
1210
pub struct HmacCtx;
1311
}
1412

15-
impl HmacCtx {
13+
impl HmacCtxRef {
1614
/// Configures HmacCtx to use `md` as the hash function and `key` as the key.
1715
///
1816
/// https://commondatastorage.googleapis.com/chromium-boringssl-docs/hmac.h.html#HMAC_Init_ex
@@ -26,7 +24,7 @@ impl HmacCtx {
2624
unsafe {
2725
cvt(ffi::HMAC_Init_ex(
2826
self.as_ptr(),
29-
key.as_ptr() as *const c_void,
27+
key.as_ptr().cast(),
3028
key.len(),
3129
md.as_ptr(),
3230
// ENGINE api is deprecated

boring/src/ssl/callbacks.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use super::{
88
};
99
use crate::error::ErrorStack;
1010
use crate::ffi;
11-
use crate::hmac::HmacCtx;
11+
use crate::hmac::HmacCtxRef;
1212
use crate::ssl::TicketKeyCallbackResult;
13-
use crate::symm::CipherCtx;
13+
use crate::symm::CipherCtxRef;
1414
use crate::x509::{X509StoreContext, X509StoreContextRef};
1515
use foreign_types::ForeignType;
1616
use foreign_types::ForeignTypeRef;
1717
use libc::{c_char, c_int, c_uchar, c_uint, c_void};
1818
use std::ffi::CStr;
19-
use std::mem::{ManuallyDrop, MaybeUninit};
19+
use std::mem::MaybeUninit;
2020
use std::ptr;
2121
use std::slice;
2222
use std::str;
@@ -290,8 +290,8 @@ where
290290
&SslRef,
291291
&mut [u8; 16],
292292
&mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
293-
&mut CipherCtx,
294-
&mut HmacCtx,
293+
&mut CipherCtxRef,
294+
&mut HmacCtxRef,
295295
bool,
296296
) -> TicketKeyCallbackResult
297297
+ 'static
@@ -328,8 +328,8 @@ where
328328
let iv = unsafe { iv.assume_init_mut() };
329329

330330
// The EVP_CIPHER_CTX and HMAC_CTX are owned by boringSSL.
331-
let mut evp_ctx = ManuallyDrop::new(unsafe { CipherCtx::from_ptr(evp_ctx) });
332-
let mut hmac_ctx = ManuallyDrop::new(unsafe { HmacCtx::from_ptr(hmac_ctx) });
331+
let mut evp_ctx = unsafe { CipherCtxRef::from_ptr_mut(evp_ctx) };
332+
let mut hmac_ctx = unsafe { HmacCtxRef::from_ptr_mut(hmac_ctx) };
333333

334334
callback(ssl, key_name, iv, &mut evp_ctx, &mut hmac_ctx, encrypt).into()
335335
}

boring/src/ssl/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ use crate::dh::DhRef;
8181
use crate::ec::EcKeyRef;
8282
use crate::error::ErrorStack;
8383
use crate::ex_data::Index;
84-
use crate::hmac::HmacCtx;
84+
use crate::hmac::HmacCtxRef;
8585
use crate::nid::Nid;
8686
use crate::pkey::{HasPrivate, PKeyRef, Params, Private};
8787
use crate::srtp::{SrtpProtectionProfile, SrtpProtectionProfileRef};
8888
use crate::ssl::bio::BioMethod;
8989
use crate::ssl::callbacks::*;
9090
use crate::ssl::error::InnerError;
9191
use crate::stack::{Stack, StackRef, Stackable};
92-
use crate::symm::CipherCtx;
92+
use crate::symm::CipherCtxRef;
9393
use crate::x509::store::{X509Store, X509StoreBuilder, X509StoreBuilderRef, X509StoreRef};
9494
use crate::x509::verify::X509VerifyParamRef;
9595
use crate::x509::{
@@ -1258,8 +1258,8 @@ impl SslContextBuilder {
12581258
&SslRef,
12591259
&mut [u8; 16],
12601260
&mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
1261-
&mut CipherCtx,
1262-
&mut HmacCtx,
1261+
&mut CipherCtxRef,
1262+
&mut HmacCtxRef,
12631263
bool,
12641264
) -> TicketKeyCallbackResult
12651265
+ 'static

boring/src/ssl/test/session_resumption.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::server::Server;
22
use crate::ssl::test::MessageDigest;
3-
use crate::ssl::HmacCtx;
3+
use crate::ssl::HmacCtxRef;
44
use crate::ssl::SslRef;
55
use crate::ssl::SslSession;
66
use crate::ssl::SslSessionCacheMode;
77
use crate::ssl::TicketKeyCallbackResult;
88
use crate::symm::Cipher;
9-
use crate::symm::CipherCtx;
9+
use crate::symm::CipherCtxRef;
1010
use std::sync::atomic::{AtomicU8, Ordering};
1111
use std::sync::OnceLock;
1212

@@ -148,8 +148,8 @@ fn test_noop_tickey_key_callback(
148148
_ssl: &SslRef,
149149
key_name: &mut [u8; 16],
150150
iv: &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
151-
evp_ctx: &mut CipherCtx,
152-
hmac_ctx: &mut HmacCtx,
151+
evp_ctx: &mut CipherCtxRef,
152+
hmac_ctx: &mut HmacCtxRef,
153153
encrypt: bool,
154154
) -> TicketKeyCallbackResult {
155155
// These should only be used for testing purposes.
@@ -188,8 +188,8 @@ fn test_success_tickey_key_callback(
188188
_ssl: &SslRef,
189189
key_name: &mut [u8; 16],
190190
iv: &mut [u8; ffi::EVP_MAX_IV_LENGTH as usize],
191-
evp_ctx: &mut CipherCtx,
192-
hmac_ctx: &mut HmacCtx,
191+
evp_ctx: &mut CipherCtxRef,
192+
hmac_ctx: &mut HmacCtxRef,
193193
encrypt: bool,
194194
) -> TicketKeyCallbackResult {
195195
// These should only be used for testing purposes.

boring/src/symm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
//! ```
5454
5555
use crate::ffi;
56-
use foreign_types::ForeignType;
56+
use foreign_types::ForeignTypeRef;
5757
use libc::{c_int, c_uint};
5858
use openssl_macros::corresponds;
5959
use std::cmp;
@@ -76,7 +76,7 @@ foreign_type_and_impl_send_sync! {
7676
pub struct CipherCtx;
7777
}
7878

79-
impl CipherCtx {
79+
impl CipherCtxRef {
8080
/// Configures CipherCtx for a fresh encryption operation using `cipher`.
8181
///
8282
/// https://commondatastorage.googleapis.com/chromium-boringssl-docs/cipher.h.html#EVP_EncryptInit_ex

0 commit comments

Comments
 (0)