/// 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) -> Result<Vec<u8>> {
        let mut p = vec![0; self.payload_size as usize];
        reader.read_exact(p.as_mut())?;
        let hash = digest::digest(&digest::SHA256, p.as_ref());
        let hash = digest::digest(&digest::SHA256, &hash.as_ref());
        let h = &hash.as_ref();
        let j = &self.checksum;
        if h[0] != j[0] || h[1] != j[1] || h[2] != j[2] || h[3] != j[3] {
            let msg = format!("Bad checksum: {:?} != {:?}", &h[..4], j);
            return Err(Error::BadData(msg));
        }
        Ok(p)
    }
pub fn payload ( & self , reader : & mut dyn Read ) -> Result < Vec < u8 > > { let mut p = vec ! [ 0 self payload_size as usize ] ; reader . read_exact ( p . as_mut ( ) ) ? ; let hash = digest :: digest ( & digest :: SHA256 , p . as_ref ( ) ) ; let hash = digest :: digest ( & digest :: SHA256 , & hash . as_ref ( ) ) ; let h = & hash . as_ref ( ) ; let j = & self . checksum ; if h [ 0 ] != j [ 0 ] || h [ 1 ] != j [ 1 ] || h [ 2 ] != j [ 2 ] || h [ 3 ] != j [ 3 ] { let msg = format ! ( " " h [ 4 ] j ) ; return Err ( Error :: BadData ( msg ) ) ; } Ok ( p ) }
Reads the payload and verifies its checksum
Reads the payload and verifies its checksum
&self
reader
&mut dyn Read