use crate::command_runner::CommandRunner; use crate::symbols::Symbol; use std::borrow::Borrow; use std::error::Error; use std::path::Path; #[derive(Debug)] pub struct Csr { command_runner: C, domain: D, key_path: K, csr_path: P, } impl Csr { pub fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self { Self { command_runner, domain, key_path, csr_path, } } } impl, K: Borrow, P: Borrow> Symbol for Csr { fn target_reached(&self) -> Result> { if !self.csr_path.borrow().exists() { return Ok(false); } let output = self.command_runner.get_stderr( "openssl", args!["req", "-in", self.csr_path.borrow(), "-noout", "-verify",], )?; Ok(output == b"verify OK\n") } fn execute(&self) -> Result<(), Box> { self.command_runner.run_successfully( "openssl", args![ "req", "-new", "-sha256", "-key", self.key_path.borrow(), "-out", self.csr_path.borrow(), "-subj", format!("/CN={}", self.domain.borrow()), ], )?; Ok(()) } } #[cfg(test)] mod test {}