diff --git a/src/lib.rs b/src/lib.rs index f4fbbc4..4570d03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,7 +149,7 @@ pub fn private_key_ecdh( cmd.arg(STANDARD.encode(ephemera_public_key)); let cmd_stdout = run_command_stdout(cmd)?; - parse_dh_result(&cmd_stdout) + parse_ecdh_result(&cmd_stdout) } pub fn external_sign(external_command: &str, parameter: &str, alg: &str, content: &[u8]) -> XResult> { @@ -175,27 +175,7 @@ pub fn external_ecdh(external_command: &str, parameter: &str, ephemera_public_ke cmd.arg(STANDARD.encode(ephemera_public_key)); let cmd_stdout = run_command_stdout(cmd)?; - parse_dh_result(&cmd_stdout) -} - -fn parse_sign_result(stdout: &str) -> XResult> { - if is_success(stdout)? { - let sign_result: SignResult = from_str(stdout)?; - Ok(STANDARD.decode(&sign_result.signature_base64)?) - } else { - let error_result: ErrorResult = from_str(stdout)?; - simple_error!("{}", error_result.error) - } -} - -fn parse_dh_result(stdout: &str) -> XResult> { - if is_success(stdout)? { - let dh_result: DhResult = from_str(stdout)?; - Ok(hex::decode(&dh_result.shared_secret_hex)?) - } else { - let error_result: ErrorResult = from_str(stdout)?; - simple_error!("{}", error_result.error) - } + parse_ecdh_result(&cmd_stdout) } fn run_command_stdout(cmd: Command) -> XResult { @@ -240,6 +220,26 @@ fn parse_keypair_result(cmd_stdout: &str) -> XResult { } } +fn parse_sign_result(stdout: &str) -> XResult> { + if is_success(stdout)? { + let sign_result: SignResult = from_str(stdout)?; + Ok(STANDARD.decode(&sign_result.signature_base64)?) + } else { + let error_result: ErrorResult = from_str(stdout)?; + simple_error!("{}", error_result.error) + } +} + +fn parse_ecdh_result(stdout: &str) -> XResult> { + if is_success(stdout)? { + let dh_result: DhResult = from_str(stdout)?; + Ok(hex::decode(&dh_result.shared_secret_hex)?) + } else { + let error_result: ErrorResult = from_str(stdout)?; + simple_error!("{}", error_result.error) + } +} + pub fn from_str<'a, T>(s: &'a str) -> XResult where T: de::Deserialize<'a>,