pub fn format_packet_data<'a>(&self, src: &[u8], dst: &'a mut [u8]) -> &'a mut [u8] {
        if DATA_OFF + src.len() + AEAD_SIZE > dst.len() {
            // This is a very incorrect use of the library, therefore panic and not error
            panic!("The destination buffer is too small");
        }

        let sending_key_counter = self.sending_key_counter.fetch_add(1, Ordering::Relaxed) as u64;
        dst[MSG_TYPE_OFF..MSG_TYPE_OFF + MSG_TYPE_SZ]
            .copy_from_slice(&PACKET_DATA_TYPE.to_le_bytes());
        dst[IDX_OFF..IDX_OFF + IDX_SZ].copy_from_slice(&self.sending_index.to_le_bytes());
        dst[CTR_OFF..CTR_OFF + CTR_SZ].copy_from_slice(&sending_key_counter.to_le_bytes());
        // TODO: spec requires padding to 16 bytes, but actually works fine without it

        #[cfg(not(target_arch = "arm"))]
        {
            let mut nonce = [0u8; 12];
            nonce[4..12].copy_from_slice(&sending_key_counter.to_le_bytes());
            dst[DATA_OFF..DATA_OFF + src.len()].copy_from_slice(src);
            let n = seal_in_place(
                &self.sender,
                Nonce::assume_unique_for_key(nonce),
                Aad::from(&[]),
                &mut dst[DATA_OFF..DATA_OFF + src.len() + AEAD_SIZE],
                AEAD_SIZE,
            )
            .unwrap();
            &mut dst[..DATA_OFF + n]
        }

        #[cfg(target_arch = "arm")]
        {
            let n = self.sender.seal_wg(
                sending_key_counter,
                &[],
                src,
                &mut dst[DATA_OFF..DATA_OFF + src.len() + AEAD_SIZE],
            );
            &mut dst[..DATA_OFF + n]
        }
    }
// src - an IP packet from the interface
// dst - preallocated space to hold the encapsulating UDP packet to send over the network
// returns the size of the formatted packet
an IP packet from the interface
dst - preallocated space to hold the encapsulating UDP packet to send over the network
returns the size of the formatted packet
an IP packet from the interface dst - preallocated space to hold the encapsulating UDP packet to send over the network returns the size of the formatted packet
pub fn format_packet_data<'a>(&self, src: &[u8], dst: &'a mut [u8]) -> &'a mut [u8] {
        if DATA_OFF + src.len() + AEAD_SIZE > dst.len() {
            // This is a very incorrect use of the library, therefore panic and not error
            panic!("The destination buffer is too small");
        }
        let sending_key_counter = self.sending_key_counter.fetch_add(1, Ordering::Relaxed) as u64;
        dst[MSG_TYPE_OFF..MSG_TYPE_OFF + MSG_TYPE_SZ]
            .copy_from_slice(&PACKET_DATA_TYPE.to_le_bytes());
        dst[IDX_OFF..IDX_OFF + IDX_SZ].copy_from_slice(&self.sending_index.to_le_bytes());
        dst[CTR_OFF..CTR_OFF + CTR_SZ].copy_from_slice(&sending_key_counter.to_le_bytes());
        // TODO: spec requires padding to 16 bytes, but actually works fine without it
        #[cfg(not(target_arch = "arm"))]
        {
            let mut nonce = [0u8; 12];
            nonce[4..12].copy_from_slice(&sending_key_counter.to_le_bytes());
            dst[DATA_OFF..DATA_OFF + src.len()].copy_from_slice(src);
            let n = seal_in_place(
                &self.sender,
                Nonce::assume_unique_for_key(nonce),
                Aad::from(&[]),
                &mut dst[DATA_OFF..DATA_OFF + src.len() + AEAD_SIZE],
                AEAD_SIZE,
            )
            .unwrap();
            &mut dst[..DATA_OFF + n]
        }
        #[cfg(target_arch = "arm")]
        {
            let n = self.sender.seal_wg(
                sending_key_counter,
                &[],
                src,
                &mut dst[DATA_OFF..DATA_OFF + src.len() + AEAD_SIZE],
            );
            &mut dst[..DATA_OFF + n]
        }
    }
pub fn format_packet_data < ' a > ( & self , src : & [ u8 ] , dst : & ' a mut [ u8 ] ) -> & ' a mut [ u8 ] { if DATA_OFF + src . len ( ) + AEAD_SIZE > dst . len ( ) { // This is a very incorrect use of the library, therefore panic and not error panic ! ( " " ) ; } let sending_key_counter = self . sending_key_counter . fetch_add ( 1 , Ordering :: Relaxed ) as u64 ; dst [ MSG_TYPE_OFF .. MSG_TYPE_OFF + MSG_TYPE_SZ ] . copy_from_slice ( & PACKET_DATA_TYPE . to_le_bytes ( ) ) ; dst [ IDX_OFF .. IDX_OFF + IDX_SZ ] . copy_from_slice ( & self . sending_index . to_le_bytes ( ) ) ; dst [ CTR_OFF .. CTR_OFF + CTR_SZ ] . copy_from_slice ( & sending_key_counter . to_le_bytes ( ) ) ; // TODO: spec requires padding to 16 bytes, but actually works fine without it # [ cfg ( not ( target_arch " " ) ) ] { let mut nonce = [ 0u8 ; 12 ] ; nonce [ 4 .. 12 ] . copy_from_slice ( & sending_key_counter . to_le_bytes ( ) ) ; dst [ DATA_OFF .. DATA_OFF + src . len ( ) ] . copy_from_slice ( src ) ; let n = seal_in_place ( & self . sender , Nonce :: assume_unique_for_key ( nonce ) , Aad :: from ( & [ ] ) , & mut dst [ DATA_OFF .. DATA_OFF + src . len ( ) + AEAD_SIZE ] , AEAD_SIZE , ) . unwrap ( ) ; & mut dst [ .. DATA_OFF + n ] } # [ cfg ( target_arch " " ) ] { let n = self . sender . seal_wg ( sending_key_counter , & [ ] , src , & mut dst [ DATA_OFF .. DATA_OFF + src . len ( ) + AEAD_SIZE ] , ) ; & mut dst [ .. DATA_OFF + n ] } }
src - an IP packet from the interface
dst - preallocated space to hold the encapsulating UDP packet to send over the network
returns the size of the formatted packet
src - an IP packet from the interface dst - preallocated space to hold the encapsulating UDP packet to send over the network returns the size of the formatted packet
&self
src
&[u8]
dst
&'a mut [u8]
&self
src
&[u8]
dst
&'a mut [u8]