apicurio_cli/commands/
verify.rs

1use crate::{constants::APICURIO_LOCK, lockfile::LockFile};
2use anyhow::{anyhow, Result};
3use sha2::{Digest, Sha256};
4use std::{fs, path::PathBuf};
5
6pub async fn run() -> Result<()> {
7    let lock = LockFile::load(&PathBuf::from(APICURIO_LOCK))?;
8    let mut all_ok = true;
9
10    for ld in &lock.locked_dependencies {
11        let file = PathBuf::from(&ld.output_path);
12        if !file.exists() {
13            println!("❌ missing file for {}: {}", ld.name, file.display());
14            all_ok = false;
15            continue;
16        }
17        let data = fs::read(&file)?;
18        let mut hasher = Sha256::new();
19        hasher.update(&data);
20        let sha = hex::encode(hasher.finalize());
21        if sha != ld.sha256 {
22            println!(
23                "❌ hash mismatch {}: expected={}, got={}",
24                ld.name, ld.sha256, sha
25            );
26            all_ok = false;
27        } else {
28            println!("✔️  {} OK", ld.name);
29        }
30    }
31
32    if !all_ok {
33        return Err(anyhow!("verification failed"));
34    }
35    Ok(())
36}