feat: add examples

This commit is contained in:
2025-03-23 23:00:39 +08:00
parent f08fb6c135
commit 799805a4fa
4 changed files with 51 additions and 0 deletions

View File

@@ -12,3 +12,6 @@ categories = ["cryptography"]
[dependencies]
base64 = "0.22.1"
rust_util = "0.6.47"
[dev-dependencies]
hex = "0.4.3"

View File

@@ -0,0 +1,42 @@
use swift_secure_enclave_tool_rs::{
generate_ecdsa_keypair, is_secure_enclave_supported, KeyMaterial, KeyPurpose,
};
fn main() {
println!(
"Secure Enclave supported: {}",
is_secure_enclave_supported().unwrap()
);
let ecdsa_key_material_require_bio = generate_ecdsa_keypair(KeyPurpose::Signing, true).unwrap();
print_key_material("Signing key [require bio]", &ecdsa_key_material_require_bio);
let ecdsa_key_material_no_bio = generate_ecdsa_keypair(KeyPurpose::Signing, true).unwrap();
print_key_material("Signing key [no bio]", &ecdsa_key_material_no_bio);
let ecdsa_key_material_require_bio =
generate_ecdsa_keypair(KeyPurpose::KeyAgreement, true).unwrap();
print_key_material(
"Key agreement key [require bio]",
&ecdsa_key_material_require_bio,
);
let ecdsa_key_material_no_bio = generate_ecdsa_keypair(KeyPurpose::KeyAgreement, true).unwrap();
print_key_material("Key agreement key [no bio]", &ecdsa_key_material_no_bio);
}
fn print_key_material(prefix: &str, key_material: &KeyMaterial) {
println!("\n{}", prefix);
println!(
"Public key point:\n{}",
hex::encode(&key_material.public_key_point)
);
println!(
"\nPublic key:\n{}",
hex::encode(&key_material.public_key_der)
);
println!(
"\nPrivate key representation:\n{}",
hex::encode(&key_material.private_key_representation)
);
}

3
examples/recover_ecdh.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
}

View File

@@ -0,0 +1,3 @@
fn main() {
}