lanzaboote/rust/lanzatool/src/signer.rs

41 lines
1.0 KiB
Rust
Raw Normal View History

use anyhow::Result;
use std::path::{Path, PathBuf};
2022-11-25 07:07:04 -05:00
use std::process::Command;
2022-11-25 07:07:04 -05:00
pub struct Signer {
pub private_key: PathBuf,
pub public_key: PathBuf,
}
2022-11-25 07:07:04 -05:00
impl Signer {
pub fn new(public_key: &Path, private_key: &Path) -> Self {
Self {
2022-11-25 07:07:04 -05:00
public_key: public_key.into(),
private_key: private_key.into(),
}
}
pub fn sign_file(&self, filepath: &Path) -> Result<()> {
let args = vec![
String::from("--key"),
String::from(self.private_key.to_str().unwrap()),
String::from("--cert"),
String::from(self.public_key.to_str().unwrap()),
2022-11-24 21:04:44 -05:00
String::from(filepath.to_str().unwrap()),
String::from("--output"),
2022-11-25 07:07:04 -05:00
String::from(filepath.to_str().unwrap()),
];
2022-11-25 07:07:04 -05:00
let status = Command::new("sbsign").args(&args).status()?;
if !status.success() {
2022-11-25 07:07:04 -05:00
return Err(
anyhow::anyhow!("Failed to sign with sbsign with args `{:?}`", &args).into(),
);
}
Ok(())
}
}