use crate::command_runner::CommandRunner; use crate::symbols::Symbol; use std::error::Error; use std::path::Path; #[derive(Debug)] pub struct Key { file_path: P, command_runner: C, } impl Key { pub fn new(command_runner: C, file_path: P) -> Self { Self { file_path, command_runner, } } fn get_bytes(&self) -> u32 { 4096 } } impl> Symbol for Key { fn target_reached(&self) -> Result> { if !self.file_path.as_ref().exists() { return Ok(false); } let stdout = self.command_runner.get_output( "openssl", args![ "rsa", "-in", self.file_path.as_ref(), "-noout", "-check", "-text", ], )?; // FIXME check bytes Ok(stdout.ends_with(b"RSA key ok\n")) } fn execute(&self) -> Result<(), Box> { self.command_runner.run_successfully( "openssl", args![ "genrsa", "-out", self.file_path.as_ref(), self.get_bytes().to_string(), ], ) } } #[cfg(test)] mod test {}