You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.3 KiB
66 lines
1.3 KiB
use crate::command_runner::CommandRunner;
|
|
use crate::symbols::Symbol;
|
|
use async_trait::async_trait;
|
|
use std::error::Error;
|
|
use std::path::Path;
|
|
|
|
#[derive(Debug)]
|
|
pub struct Key<C, P> {
|
|
file_path: P,
|
|
command_runner: C,
|
|
bytes: u32,
|
|
}
|
|
|
|
impl<C, P> Key<C, P> {
|
|
pub const fn new(command_runner: C, file_path: P) -> Self {
|
|
Self {
|
|
file_path,
|
|
command_runner,
|
|
bytes: 4096,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait(?Send)]
|
|
impl<C: CommandRunner, P: AsRef<Path>> Symbol for Key<C, P> {
|
|
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
|
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",
|
|
],
|
|
)
|
|
.await?;
|
|
// FIXME check bytes
|
|
Ok(stdout.ends_with(b"RSA key ok\n"))
|
|
}
|
|
|
|
async fn execute(&self) -> Result<(), Box<dyn Error>> {
|
|
self
|
|
.command_runner
|
|
.run_successfully(
|
|
"openssl",
|
|
args![
|
|
"genrsa",
|
|
"-out",
|
|
self.file_path.as_ref(),
|
|
self.bytes.to_string(),
|
|
],
|
|
)
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {}
|