Skip to main content

age_setup/types/
keypair.rs

1//! Keypair structure combining public and secret keys.
2
3use crate::types::{PublicKey, SecretKey};
4
5/// A keypair consisting of an age public key and its corresponding secret key.
6///
7/// This is the main output of [`build_keypair`](crate::build_keypair).
8/// Both fields are public for direct access.
9#[derive(Debug)]
10pub struct KeyPair {
11    /// The public key (starts with "age1").
12    pub public: PublicKey,
13    /// The secret key (zeroized on drop).
14    pub secret: SecretKey,
15}
16
17impl KeyPair {
18    /// Creates a new keypair (internal use only).
19    pub(crate) fn new(public: PublicKey, secret: SecretKey) -> Self {
20        Self { public, secret }
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use crate::types::{PublicKey, SecretKey};
28
29    #[test]
30    fn test_keypair_new() {
31        let pub_key = PublicKey::new("age1pub".to_string()).unwrap();
32        let secret_key = SecretKey::new("secret".to_string());
33        let kp = KeyPair::new(pub_key, secret_key);
34        assert_eq!(kp.public.expose(), "age1pub");
35        assert_eq!(kp.secret.expose(), "secret");
36    }
37}