feat: v0.1.1

This commit is contained in:
2025-03-24 01:10:16 +08:00
parent f1c8500873
commit 60767a8d7b
6 changed files with 39 additions and 23 deletions

View File

@@ -31,41 +31,59 @@ pub fn is_secure_enclave_supported() -> XResult<bool> {
}
}
#[deprecated]
pub fn generate_ecdsa_keypair(key_purpose: KeyPurpose, require_bio: bool) -> XResult<KeyMaterial> {
generate_keypair(key_purpose, require_bio)
}
pub fn generate_keypair(key_purpose: KeyPurpose, require_bio: bool) -> XResult<KeyMaterial> {
let mut cmd = Command::new(SWIFT_SECURE_ENCLAVE_TOOL_CMD);
cmd.arg(match key_purpose {
KeyPurpose::Signing => "generate_p256_ecsign_keypair",
KeyPurpose::KeyAgreement => "generate_p256_ecdh_keypair",
});
cmd.arg(&format!("{}", require_bio));
cmd.arg(format!("{}", require_bio));
let cmd_stdout = run_command_stdout(cmd)?;
parse_keypair_result(&cmd_stdout)
}
#[deprecated]
pub fn recover_ecdsa_keypair(
key_purpose: KeyPurpose,
private_key_representation: &[u8],
) -> XResult<KeyMaterial> {
recover_keypair(key_purpose, private_key_representation)
}
pub fn recover_keypair(
key_purpose: KeyPurpose,
private_key_representation: &[u8],
) -> XResult<KeyMaterial> {
let mut cmd = Command::new(SWIFT_SECURE_ENCLAVE_TOOL_CMD);
cmd.arg(match key_purpose {
KeyPurpose::Signing => "recover_p256_ecsign_public_key",
KeyPurpose::KeyAgreement => "recover_p256_ecdh_public_key",
});
cmd.arg(&STANDARD.encode(private_key_representation));
cmd.arg(STANDARD.encode(private_key_representation));
let cmd_stdout = run_command_stdout(cmd)?;
parse_keypair_result(&cmd_stdout)
}
#[deprecated]
pub fn private_key_ecdsa_sign(
private_key_representation: &[u8],
content: &[u8],
) -> XResult<Vec<u8>> {
private_key_sign(private_key_representation, content)
}
pub fn private_key_sign(private_key_representation: &[u8], content: &[u8]) -> XResult<Vec<u8>> {
let mut cmd = Command::new(SWIFT_SECURE_ENCLAVE_TOOL_CMD);
cmd.arg("compute_p256_ecsign");
cmd.arg(&STANDARD.encode(private_key_representation));
cmd.arg(&STANDARD.encode(content));
cmd.arg(STANDARD.encode(private_key_representation));
cmd.arg(STANDARD.encode(content));
let cmd_stdout = run_command_stdout(cmd)?;
if cmd_stdout.starts_with("ok:") {
@@ -83,8 +101,8 @@ pub fn private_key_ecdh(
) -> XResult<Vec<u8>> {
let mut cmd = Command::new(SWIFT_SECURE_ENCLAVE_TOOL_CMD);
cmd.arg("compute_p256_ecdh");
cmd.arg(&STANDARD.encode(private_key_representation));
cmd.arg(&STANDARD.encode(ephemera_public_key));
cmd.arg(STANDARD.encode(private_key_representation));
cmd.arg(STANDARD.encode(ephemera_public_key));
let cmd_stdout = run_command_stdout(cmd)?;
if cmd_stdout.starts_with("ok:SharedSecret:") {
@@ -121,9 +139,9 @@ fn parse_keypair_result(cmd_stdout: &str) -> XResult<KeyMaterial> {
if cmd_stdout.starts_with("ok:") {
let result = cmd_stdout.chars().skip(3).collect::<String>();
let parts = result.split(",").collect::<Vec<_>>();
let public_key_point = STANDARD.decode(&parts[0])?;
let public_key_der = STANDARD.decode(&parts[1])?;
let private_key_representation = STANDARD.decode(&parts[2])?;
let public_key_point = STANDARD.decode(parts[0])?;
let public_key_der = STANDARD.decode(parts[1])?;
let private_key_representation = STANDARD.decode(parts[2])?;
Ok(KeyMaterial {
public_key_point,
public_key_der,