pub fn build(mut self, crypto: &mut CryptoDxState) -> Res<Encoder> {
        if self.len() > self.limit {
            qwarn!("Packet contents are more than the limit");
            debug_assert!(false);
            return Err(Error::InternalError(5));
        }

        self.pad_for_crypto(crypto);
        if self.offsets.len > 0 {
            self.write_len(crypto.expansion());
        }

        let hdr = &self.encoder[self.header.clone()];
        let body = &self.encoder[self.header.end..];
        qtrace!(
            "Packet build pn={} hdr={} body={}",
            self.pn,
            hex(hdr),
            hex(body)
        );
        let ciphertext = crypto.encrypt(self.pn, hdr, body)?;

        // Calculate the mask.
        let offset = SAMPLE_OFFSET - self.offsets.pn.len();
        assert!(offset + SAMPLE_SIZE <= ciphertext.len());
        let sample = &ciphertext[offset..offset + SAMPLE_SIZE];
        let mask = crypto.compute_mask(sample)?;

        // Apply the mask.
        self.encoder[self.header.start] ^= mask[0] & self.offsets.first_byte_mask;
        for (i, j) in (1..=self.offsets.pn.len()).zip(self.offsets.pn) {
            self.encoder[j] ^= mask[i];
        }

        // Finally, cut off the plaintext and add back the ciphertext.
        self.encoder.truncate(self.header.end);
        self.encoder.encode(&ciphertext);
        qtrace!("Packet built {}", hex(&self.encoder));
        Ok(self.encoder)
    }
/// Build the packet and return the encoder.
Build the packet and return the encoder.
Build the packet and return the encoder .
pub fn build(mut self, crypto: &mut CryptoDxState) -> Res<Encoder> {
        if self.len() > self.limit {
            qwarn!("Packet contents are more than the limit");
            debug_assert!(false);
            return Err(Error::InternalError(5));
        }
        self.pad_for_crypto(crypto);
        if self.offsets.len > 0 {
            self.write_len(crypto.expansion());
        }
        let hdr = &self.encoder[self.header.clone()];
        let body = &self.encoder[self.header.end..];
        qtrace!(
            "Packet build pn={} hdr={} body={}",
            self.pn,
            hex(hdr),
            hex(body)
        );
        let ciphertext = crypto.encrypt(self.pn, hdr, body)?;
        // Calculate the mask.
        let offset = SAMPLE_OFFSET - self.offsets.pn.len();
        assert!(offset + SAMPLE_SIZE <= ciphertext.len());
        let sample = &ciphertext[offset..offset + SAMPLE_SIZE];
        let mask = crypto.compute_mask(sample)?;
        // Apply the mask.
        self.encoder[self.header.start] ^= mask[0] & self.offsets.first_byte_mask;
        for (i, j) in (1..=self.offsets.pn.len()).zip(self.offsets.pn) {
            self.encoder[j] ^= mask[i];
        }
        // Finally, cut off the plaintext and add back the ciphertext.
        self.encoder.truncate(self.header.end);
        self.encoder.encode(&ciphertext);
        qtrace!("Packet built {}", hex(&self.encoder));
        Ok(self.encoder)
    }
pub fn build ( mut self , crypto : & mut CryptoDxState ) -> Res < Encoder > { if self . len ( ) > self . limit { qwarn ! ( " " ) ; debug_assert ! ( false ) ; return Err ( Error :: InternalError ( 5 ) ) ; } self . pad_for_crypto ( crypto ) ; if self . offsets . len > 0 { self . write_len ( crypto . expansion ( ) ) ; } let hdr = & self . encoder [ self . header . clone ( ) ] ; let body = & self . encoder [ self . header . end .. ] ; qtrace ! ( " " self pn hex ( hdr ) hex ( body ) ) ; let ciphertext = crypto . encrypt ( self . pn , hdr , body ) ? ; // Calculate the mask. let offset = SAMPLE_OFFSET - self . offsets . pn . len ( ) ; assert ! ( offset SAMPLE_SIZE ciphertext len ( ) ) ; let sample = & ciphertext [ offset .. offset + SAMPLE_SIZE ] ; let mask = crypto . compute_mask ( sample ) ? ; // Apply the mask. self . encoder [ self . header . start ] ^= mask [ 0 ] & self . offsets . first_byte_mask ; for ( i , j ) in ( 1 ..= self . offsets . pn . len ( ) ) . zip ( self . offsets . pn ) { self . encoder [ j ] ^= mask [ i ] ; } // Finally, cut off the plaintext and add back the ciphertext. self . encoder . truncate ( self . header . end ) ; self . encoder . encode ( & ciphertext ) ; qtrace ! ( " " hex ( self encoder ) ) ; Ok ( self . encoder ) }
Build the packet and return the encoder.
Build the packet and return the encoder .
mut self
crypto
&mut CryptoDxState