// src - a packet we received from the network
// dst - preallocated space to hold the encapsulated IP packet, to send to the interface
//       dst will always take less space than src
// return the size of the encapsulated packet on success
a packet we received from the network
dst - preallocated space to hold the encapsulated IP packet, to send to the interface
dst will always take less space than src
return the size of the encapsulated packet on success
a packet we received from the network dst - preallocated space to hold the encapsulated IP packet to send to the interface dst will always take less space than src return the size of the encapsulated packet on success
pub fn receive_packet_data<'a>(
        &self,
        src: &[u8],
        dst: &'a mut [u8],
    ) -> Result<&'a mut [u8], WireGuardError> {
        if DATA_OFF + dst.len() + AEAD_SIZE < src.len() {
            // This is a very incorrect use of the library, therefore panic and not error
            panic!("The destination buffer is too small");
        }
        let message_type = u32::from_le_bytes(make_array(&src[MSG_TYPE_OFF..]));
        if message_type != PACKET_DATA_TYPE {
            return Err(WireGuardError::WrongPacketType);
        }
        let receiver_index = u32::from_le_bytes(make_array(&src[IDX_OFF..]));
        let receiving_key_counter = u64::from_le_bytes(make_array(&src[CTR_OFF..]));
        if receiver_index != self.receiving_index {
            return Err(WireGuardError::WrongIndex);
        }
        // Don't reuse counters, in case this is a replay attack we want to quickly check the counter without running expensive decryption
        self.receiving_counter_quick_check(receiving_key_counter)?;
        #[cfg(not(target_arch = "arm"))]
        {
            let mut nonce = [0u8; 12];
            nonce[4..12].copy_from_slice(&receiving_key_counter.to_le_bytes());
            dst[..src.len() - DATA_OFF].copy_from_slice(&src[DATA_OFF..]);
            let packet = open_in_place(
                &self.receiver,
                Nonce::assume_unique_for_key(nonce),
                Aad::from(&[]),
                0,
                &mut dst[..src.len() - DATA_OFF],
            )
            .map_err(|_| WireGuardError::InvalidAeadTag)?;
            // After decryption is done, check counter again, and mark as received
            self.receiving_counter_mark(receiving_key_counter)?;
            Ok(packet)
        }
        #[cfg(target_arch = "arm")]
        {
            let packet =
                self.receiver
                    .open_wg(receiving_key_counter, &[], &src[DATA_OFF..], dst)?;
            self.receiving_counter_mark(receiving_key_counter)?;
            Ok(packet)
        }
    }
pub fn receive_packet_data < ' a > ( & self , src : & [ u8 ] , dst : & ' a mut [ u8 ] , ) -> Result < & ' a mut [ u8 ] , WireGuardError > { if DATA_OFF + dst . len ( ) + AEAD_SIZE < src . len ( ) { // This is a very incorrect use of the library, therefore panic and not error panic ! ( " " ) ; } let message_type = u32 :: from_le_bytes ( make_array ( & src [ MSG_TYPE_OFF .. ] ) ) ; if message_type != PACKET_DATA_TYPE { return Err ( WireGuardError :: WrongPacketType ) ; } let receiver_index = u32 :: from_le_bytes ( make_array ( & src [ IDX_OFF .. ] ) ) ; let receiving_key_counter = u64 :: from_le_bytes ( make_array ( & src [ CTR_OFF .. ] ) ) ; if receiver_index != self . receiving_index { return Err ( WireGuardError :: WrongIndex ) ; } // Don't reuse counters, in case this is a replay attack we want to quickly check the counter without running expensive decryption self . receiving_counter_quick_check ( receiving_key_counter ) ? ; # [ cfg ( not ( target_arch " " ) ) ] { let mut nonce = [ 0u8 ; 12 ] ; nonce [ 4 .. 12 ] . copy_from_slice ( & receiving_key_counter . to_le_bytes ( ) ) ; dst [ .. src . len ( ) - DATA_OFF ] . copy_from_slice ( & src [ DATA_OFF .. ] ) ; let packet = open_in_place ( & self . receiver , Nonce :: assume_unique_for_key ( nonce ) , Aad :: from ( & [ ] ) , 0 , & mut dst [ .. src . len ( ) - DATA_OFF ] , ) . map_err ( | _ | WireGuardError :: InvalidAeadTag ) ? ; // After decryption is done, check counter again, and mark as received self . receiving_counter_mark ( receiving_key_counter ) ? ; Ok ( packet ) } # [ cfg ( target_arch " " ) ] { let packet = self . receiver . open_wg ( receiving_key_counter , & [ ] , & src [ DATA_OFF .. ] , dst ) ? ; self . receiving_counter_mark ( receiving_key_counter ) ? ; Ok ( packet ) } }
src - a packet we received from the network
dst - preallocated space to hold the encapsulated IP packet, to send to the interface
dst will always take less space than src
return the size of the encapsulated packet on success
src - a packet we received from the network dst - preallocated space to hold the encapsulated IP packet to send to the interface dst will always take less space than src return the size of the encapsulated packet on success
&self
src
&[u8]
dst
&'a mut [u8]