fn read_and_check_body(
    reader: impl std::io::Read,
    checksum: &[u8],
) -> Result<Vec<u8>, ReadAndCheckBodyError> {
    use std::io::Read;
    let mut reader = BufReader::new(reader);
    let mut context = Context::new(&SHA256);
    let mut buffer = [0; 1024];
    let mut body = Vec::new();

    loop {
        let count = reader.read(&mut buffer)?;
        if count == 0 {
            break;
        }
        let bytes = &buffer[..count];
        context.update(bytes);
        body.extend_from_slice(bytes);
    }

    let digest = context.finish();
    if digest.as_ref() == checksum {
        Ok(body)
    } else {
        Err(ReadAndCheckBodyError::IncorrectChecksum)
    }
}
/// Read a body and ensure it has the given sha256 digest.
Read a body and ensure it has the given sha256 digest.
Read a body and ensure it has the given sha256 digest .
fn read_and_check_body(
    reader: impl std::io::Read,
    checksum: &[u8],
) -> Result<Vec<u8>, ReadAndCheckBodyError> {
    use std::io::Read;
    let mut reader = BufReader::new(reader);
    let mut context = Context::new(&SHA256);
    let mut buffer = [0; 1024];
    let mut body = Vec::new();
    loop {
        let count = reader.read(&mut buffer)?;
        if count == 0 {
            break;
        }
        let bytes = &buffer[..count];
        context.update(bytes);
        body.extend_from_slice(bytes);
    }
    let digest = context.finish();
    if digest.as_ref() == checksum {
        Ok(body)
    } else {
        Err(ReadAndCheckBodyError::IncorrectChecksum)
    }
}
fn read_and_check_body ( reader : impl std :: io :: Read , checksum : & [ u8 ] , ) -> Result < Vec < u8 > , ReadAndCheckBodyError > { use std :: io :: Read ; let mut reader = BufReader :: new ( reader ) ; let mut context = Context :: new ( & SHA256 ) ; let mut buffer = [ 0 ; 1024 ] ; let mut body = Vec :: new ( ) ; loop { let count = reader . read ( & mut buffer ) ? ; if count == 0 { break ; } let bytes = & buffer [ .. count ] ; context . update ( bytes ) ; body . extend_from_slice ( bytes ) ; } let digest = context . finish ( ) ; if digest . as_ref ( ) == checksum { Ok ( body ) } else { Err ( ReadAndCheckBodyError :: IncorrectChecksum ) } }
Read a body and ensure it has the given sha256 digest.
Read a body and ensure it has the given sha256 digest .
reader
impl std::io::Read
checksum
&[u8]
reader
impl std::io::Read
checksum
&[u8]