3838//! ```
3939//!
4040use crate :: ffi;
41- use libc:: { c_int, c_uint, size_t } ;
41+ use libc:: { c_int, c_uint} ;
4242use openssl_macros:: corresponds;
4343use std:: mem:: MaybeUninit ;
4444use std:: ptr;
@@ -63,7 +63,7 @@ impl AesKey {
6363
6464 let mut aes_key = MaybeUninit :: uninit ( ) ;
6565 let r = ffi:: AES_set_encrypt_key (
66- key. as_ptr ( ) as * const _ ,
66+ key. as_ptr ( ) ,
6767 key. len ( ) as c_uint * 8 ,
6868 aes_key. as_mut_ptr ( ) ,
6969 ) ;
@@ -87,7 +87,7 @@ impl AesKey {
8787
8888 let mut aes_key = MaybeUninit :: uninit ( ) ;
8989 let r = ffi:: AES_set_decrypt_key (
90- key. as_ptr ( ) as * const _ ,
90+ key. as_ptr ( ) ,
9191 key. len ( ) as c_uint * 8 ,
9292 aes_key. as_mut_ptr ( ) ,
9393 ) ;
@@ -125,12 +125,11 @@ pub fn wrap_key(
125125 assert ! ( out. len( ) >= in_. len( ) + 8 ) ; // Ciphertext is 64 bits longer (see 2.2.1)
126126
127127 let written = ffi:: AES_wrap_key (
128- & key. 0 as * const _ as * mut _ , // this is safe, the implementation only uses the key as a const pointer.
129- iv. as_ref ( )
130- . map_or ( ptr:: null ( ) , |iv| iv. as_ptr ( ) as * const _ ) ,
131- out. as_ptr ( ) as * mut _ ,
132- in_. as_ptr ( ) as * const _ ,
133- in_. len ( ) as size_t ,
128+ std:: ptr:: addr_of!( key. 0 ) . cast_mut ( ) , // this is safe, the implementation only uses the key as a const pointer.
129+ iv. as_ref ( ) . map_or ( ptr:: null ( ) , |iv| iv. as_ptr ( ) ) ,
130+ out. as_mut_ptr ( ) ,
131+ in_. as_ptr ( ) ,
132+ in_. len ( ) ,
134133 ) ;
135134 if written <= 0 {
136135 Err ( KeyError ( ( ) ) )
@@ -164,12 +163,11 @@ pub fn unwrap_key(
164163 assert ! ( out. len( ) + 8 <= in_. len( ) ) ;
165164
166165 let written = ffi:: AES_unwrap_key (
167- & key. 0 as * const _ as * mut _ , // this is safe, the implementation only uses the key as a const pointer.
168- iv. as_ref ( )
169- . map_or ( ptr:: null ( ) , |iv| iv. as_ptr ( ) as * const _ ) ,
170- out. as_ptr ( ) as * mut _ ,
171- in_. as_ptr ( ) as * const _ ,
172- in_. len ( ) as size_t ,
166+ std:: ptr:: addr_of!( key. 0 ) . cast_mut ( ) , // this is safe, the implementation only uses the key as a const pointer.
167+ iv. as_ref ( ) . map_or ( ptr:: null ( ) , |iv| iv. as_ptr ( ) . cast ( ) ) ,
168+ out. as_ptr ( ) . cast_mut ( ) ,
169+ in_. as_ptr ( ) . cast ( ) ,
170+ in_. len ( ) ,
173171 ) ;
174172
175173 if written <= 0 {
0 commit comments