feat: 1.2.0

This commit is contained in:
2025-05-14 23:13:15 +08:00
parent c4be43b928
commit e5eca1fe65
4 changed files with 62 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "swift-secure-enclave-tool-rs"
version = "1.1.0"
version = "1.2.0"
edition = "2024"
authors = ["Hatter Jiang"]
repository = "https://git.hatter.ink/hatter/swift-secure-enclave-tool-rs"

View File

@@ -0,0 +1,10 @@
use swift_secure_enclave_tool_rs::external_public_key;
fn main() {
let args = std::env::args().collect::<Vec<_>>();
let parameter = &args[1];
let public_key = external_public_key("card-cli", parameter).unwrap();
println!("{}", hex::encode(&public_key));
}

View File

@@ -0,0 +1,6 @@
use swift_secure_enclave_tool_rs::external_spec;
fn main() {
let shared_secret = external_spec("card-cli").unwrap();
println!("{:?}", shared_secret);
}

View File

@@ -78,6 +78,21 @@ struct DhResult {
pub shared_secret_hex: String,
}
#[derive(Debug, Deserialize)]
pub struct ExternalSpec {
#[allow(dead_code)]
pub success: bool,
pub agent: String,
pub specification: String,
}
#[derive(Debug, Deserialize)]
struct ExternalPublicKey {
#[allow(dead_code)]
pub success: bool,
pub public_key_base64: String,
}
pub fn is_secure_enclave_supported() -> XResult<bool> {
let mut cmd = Command::new(SWIFT_SECURE_ENCLAVE_TOOL_CMD);
cmd.arg("is_support_secure_enclave");
@@ -178,6 +193,36 @@ pub fn external_ecdh(external_command: &str, parameter: &str, ephemera_public_ke
parse_ecdh_result(&cmd_stdout)
}
pub fn external_spec(external_command: &str) -> XResult<ExternalSpec> {
let mut cmd = Command::new(external_command);
cmd.arg("external_spec");
let cmd_stdout = run_command_stdout(cmd)?;
if is_success(&cmd_stdout)? {
let external_spec: ExternalSpec = from_str(&cmd_stdout)?;
Ok(external_spec)
} else {
let error_result: ErrorResult = from_str(&cmd_stdout)?;
simple_error!("{}", error_result.error)
}
}
pub fn external_public_key(external_command: &str, parameter: &str) -> XResult<Vec<u8>> {
let mut cmd = Command::new(external_command);
cmd.arg("external_public_key");
cmd.arg("--parameter");
cmd.arg(parameter);
let cmd_stdout = run_command_stdout(cmd)?;
if is_success(&cmd_stdout)? {
let external_public_key: ExternalPublicKey = from_str(&cmd_stdout)?;
Ok(STANDARD.decode(&external_public_key.public_key_base64)?)
} else {
let error_result: ErrorResult = from_str(&cmd_stdout)?;
simple_error!("{}", error_result.error)
}
}
fn run_command_stdout(cmd: Command) -> XResult<String> {
let output = run_command(cmd)?;
let stdout_text = opt_result!(String::from_utf8(output.stdout), "Parse stdout failed:{}");