feat: add examples
This commit is contained in:
@@ -12,3 +12,6 @@ categories = ["cryptography"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
rust_util = "0.6.47"
|
rust_util = "0.6.47"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
hex = "0.4.3"
|
||||||
|
|||||||
42
examples/generate_keypair.rs
Normal file
42
examples/generate_keypair.rs
Normal 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
3
examples/recover_ecdh.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
|
||||||
|
}
|
||||||
3
examples/recover_ecdsa.rs
Normal file
3
examples/recover_ecdsa.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user