pub fn payload(&self, reader: &mut dyn Read, ctx: &mut dyn Ctx) -> Result<Vec<u8>> {
        let payload_size = self.payload_size as usize;
        let padding = (16 - (payload_size % 16)) % 16;
        let full_length = payload_size + padding + 16;

        let mut payload: Vec<u8> = vec![0u8; full_length];
        reader.read_exact(payload.as_mut_slice())?;

        ctx.update_local_mac(&payload[0..payload.len() - SecHeader::HEADER_LEN]);
        let mut prev = Hash128::default();
        ctx.get_local_mac(prev.as_bytes_mut());
        let mut enc = Hash128::default();
        &mut enc[..].copy_from_slice(prev.as_bytes());
        let mac_encoder: Ecb<Aes256, ZeroPadding> = Ecb::new_var(&ctx.secret_key()[..], &[]).unwrap();
        let enc_mut = enc.as_bytes_mut();
        mac_encoder.encrypt(enc_mut, enc_mut.len()).unwrap();
        enc = enc ^ prev;
        ctx.update_local_mac(enc.as_bytes());
	    let mac = &payload[(payload.len() - SecHeader::HEADER_LEN)..];
        let mut expect = Hash128::default();
        ctx.get_local_mac(expect.as_bytes_mut());
		if mac != expect.as_bytes() { panic!("paylaod auth error. mac is not valid"); }
		
		ctx.decoder().try_apply_keystream(&mut payload[..payload_size + padding]).unwrap();
		payload.truncate(payload_size);
        return Ok(payload);
    }
/// Reads the payload and verifies its checksum
Reads the payload and verifies its checksum
Reads the payload and verifies its checksum
pub fn payload(&self, reader: &mut dyn Read, ctx: &mut dyn Ctx) -> Result<Vec<u8>> {
        let payload_size = self.payload_size as usize;
        let padding = (16 - (payload_size % 16)) % 16;
        let full_length = payload_size + padding + 16;
        let mut payload: Vec<u8> = vec![0u8; full_length];
        reader.read_exact(payload.as_mut_slice())?;
        ctx.update_local_mac(&payload[0..payload.len() - SecHeader::HEADER_LEN]);
        let mut prev = Hash128::default();
        ctx.get_local_mac(prev.as_bytes_mut());
        let mut enc = Hash128::default();
        &mut enc[..].copy_from_slice(prev.as_bytes());
        let mac_encoder: Ecb<Aes256, ZeroPadding> = Ecb::new_var(&ctx.secret_key()[..], &[]).unwrap();
        let enc_mut = enc.as_bytes_mut();
        mac_encoder.encrypt(enc_mut, enc_mut.len()).unwrap();
        enc = enc ^ prev;
        ctx.update_local_mac(enc.as_bytes());
	    let mac = &payload[(payload.len() - SecHeader::HEADER_LEN)..];
        let mut expect = Hash128::default();
        ctx.get_local_mac(expect.as_bytes_mut());
		if mac != expect.as_bytes() { panic!("paylaod auth error. mac is not valid"); }
		ctx.decoder().try_apply_keystream(&mut payload[..payload_size + padding]).unwrap();
		payload.truncate(payload_size);
        return Ok(payload);
    }
pub fn payload ( & self , reader : & mut dyn Read , ctx : & mut dyn Ctx ) -> Result < Vec < u8 > > { let payload_size = self . payload_size as usize ; let padding = ( 16 - ( payload_size % 16 ) ) % 16 ; let full_length = payload_size + padding + 16 ; let mut payload : Vec < u8 > = vec ! [ 0u8 full_length ] ; reader . read_exact ( payload . as_mut_slice ( ) ) ? ; ctx . update_local_mac ( & payload [ 0 .. payload . len ( ) - SecHeader :: HEADER_LEN ] ) ; let mut prev = Hash128 :: default ( ) ; ctx . get_local_mac ( prev . as_bytes_mut ( ) ) ; let mut enc = Hash128 :: default ( ) ; & mut enc [ .. ] . copy_from_slice ( prev . as_bytes ( ) ) ; let mac_encoder : Ecb < Aes256 , ZeroPadding > = Ecb :: new_var ( & ctx . secret_key ( ) [ .. ] , & [ ] ) . unwrap ( ) ; let enc_mut = enc . as_bytes_mut ( ) ; mac_encoder . encrypt ( enc_mut , enc_mut . len ( ) ) . unwrap ( ) ; enc = enc ^ prev ; ctx . update_local_mac ( enc . as_bytes ( ) ) ; let mac = & payload [ ( payload . len ( ) - SecHeader :: HEADER_LEN ) .. ] ; let mut expect = Hash128 :: default ( ) ; ctx . get_local_mac ( expect . as_bytes_mut ( ) ) ; if mac != expect . as_bytes ( ) { panic ! ( " " ) ; } ctx . decoder ( ) . try_apply_keystream ( & mut payload [ .. payload_size + padding ] ) . unwrap ( ) ; payload . truncate ( payload_size ) ; return Ok ( payload ) ; }
Reads the payload and verifies its checksum
Reads the payload and verifies its checksum
&self
reader
&mut dyn Read
ctx
&mut dyn Ctx
&self
reader
&mut dyn Read
ctx
&mut dyn Ctx