lanzaboote/rust/lanzatool/src/signer.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

use std::path::{Path, PathBuf};
2022-11-25 07:07:04 -05:00
use std::process::Command;
2022-11-25 09:46:33 -05:00
use anyhow::Result;
use crate::utils;
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(),
}
}
2022-11-26 09:32:43 -05:00
pub fn sign_and_copy(&self, from: &Path, to: &Path) -> Result<()> {
let args = vec![
String::from("--key"),
2022-11-25 09:46:33 -05:00
utils::path_to_string(&self.private_key),
String::from("--cert"),
2022-11-25 09:46:33 -05:00
utils::path_to_string(&self.public_key),
2022-11-26 09:32:43 -05:00
utils::path_to_string(from),
2022-11-24 21:04:44 -05:00
String::from("--output"),
2022-11-26 09:32:43 -05:00
utils::path_to_string(to),
];
let output = Command::new("sbsign").args(&args).output()?;
if !output.status.success() {
print!("{:?}", output.stderr);
return Err(anyhow::anyhow!(
"Failed to sign file using sbsign with args `{:?}`",
&args
)
.into());
}
Ok(())
}
}