async fn validate_file(
    file_path: &Path,
    descriptor: &ociv1::Descriptor,
    progress: &ProgressBar,
) -> Result<(), failure::Error> {
    let mut validator = descriptor
        .digest
        .validator()
        .ok_or_else(|| failure::err_msg("unsupported digest algorithm"))?;

    let mut file = File::open(&file_path)
        .await
        .context(format!("could not open {:?}", file_path))?;

    let mut buf = [0; 2048];
    loop {
        let len = file.read(&mut buf).await?;
        if len == 0 {
            progress.inc(1);
            if validator.validate() {
                return Ok(());
            } else {
                return Err(failure::err_msg(format!(
                    "Digest mismatch! {:?}",
                    file_path.file_name().unwrap()
                )));
            }
        }
        validator.input(&buf[..len]);
    }
}
/// Reads a file from disk, and validates it with the given digest
Reads a file from disk, and validates it with the given digest
Reads a file from disk and validates it with the given digest
async fn validate_file(
    file_path: &Path,
    descriptor: &ociv1::Descriptor,
    progress: &ProgressBar,
) -> Result<(), failure::Error> {
    let mut validator = descriptor
        .digest
        .validator()
        .ok_or_else(|| failure::err_msg("unsupported digest algorithm"))?;
    let mut file = File::open(&file_path)
        .await
        .context(format!("could not open {:?}", file_path))?;
    let mut buf = [0; 2048];
    loop {
        let len = file.read(&mut buf).await?;
        if len == 0 {
            progress.inc(1);
            if validator.validate() {
                return Ok(());
            } else {
                return Err(failure::err_msg(format!(
                    "Digest mismatch! {:?}",
                    file_path.file_name().unwrap()
                )));
            }
        }
        validator.input(&buf[..len]);
    }
}
async fn validate_file ( file_path : & Path , descriptor : & ociv1 :: Descriptor , progress : & ProgressBar , ) -> Result < ( ) , failure :: Error > { let mut validator = descriptor . digest . validator ( ) . ok_or_else ( | | failure :: err_msg ( " " ) ) ? ; let mut file = File :: open ( & file_path ) . await . context ( format ! ( " " file_path ) ) ? ; let mut buf = [ 0 ; 2048 ] ; loop { let len = file . read ( & mut buf ) . await ? ; if len == 0 { progress . inc ( 1 ) ; if validator . validate ( ) { return Ok ( ( ) ) ; } else { return Err ( failure :: err_msg ( format ! ( " " file_path file_name ( ) unwrap ( ) ) ) ) ; } } validator . input ( & buf [ .. len ] ) ; } }
Reads a file from disk, and validates it with the given digest
Reads a file from disk and validates it with the given digest
file_path
&Path
descriptor
&ociv1::Descriptor
progress
&ProgressBar
file_path
&Path
descriptor
&ociv1::Descriptor
progress
&ProgressBar