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.
60 lines
1.5 KiB
60 lines
1.5 KiB
use std::borrow::Cow;
|
|
use std::error::Error;
|
|
use std::fmt;
|
|
|
|
use command_runner::CommandRunner;
|
|
use symbols::Symbol;
|
|
|
|
pub struct AcmeAccountKey<'a> {
|
|
path: Cow<'a, str>,
|
|
command_runner: &'a CommandRunner
|
|
}
|
|
|
|
impl<'a> AcmeAccountKey<'a> {
|
|
pub fn new(path: Cow<'a, str>, command_runner: &'a CommandRunner) -> AcmeAccountKey<'a> {
|
|
AcmeAccountKey {
|
|
path: path,
|
|
command_runner: command_runner
|
|
}
|
|
}
|
|
|
|
fn get_path(&self) -> String {
|
|
self.path.clone().into_owned()
|
|
}
|
|
|
|
fn get_bytes(&self) -> u32 {
|
|
4096
|
|
}
|
|
}
|
|
|
|
impl<'a> fmt::Display for AcmeAccountKey<'a> {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "AcmeAccountKey {}", self.path)
|
|
}
|
|
}
|
|
|
|
impl<'a> Symbol for AcmeAccountKey<'a> {
|
|
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
|
let result = self.command_runner.run_with_args("openssl", &["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"]);
|
|
match result {
|
|
Err(e) => Err(Box::new(e)),
|
|
Ok(output) => match output.status.code() {
|
|
Some(0) => Ok(output.stdout.starts_with(format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())),
|
|
Some(_) => Ok(false),
|
|
_ => Err("Didn't work".to_string().into())
|
|
}
|
|
}
|
|
}
|
|
|
|
fn execute(&self) -> Result<(), Box<Error>> {
|
|
let output = self.command_runner.run_with_args("openssl", &["genrsa", "-out", &self.get_path(), &self.get_bytes().to_string()]);
|
|
match output {
|
|
Err(e) => Err(Box::new(e)),
|
|
Ok(_) => Ok(())
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
}
|