use crate::command_runner::CommandRunner; use crate::symbols::Symbol; use async_trait::async_trait; 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 const fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self { Self { command_runner, domain, key_path, csr_path, } } } #[async_trait(?Send)] impl, K: Borrow, P: Borrow> Symbol for Csr { async 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",], ) .await?; Ok(output == b"verify OK\n") } async 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()), ], ) .await } } #[cfg(test)] mod test {}