#![cfg(feature = "crypto-p256")]
use base64::Engine;
use p256::ecdh::EphemeralSecret;
use p256::elliptic_curve::sec1::ToEncodedPoint;
use rand::rngs::OsRng;
#[test]
fn test_ephemeral_key_generation() {
let ephemeral_secret = EphemeralSecret::random(&mut OsRng);
let ephemeral_public_key = ephemeral_secret.public_key();
let point = ephemeral_public_key.to_encoded_point(false); let x_bytes = point.x().unwrap().to_vec();
let y_bytes = point.y().unwrap().to_vec();
let x_b64 = base64::engine::general_purpose::STANDARD.encode(&x_bytes);
let y_b64 = base64::engine::general_purpose::STANDARD.encode(&y_bytes);
println!("x coordinate (base64): {}", x_b64);
println!("y coordinate (base64): {}", y_b64);
assert!(!x_b64.is_empty(), "x coordinate should not be empty");
assert!(!y_b64.is_empty(), "y coordinate should not be empty");
let x_decoded = base64::engine::general_purpose::STANDARD
.decode(&x_b64)
.unwrap();
let y_decoded = base64::engine::general_purpose::STANDARD
.decode(&y_b64)
.unwrap();
assert_eq!(x_decoded.len(), 32, "x coordinate should be 32 bytes");
assert_eq!(y_decoded.len(), 32, "y coordinate should be 32 bytes");
println!("✅ Ephemeral key generation test passed");
}