fn send_encrypted_record<W5500: Registers>(
        &mut self,
        w5500: &mut W5500,
        content_type: ContentType,
        data: &[u8],
    ) -> Result<(), HlError<W5500::Error>> {
        const CONTENT_TYPE_LEN: usize = 1;
        let data_len: u16 = unwrap!((data.len() + GCM_TAG_LEN + CONTENT_TYPE_LEN).try_into());

        let header: [u8; 5] = [
            ContentType::ApplicationData.into(),
            TlsVersion::V1_2.msb(),
            TlsVersion::V1_2.lsb(),
            (data_len >> 8) as u8,
            data_len as u8,
        ];

        let mut writer: TcpWriter<W5500> = w5500.tcp_writer(self.sn)?;

        // write the record header
        writer.write_all(&header)?;

        let (key, nonce): ([u8; 16], [u8; 12]) = self.key_schedule.client_key_and_nonce().unwrap();
        let mut cipher = crate::crypto::Aes128Gcm::new(&key, &nonce, &header);

        // write the record data in 128-bit chunks
        let mut chunks = data.chunks_exact(16);
        for chunk in &mut chunks {
            let mut mut_chunck: [u8; 16] = chunk.try_into().unwrap();
            cipher.encrypt_block_inplace(&mut mut_chunck);
            writer.write_all(&mut_chunck)?;
        }

        // write the remaining data
        let rem = chunks.remainder();
        let mut padded_block: [u8; 16] = [0; 16];
        padded_block[..rem.len()].copy_from_slice(rem);
        // append the content type
        padded_block[rem.len()] = content_type as u8;
        let remainder_len: usize = rem.len() + CONTENT_TYPE_LEN;
        cipher.encrypt_remainder_inplace(&mut padded_block, remainder_len);
        writer.write_all(&padded_block[..remainder_len])?;

        // write the AES-GCM authentication tag
        let tag: [u8; GCM_TAG_LEN] = cipher.finish();
        writer.write_all(&tag)?;
        writer.send()?;

        Ok(())
    }
// helper to send an encrypted record without a round-trip to the socket
// buffers
helper to send an encrypted record without a round-trip to the socket
buffers
helper to send an encrypted record without a round - trip to the socket buffers
fn send_encrypted_record<W5500: Registers>(
        &mut self,
        w5500: &mut W5500,
        content_type: ContentType,
        data: &[u8],
    ) -> Result<(), HlError<W5500::Error>> {
        const CONTENT_TYPE_LEN: usize = 1;
        let data_len: u16 = unwrap!((data.len() + GCM_TAG_LEN + CONTENT_TYPE_LEN).try_into());
        let header: [u8; 5] = [
            ContentType::ApplicationData.into(),
            TlsVersion::V1_2.msb(),
            TlsVersion::V1_2.lsb(),
            (data_len >> 8) as u8,
            data_len as u8,
        ];
        let mut writer: TcpWriter<W5500> = w5500.tcp_writer(self.sn)?;
        // write the record header
        writer.write_all(&header)?;
        let (key, nonce): ([u8; 16], [u8; 12]) = self.key_schedule.client_key_and_nonce().unwrap();
        let mut cipher = crate::crypto::Aes128Gcm::new(&key, &nonce, &header);
        // write the record data in 128-bit chunks
        let mut chunks = data.chunks_exact(16);
        for chunk in &mut chunks {
            let mut mut_chunck: [u8; 16] = chunk.try_into().unwrap();
            cipher.encrypt_block_inplace(&mut mut_chunck);
            writer.write_all(&mut_chunck)?;
        }
        // write the remaining data
        let rem = chunks.remainder();
        let mut padded_block: [u8; 16] = [0; 16];
        padded_block[..rem.len()].copy_from_slice(rem);
        // append the content type
        padded_block[rem.len()] = content_type as u8;
        let remainder_len: usize = rem.len() + CONTENT_TYPE_LEN;
        cipher.encrypt_remainder_inplace(&mut padded_block, remainder_len);
        writer.write_all(&padded_block[..remainder_len])?;
        // write the AES-GCM authentication tag
        let tag: [u8; GCM_TAG_LEN] = cipher.finish();
        writer.write_all(&tag)?;
        writer.send()?;
        Ok(())
    }
fn send_encrypted_record < W5500 : Registers > ( & mut self , w5500 : & mut W5500 , content_type : ContentType , data : & [ u8 ] , ) -> Result < ( ) , HlError < W5500 :: Error > > { const CONTENT_TYPE_LEN : usize = 1 ; let data_len : u16 = unwrap ! ( ( data len ( ) GCM_TAG_LEN CONTENT_TYPE_LEN ) try_into ( ) ) ; let header : [ u8 ; 5 ] = [ ContentType :: ApplicationData . into ( ) , TlsVersion :: V1_2 . msb ( ) , TlsVersion :: V1_2 . lsb ( ) , ( data_len >> 8 ) as u8 , data_len as u8 , ] ; let mut writer : TcpWriter < W5500 > = w5500 . tcp_writer ( self . sn ) ? ; // write the record header writer . write_all ( & header ) ? ; let ( key , nonce ) : ( [ u8 ; 16 ] , [ u8 ; 12 ] ) = self . key_schedule . client_key_and_nonce ( ) . unwrap ( ) ; let mut cipher = crate :: crypto :: Aes128Gcm :: new ( & key , & nonce , & header ) ; // write the record data in 128-bit chunks let mut chunks = data . chunks_exact ( 16 ) ; for chunk in & mut chunks { let mut mut_chunck : [ u8 ; 16 ] = chunk . try_into ( ) . unwrap ( ) ; cipher . encrypt_block_inplace ( & mut mut_chunck ) ; writer . write_all ( & mut_chunck ) ? ; } // write the remaining data let rem = chunks . remainder ( ) ; let mut padded_block : [ u8 ; 16 ] = [ 0 ; 16 ] ; padded_block [ .. rem . len ( ) ] . copy_from_slice ( rem ) ; // append the content type padded_block [ rem . len ( ) ] = content_type as u8 ; let remainder_len : usize = rem . len ( ) + CONTENT_TYPE_LEN ; cipher . encrypt_remainder_inplace ( & mut padded_block , remainder_len ) ; writer . write_all ( & padded_block [ .. remainder_len ] ) ? ; // write the AES-GCM authentication tag let tag : [ u8 ; GCM_TAG_LEN ] = cipher . finish ( ) ; writer . write_all ( & tag ) ? ; writer . send ( ) ? ; Ok ( ( ) ) }
helper to send an encrypted record without a round-trip to the socket
buffers
helper to send an encrypted record without a round - trip to the socket buffers
&mut self
w5500
&mut W5500
content_type
ContentType
data
&[u8]
&mut self
w5500
&mut W5500
content_type
ContentType
data
&[u8]