1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Age key pair.
//!
//! This module defines the [`KeyPair`] type, which bundles a validated
//! [`PublicKey`] with its corresponding [`SecretKey`]. Key pairs are created
//! via the [`build_keypair`](crate::build_keypair) function, which handles
//! generation and validation, ensuring that the two keys are mathematically
//! related and conform to the age specification.
use cratePublicKey;
use crateSecretKey;
/// An age X25519 key pair consisting of a public key and a secret key.
///
/// `KeyPair` is the central type of this crate. It is produced by
/// [`build_keypair`](crate::build_keypair) and provides access to both the
/// public identity (safe to share) and the secret identity (must be kept
/// confidential).
///
/// # Fields
///
/// * `public: PublicKey` – The public key. It is guaranteed to start with
/// `"age1"` and can be safely displayed, cloned, and shared.
/// * `secret: SecretKey` – The secret key. It is automatically zeroized when
/// dropped, and its `Display` and `Debug` implementations redact the actual
/// key material.
///
/// # Creation
///
/// `KeyPair` cannot be constructed directly from outside the crate because
/// its constructor is `pub(crate)`. This ensures that all key pairs are
/// produced by [`build_keypair`], which properly generates a fresh identity
/// and validates both keys.
///
/// # Examples
///
/// ```rust
/// use age_setup::build_keypair;
///
/// let kp = build_keypair()?;
/// println!("Public key: {}", kp.public);
/// // Secret key is redacted when printed:
/// println!("Secret key: {}", kp.secret); // prints [REDACTED]
/// # Ok::<(), age_setup::Error>(())
/// ```