fn check_image_and_sig(
    source: &ImageSource,
    path: &Path,
    sig_path: &Path,
    keys: VerifyKeys,
) -> Result<()> {
    // ensure we have something to check
    if source.signature.is_none() {
        bail!("no signature available; can't check existing file");
    }
    let signature = source.signature.as_ref().unwrap();

    // compare signature to expectation
    let mut sig_file = OpenOptions::new()
        .read(true)
        .open(sig_path)
        .with_context(|| format!("opening {}", sig_path.display()))?;
    let mut buf = Vec::new();
    sig_file
        .read_to_end(&mut buf)
        .with_context(|| format!("reading {}", sig_path.display()))?;
    if &buf != signature {
        bail!("signature file doesn't match source");
    }

    // open image file
    let mut file = OpenOptions::new()
        .read(true)
        .open(path)
        .with_context(|| format!("opening {}", path.display()))?;

    // perform GPG verification
    let mut reader = VerifyReader::new(
        BufReader::with_capacity(BUFFER_SIZE, &mut file),
        Some(signature),
        keys,
    )?;
    copy(&mut reader, &mut io::sink())?;
    reader.verify_without_logging_failure()?;

    Ok(())
}
// Check an existing image and signature for validity.  The image cannot
// have been decompressed after downloading.  Return an error if invalid for
// any reason.
Check an existing image and signature for validity.  The image cannot
have been decompressed after downloading.  Return an error if invalid for
any reason.
Check an existing image and signature for validity . The image cannot have been decompressed after downloading . Return an error if invalid for any reason .
fn check_image_and_sig(
    source: &ImageSource,
    path: &Path,
    sig_path: &Path,
    keys: VerifyKeys,
) -> Result<()> {
    // ensure we have something to check
    if source.signature.is_none() {
        bail!("no signature available; can't check existing file");
    }
    let signature = source.signature.as_ref().unwrap();
    // compare signature to expectation
    let mut sig_file = OpenOptions::new()
        .read(true)
        .open(sig_path)
        .with_context(|| format!("opening {}", sig_path.display()))?;
    let mut buf = Vec::new();
    sig_file
        .read_to_end(&mut buf)
        .with_context(|| format!("reading {}", sig_path.display()))?;
    if &buf != signature {
        bail!("signature file doesn't match source");
    }
    // open image file
    let mut file = OpenOptions::new()
        .read(true)
        .open(path)
        .with_context(|| format!("opening {}", path.display()))?;
    // perform GPG verification
    let mut reader = VerifyReader::new(
        BufReader::with_capacity(BUFFER_SIZE, &mut file),
        Some(signature),
        keys,
    )?;
    copy(&mut reader, &mut io::sink())?;
    reader.verify_without_logging_failure()?;
    Ok(())
}
fn check_image_and_sig ( source : & ImageSource , path : & Path , sig_path : & Path , keys : VerifyKeys , ) -> Result < ( ) > { // ensure we have something to check if source . signature . is_none ( ) { bail ! ( " " ) ; } let signature = source . signature . as_ref ( ) . unwrap ( ) ; // compare signature to expectation let mut sig_file = OpenOptions :: new ( ) . read ( true ) . open ( sig_path ) . with_context ( | | format ! ( " " sig_path display ( ) ) ) ? ; let mut buf = Vec :: new ( ) ; sig_file . read_to_end ( & mut buf ) . with_context ( | | format ! ( " " sig_path display ( ) ) ) ? ; if & buf != signature { bail ! ( " " ) ; } // open image file let mut file = OpenOptions :: new ( ) . read ( true ) . open ( path ) . with_context ( | | format ! ( " " path display ( ) ) ) ? ; // perform GPG verification let mut reader = VerifyReader :: new ( BufReader :: with_capacity ( BUFFER_SIZE , & mut file ) , Some ( signature ) , keys , ) ? ; copy ( & mut reader , & mut io :: sink ( ) ) ? ; reader . verify_without_logging_failure ( ) ? ; Ok ( ( ) ) }
Check an existing image and signature for validity.
Check an existing image and signature for validity .
source
&ImageSource
path
&Path
sig_path
&Path
keys
VerifyKeys
source
&ImageSource
path
&Path
sig_path
&Path
keys
VerifyKeys