@@ -140,12 +140,15 @@ impl MessageEncrypter for WCTls12Encrypter {
140140 // 8 bytes.
141141 let payload_start = GCM_NONCE_LENGTH - 4 ;
142142 let payload_end = m. payload . len ( ) + ( GCM_NONCE_LENGTH - 4 ) ;
143+ let buf = & mut payload. as_mut ( ) [ payload_start..payload_end] ;
144+ let buf_len = buf. len ( ) as word32 ;
145+ let buf_ptr = buf. as_mut_ptr ( ) ;
143146 ret = unsafe {
144147 wc_AesGcmEncrypt (
145148 aes_object. as_ptr ( ) ,
146- payload . as_mut ( ) [ payload_start..payload_end ] . as_mut_ptr ( ) ,
147- payload . as_ref ( ) [ payload_start..payload_end ] . as_ptr ( ) ,
148- payload . as_ref ( ) [ payload_start..payload_end ] . len ( ) as word32 ,
149+ buf_ptr ,
150+ buf_ptr as * const u8 ,
151+ buf_len ,
149152 nonce. as_ptr ( ) ,
150153 nonce. len ( ) as word32 ,
151154 auth_tag. as_mut_ptr ( ) ,
@@ -173,7 +176,7 @@ impl MessageDecrypter for WCTls12Decrypter {
173176 seq : u64 ,
174177 ) -> Result < InboundPlainMessage < ' a > , rustls:: Error > {
175178 let payload = & mut m. payload ;
176- if payload. len ( ) < GCM_TAG_LENGTH {
179+ if payload. len ( ) < ( GCM_NONCE_LENGTH - 4 ) + GCM_TAG_LENGTH {
177180 return Err ( rustls:: Error :: DecryptError ) ;
178181 }
179182 let payload_len = payload. len ( ) ;
@@ -212,15 +215,15 @@ impl MessageDecrypter for WCTls12Decrypter {
212215 // from the payload.
213216 let payload_start = GCM_NONCE_LENGTH - 4 ;
214217 let payload_end = payload_len - GCM_TAG_LENGTH ;
218+ let buf = & mut payload[ payload_start..payload_end] ;
219+ let buf_len = buf. len ( ) as word32 ;
220+ let buf_ptr = buf. as_mut_ptr ( ) ;
215221 ret = unsafe {
216222 wc_AesGcmDecrypt (
217223 aes_object. as_ptr ( ) ,
218- payload[ payload_start..payload_end] . as_mut_ptr ( ) ,
219- payload[ payload_start..payload_end] . as_ptr ( ) ,
220- payload[ payload_start..payload_end]
221- . len ( )
222- . try_into ( )
223- . unwrap ( ) ,
224+ buf_ptr,
225+ buf_ptr as * const u8 ,
226+ buf_len,
224227 nonce. as_ptr ( ) ,
225228 nonce. len ( ) as word32 ,
226229 auth_tag. as_ptr ( ) ,
@@ -318,12 +321,15 @@ impl MessageEncrypter for WCTls13Cipher {
318321 // authIn, into the authentication tag, authTag.
319322 // Apparently we need to also need to include for the encoding type into the encrypted
320323 // payload, hence the + 1 otherwise the rustls returns EoF.
324+ let buf = & mut payload. as_mut ( ) [ ..payload_len + 1 ] ;
325+ let buf_len = buf. len ( ) as word32 ;
326+ let buf_ptr = buf. as_mut_ptr ( ) ;
321327 ret = unsafe {
322328 wc_AesGcmEncrypt (
323329 aes_object. as_ptr ( ) ,
324- payload . as_mut ( ) [ ..payload_len + 1 ] . as_mut_ptr ( ) ,
325- payload . as_ref ( ) [ ..payload_len + 1 ] . as_ptr ( ) ,
326- payload . as_ref ( ) [ ..payload_len + 1 ] . len ( ) as word32 ,
330+ buf_ptr ,
331+ buf_ptr as * const u8 ,
332+ buf_len ,
327333 nonce. 0 . as_ptr ( ) ,
328334 nonce. 0 . len ( ) as word32 ,
329335 auth_tag. as_mut_ptr ( ) ,
@@ -384,12 +390,15 @@ impl MessageDecrypter for WCTls13Cipher {
384390
385391 // Finally, we have everything to decrypt the message
386392 // from the payload.
393+ let buf = & mut payload[ ..message_len] ;
394+ let buf_len = buf. len ( ) as word32 ;
395+ let buf_ptr = buf. as_mut_ptr ( ) ;
387396 ret = unsafe {
388397 wc_AesGcmDecrypt (
389398 aes_object. as_ptr ( ) ,
390- payload [ ..message_len ] . as_mut_ptr ( ) ,
391- payload [ ..message_len ] . as_ptr ( ) ,
392- payload [ ..message_len ] . len ( ) . try_into ( ) . unwrap ( ) ,
399+ buf_ptr ,
400+ buf_ptr as * const u8 ,
401+ buf_len ,
393402 nonce. 0 . as_ptr ( ) ,
394403 nonce. 0 . len ( ) as word32 ,
395404 auth_tag. as_ptr ( ) ,
0 commit comments