use crate::public_key::PublicKey;
use crate::secret_key::SecretKey;
#[derive(Debug)]
pub struct KeyPair {
pub public: PublicKey,
pub secret: SecretKey,
}
impl KeyPair {
pub(crate) fn new(public: PublicKey, secret: SecretKey) -> Self {
Self { public, secret }
}
}
#[cfg(test)]
mod tests {
use crate::build_keypair;
#[test]
fn generated_keypair_fields_are_valid() {
let kp = build_keypair().unwrap();
assert!(kp.public.expose().starts_with("age1"));
assert!(kp.secret.expose_secret().starts_with("AGE-SECRET-KEY-1"));
}
#[test]
fn generated_keypair_fields_are_non_empty() {
let kp = build_keypair().unwrap();
assert!(!kp.public.expose().is_empty());
assert!(!kp.secret.expose_secret().is_empty());
}
#[test]
fn debug_does_not_leak_secret() {
let kp = build_keypair().unwrap();
let debug_str = format!("{:?}", kp);
assert!(debug_str.contains(kp.public.expose()));
assert!(!debug_str.contains(kp.secret.expose_secret()));
assert!(debug_str.contains("[REDACTED]"));
}
}