MCPcopy Create free account
hub / github.com/archlinux/alpm / openpgp_verify_file

Function openpgp_verify_file

dev-scripts/src/testing.rs:45–83  ·  view source on GitHub ↗

Verifies a `file` using a `signature` and a [`ModelBasedVerifier`]. The success or failure of the verification is transmitted through logging. # Errors Returns an error if - the `signature` cannot be read as an OpenPGP signature - the `file` cannot be read

(
    file: PathBuf,
    signature: PathBuf,
    model_verifier: &ModelBasedVerifier,
)

Source from the content-addressed store, hash-verified

43/// - the `signature` cannot be read as an OpenPGP signature
44/// - the `file` cannot be read
45fn openpgp_verify_file(
46 file: PathBuf,
47 signature: PathBuf,
48 model_verifier: &ModelBasedVerifier,
49) -> Result<(), Error> {
50 debug!("Verifying {file:?} with {signature:?}");
51
52 let signatures = read_openpgp_signatures(&HashSet::from_iter([RegularFile::try_from(
53 signature.clone(),
54 )?]))?;
55
56 let check_results = openpgp_verify(
57 model_verifier,
58 &signatures,
59 &RegularFile::try_from(file.clone())?,
60 )?;
61
62 // Look at the signer info of all check results and return an error if there is none.
63 for check_result in check_results {
64 if let Some(signer_info) = check_result.signer_info() {
65 debug!(
66 "Successfully verified using {} {}",
67 signer_info
68 .certificate()
69 .fingerprint()
70 .map_err(voa::Error::VoaOpenPgp)?,
71 signer_info.component_fingerprint()
72 )
73 } else {
74 return Err(Error::VoaVerificationFailed {
75 file,
76 signature,
77 context: "".to_string(),
78 });
79 }
80 }
81
82 Ok(())
83}
84
85/// This is the entry point for running validation tests of parsers on ALPM metadata files.
86#[derive(Clone, Debug)]

Callers 1

run_testsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected