feat: refactor fn names

This commit is contained in:
2025-05-14 23:04:46 +08:00
parent 800d94e5fb
commit c4be43b928

View File

@@ -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<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));
let cmd_stdout = run_command_stdout(cmd)?;
parse_dh_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)
}
parse_ecdh_result(&cmd_stdout)
}
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>
where
T: de::Deserialize<'a>,