11use super :: server:: Server ;
22use crate :: ssl:: test:: MessageDigest ;
3+ use crate :: ssl:: HmacCtx ;
34use crate :: ssl:: SslRef ;
45use crate :: ssl:: SslSession ;
56use crate :: ssl:: SslSessionCacheMode ;
67use crate :: ssl:: TicketKeyCallbackResult ;
78use crate :: symm:: Cipher ;
8- use std :: ffi :: c_void ;
9+ use crate :: symm :: CipherCtx ;
910use std:: sync:: atomic:: { AtomicU8 , Ordering } ;
1011use std:: sync:: OnceLock ;
1112
@@ -60,7 +61,7 @@ fn custom_callback_success() {
6061 unsafe {
6162 server
6263 . ctx ( )
63- . set_ticket_key_callback_unsafe ( test_success_tickey_key_callback)
64+ . set_ticket_key_callback ( test_success_tickey_key_callback)
6465 } ;
6566 let server = server. build ( ) ;
6667
@@ -105,7 +106,7 @@ fn custom_callback_unrecognized_decryption_ticket() {
105106 unsafe {
106107 server
107108 . ctx ( )
108- . set_ticket_key_callback_unsafe ( test_noop_tickey_key_callback)
109+ . set_ticket_key_callback ( test_noop_tickey_key_callback)
109110 } ;
110111 let server = server. build ( ) ;
111112
@@ -147,8 +148,8 @@ fn test_noop_tickey_key_callback(
147148 _ssl : & SslRef ,
148149 key_name : & mut [ u8 ; 16 ] ,
149150 iv : & mut [ u8 ; ffi:: EVP_MAX_IV_LENGTH as usize ] ,
150- evp_ctx : * mut ffi :: EVP_CIPHER_CTX ,
151- hmac_ctx : * mut ffi :: HMAC_CTX ,
151+ evp_ctx : & mut CipherCtx ,
152+ hmac_ctx : & mut HmacCtx ,
152153 encrypt : bool ,
153154) -> TicketKeyCallbackResult {
154155 // These should only be used for testing purposes.
@@ -164,31 +165,16 @@ fn test_noop_tickey_key_callback(
164165 assert_eq ! ( iv, & [ 0 ; 16 ] ) ;
165166
166167 NOOP_ENCRYPTION_CALLED_BACK . fetch_add ( 1 , Ordering :: SeqCst ) ;
168+
167169 // Set the encryption context.
168- let ret = unsafe {
169- ffi:: EVP_EncryptInit_ex (
170- evp_ctx,
171- cipher. as_ptr ( ) ,
172- // ENGINE api is deprecated
173- core:: ptr:: null_mut ( ) ,
174- TEST_AES_128_CBC_KEY . as_ptr ( ) ,
175- TEST_CBC_IV . as_ptr ( ) ,
176- )
170+ unsafe {
171+ evp_ctx
172+ . init_encrypt ( & cipher, & TEST_AES_128_CBC_KEY , & TEST_CBC_IV )
173+ . unwrap ( )
177174 } ;
178- assert ! ( ret == 1 ) ;
179175
180176 // Set the hmac context.
181- let ret = unsafe {
182- ffi:: HMAC_Init_ex (
183- hmac_ctx,
184- TEST_HMAC_KEY . as_ptr ( ) as * const c_void ,
185- TEST_HMAC_KEY . len ( ) ,
186- digest. as_ptr ( ) ,
187- // ENGINE api is deprecated
188- core:: ptr:: null_mut ( ) ,
189- )
190- } ;
191- assert ! ( ret == 1 ) ;
177+ unsafe { hmac_ctx. init ( & TEST_HMAC_KEY , & digest) . unwrap ( ) } ;
192178
193179 TicketKeyCallbackResult :: Success
194180 } else {
@@ -202,8 +188,8 @@ fn test_success_tickey_key_callback(
202188 _ssl : & SslRef ,
203189 key_name : & mut [ u8 ; 16 ] ,
204190 iv : & mut [ u8 ; ffi:: EVP_MAX_IV_LENGTH as usize ] ,
205- evp_ctx : * mut ffi :: EVP_CIPHER_CTX ,
206- hmac_ctx : * mut ffi :: HMAC_CTX ,
191+ evp_ctx : & mut CipherCtx ,
192+ hmac_ctx : & mut HmacCtx ,
207193 encrypt : bool ,
208194) -> TicketKeyCallbackResult {
209195 // These should only be used for testing purposes.
@@ -219,58 +205,27 @@ fn test_success_tickey_key_callback(
219205 assert_eq ! ( iv, & [ 0 ; 16 ] ) ;
220206
221207 SUCCESS_ENCRYPTION_CALLED_BACK . fetch_add ( 1 , Ordering :: SeqCst ) ;
208+
222209 // Set the encryption context.
223- let ret = unsafe {
224- ffi:: EVP_EncryptInit_ex (
225- evp_ctx,
226- cipher. as_ptr ( ) ,
227- // ENGINE api is deprecated
228- core:: ptr:: null_mut ( ) ,
229- TEST_AES_128_CBC_KEY . as_ptr ( ) ,
230- TEST_CBC_IV . as_ptr ( ) ,
231- )
210+ unsafe {
211+ evp_ctx
212+ . init_encrypt ( & cipher, & TEST_AES_128_CBC_KEY , & TEST_CBC_IV )
213+ . unwrap ( )
232214 } ;
233- assert ! ( ret == 1 ) ;
234215
235216 // Set the hmac context.
236- let ret = unsafe {
237- ffi:: HMAC_Init_ex (
238- hmac_ctx,
239- TEST_HMAC_KEY . as_ptr ( ) as * const c_void ,
240- TEST_HMAC_KEY . len ( ) ,
241- digest. as_ptr ( ) ,
242- // ENGINE api is deprecated
243- core:: ptr:: null_mut ( ) ,
244- )
245- } ;
246- assert ! ( ret == 1 ) ;
217+ unsafe { hmac_ctx. init ( & TEST_HMAC_KEY , & digest) . unwrap ( ) } ;
247218 } else {
248219 SUCCESS_DECRYPTION_CALLED_BACK . fetch_add ( 1 , Ordering :: SeqCst ) ;
249220 // Set the decryption context.
250- let ret = unsafe {
251- ffi:: EVP_DecryptInit_ex (
252- evp_ctx,
253- cipher. as_ptr ( ) ,
254- // ENGINE api is deprecated
255- core:: ptr:: null_mut ( ) ,
256- TEST_AES_128_CBC_KEY . as_ptr ( ) ,
257- TEST_CBC_IV . as_ptr ( ) ,
258- )
221+ unsafe {
222+ evp_ctx
223+ . init_decrypt ( & cipher, & TEST_AES_128_CBC_KEY , & TEST_CBC_IV )
224+ . unwrap ( )
259225 } ;
260- assert ! ( ret == 1 ) ;
261226
262227 // Set the hmac context.
263- let ret = unsafe {
264- ffi:: HMAC_Init_ex (
265- hmac_ctx,
266- TEST_HMAC_KEY . as_ptr ( ) as * const c_void ,
267- TEST_HMAC_KEY . len ( ) ,
268- digest. as_ptr ( ) ,
269- // ENGINE api is deprecated
270- core:: ptr:: null_mut ( ) ,
271- )
272- } ;
273- assert ! ( ret == 1 ) ;
228+ unsafe { hmac_ctx. init ( & TEST_HMAC_KEY , & digest) . unwrap ( ) } ;
274229 }
275230
276231 TicketKeyCallbackResult :: Success
0 commit comments