This commit is contained in:
Adrian Heine 2017-05-19 18:15:16 +02:00
parent dac3db10c8
commit eadd5f5b07
24 changed files with 108 additions and 193 deletions

View file

@ -1,6 +1,7 @@
use std::borrow::Cow;
use std::error::Error;
use std::fmt;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
@ -35,23 +36,16 @@ impl<'a> fmt::Display for TlsKey<'a> {
impl<'a> Symbol for TlsKey<'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())
}
if !Path::new(&self.get_path()).exists() {
return Ok(false);
}
let output = try!(self.command_runner.get_output("openssl", &["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"]));
Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
}
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(())
}
self.command_runner.run_successfully("openssl", &["genrsa", "-out", &self.get_path(), &self.get_bytes().to_string()])
}
}