fn decrypt_header(
        &self,
        crypto: &mut CryptoDxState,
    ) -> Res<(bool, PacketNumber, Vec<u8>, &'a [u8])> {
        assert_ne!(self.packet_type, PacketType::Retry);
        assert_ne!(self.packet_type, PacketType::VersionNegotiation);

        qtrace!(
            "unmask hdr={}",
            hex(&self.data[..self.header_len + SAMPLE_OFFSET])
        );

        let sample_offset = self.header_len + SAMPLE_OFFSET;
        let mask = if let Some(sample) = self.data.get(sample_offset..(sample_offset + SAMPLE_SIZE))
        {
            crypto.compute_mask(sample)
        } else {
            Err(Error::NoMoreData)
        }?;

        // Un-mask the leading byte.
        let bits = if self.packet_type == PacketType::Short {
            PACKET_HP_MASK_SHORT
        } else {
            PACKET_HP_MASK_LONG
        };
        let first_byte = self.data[0] ^ (mask[0] & bits);

        // Make a copy of the header to work on.
        let mut hdrbytes = self.data[..self.header_len + 4].to_vec();
        hdrbytes[0] = first_byte;

        // Unmask the PN.
        let mut pn_encoded: u64 = 0;
        for i in 0..MAX_PACKET_NUMBER_LEN {
            hdrbytes[self.header_len + i] ^= mask[1 + i];
            pn_encoded <<= 8;
            pn_encoded += u64::from(hdrbytes[self.header_len + i]);
        }

        // Now decode the packet number length and apply it, hopefully in constant time.
        let pn_len = usize::from((first_byte & 0x3) + 1);
        hdrbytes.truncate(self.header_len + pn_len);
        pn_encoded >>= 8 * (MAX_PACKET_NUMBER_LEN - pn_len);

        qtrace!("unmasked hdr={}", hex(&hdrbytes));

        let key_phase = self.packet_type == PacketType::Short
            && (first_byte & PACKET_BIT_KEY_PHASE) == PACKET_BIT_KEY_PHASE;
        let pn = Self::decode_pn(crypto.next_pn(), pn_encoded, pn_len);
        Ok((
            key_phase,
            pn,
            hdrbytes,
            &self.data[self.header_len + pn_len..],
        ))
    }
/// Decrypt the header of the packet.
Decrypt the header of the packet.
Decrypt the header of the packet .
fn decrypt_header(
        &self,
        crypto: &mut CryptoDxState,
    ) -> Res<(bool, PacketNumber, Vec<u8>, &'a [u8])> {
        assert_ne!(self.packet_type, PacketType::Retry);
        assert_ne!(self.packet_type, PacketType::VersionNegotiation);
        qtrace!(
            "unmask hdr={}",
            hex(&self.data[..self.header_len + SAMPLE_OFFSET])
        );
        let sample_offset = self.header_len + SAMPLE_OFFSET;
        let mask = if let Some(sample) = self.data.get(sample_offset..(sample_offset + SAMPLE_SIZE))
        {
            crypto.compute_mask(sample)
        } else {
            Err(Error::NoMoreData)
        }?;
        // Un-mask the leading byte.
        let bits = if self.packet_type == PacketType::Short {
            PACKET_HP_MASK_SHORT
        } else {
            PACKET_HP_MASK_LONG
        };
        let first_byte = self.data[0] ^ (mask[0] & bits);
        // Make a copy of the header to work on.
        let mut hdrbytes = self.data[..self.header_len + 4].to_vec();
        hdrbytes[0] = first_byte;
        // Unmask the PN.
        let mut pn_encoded: u64 = 0;
        for i in 0..MAX_PACKET_NUMBER_LEN {
            hdrbytes[self.header_len + i] ^= mask[1 + i];
            pn_encoded <<= 8;
            pn_encoded += u64::from(hdrbytes[self.header_len + i]);
        }
        // Now decode the packet number length and apply it, hopefully in constant time.
        let pn_len = usize::from((first_byte & 0x3) + 1);
        hdrbytes.truncate(self.header_len + pn_len);
        pn_encoded >>= 8 * (MAX_PACKET_NUMBER_LEN - pn_len);
        qtrace!("unmasked hdr={}", hex(&hdrbytes));
        let key_phase = self.packet_type == PacketType::Short
            && (first_byte & PACKET_BIT_KEY_PHASE) == PACKET_BIT_KEY_PHASE;
        let pn = Self::decode_pn(crypto.next_pn(), pn_encoded, pn_len);
        Ok((
            key_phase,
            pn,
            hdrbytes,
            &self.data[self.header_len + pn_len..],
        ))
    }
fn decrypt_header ( & self , crypto : & mut CryptoDxState , ) -> Res < ( bool , PacketNumber , Vec < u8 > , & ' a [ u8 ] ) > { assert_ne ! ( self packet_type PacketType Retry ) ; assert_ne ! ( self packet_type PacketType VersionNegotiation ) ; qtrace ! ( " " hex ( self data [ self header_len SAMPLE_OFFSET ] ) ) ; let sample_offset = self . header_len + SAMPLE_OFFSET ; let mask = if let Some ( sample ) = self . data . get ( sample_offset .. ( sample_offset + SAMPLE_SIZE ) ) { crypto . compute_mask ( sample ) } else { Err ( Error :: NoMoreData ) } ? ; // Un-mask the leading byte. let bits = if self . packet_type == PacketType :: Short { PACKET_HP_MASK_SHORT } else { PACKET_HP_MASK_LONG } ; let first_byte = self . data [ 0 ] ^ ( mask [ 0 ] & bits ) ; // Make a copy of the header to work on. let mut hdrbytes = self . data [ .. self . header_len + 4 ] . to_vec ( ) ; hdrbytes [ 0 ] = first_byte ; // Unmask the PN. let mut pn_encoded : u64 = 0 ; for i in 0 .. MAX_PACKET_NUMBER_LEN { hdrbytes [ self . header_len + i ] ^= mask [ 1 + i ] ; pn_encoded <<= 8 ; pn_encoded += u64 :: from ( hdrbytes [ self . header_len + i ] ) ; } // Now decode the packet number length and apply it, hopefully in constant time. let pn_len = usize :: from ( ( first_byte & 0x3 ) + 1 ) ; hdrbytes . truncate ( self . header_len + pn_len ) ; pn_encoded >>= 8 * ( MAX_PACKET_NUMBER_LEN - pn_len ) ; qtrace ! ( " " hex ( hdrbytes ) ) ; let key_phase = self . packet_type == PacketType :: Short && ( first_byte & PACKET_BIT_KEY_PHASE ) == PACKET_BIT_KEY_PHASE ; let pn = Self :: decode_pn ( crypto . next_pn ( ) , pn_encoded , pn_len ) ; Ok ( ( key_phase , pn , hdrbytes , & self . data [ self . header_len + pn_len .. ] , ) ) }
Decrypt the header of the packet.
Decrypt the header of the packet .
&self
crypto
&mut CryptoDxState