feat: refactor fn names
This commit is contained in:
44
src/lib.rs
44
src/lib.rs
@@ -149,7 +149,7 @@ pub fn private_key_ecdh(
|
|||||||
cmd.arg(STANDARD.encode(ephemera_public_key));
|
cmd.arg(STANDARD.encode(ephemera_public_key));
|
||||||
|
|
||||||
let cmd_stdout = run_command_stdout(cmd)?;
|
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<Vec<u8>> {
|
pub fn external_sign(external_command: &str, parameter: &str, alg: &str, content: &[u8]) -> XResult<Vec<u8>> {
|
||||||
@@ -175,27 +175,7 @@ pub fn external_ecdh(external_command: &str, parameter: &str, ephemera_public_ke
|
|||||||
cmd.arg(STANDARD.encode(ephemera_public_key));
|
cmd.arg(STANDARD.encode(ephemera_public_key));
|
||||||
|
|
||||||
let cmd_stdout = run_command_stdout(cmd)?;
|
let cmd_stdout = run_command_stdout(cmd)?;
|
||||||
parse_dh_result(&cmd_stdout)
|
parse_ecdh_result(&cmd_stdout)
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_sign_result(stdout: &str) -> XResult<Vec<u8>> {
|
|
||||||
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<Vec<u8>> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_command_stdout(cmd: Command) -> XResult<String> {
|
fn run_command_stdout(cmd: Command) -> XResult<String> {
|
||||||
@@ -240,6 +220,26 @@ fn parse_keypair_result(cmd_stdout: &str) -> XResult<KeyMaterial> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_sign_result(stdout: &str) -> XResult<Vec<u8>> {
|
||||||
|
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<Vec<u8>> {
|
||||||
|
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<T>
|
pub fn from_str<'a, T>(s: &'a str) -> XResult<T>
|
||||||
where
|
where
|
||||||
T: de::Deserialize<'a>,
|
T: de::Deserialize<'a>,
|
||||||
|
|||||||
Reference in New Issue
Block a user