Skip to content

Commit 1322779

Browse files
committed
Cary over some docs
1 parent e946556 commit 1322779

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

crates/stackable-certs/src/ca/ca_builder.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ where
5959

6060
/// This builder builds certificate authorities of type [`CertificateAuthority`].
6161
///
62+
/// It has many default values, notably;
63+
///
64+
/// - A default validity of [`DEFAULT_CA_VALIDITY`]
65+
/// - A default subject of [`SDP_ROOT_CA_SUBJECT`]
66+
/// - A randomly generated serial number
67+
/// - In case no `signing_key_pair` was provided, a fresh keypair will be created. The algorithm
68+
/// (`rsa`/`ecdsa`) is chosen by the generic [`CertificateKeypair`] type of this struct.
69+
///
70+
/// The CA contains the public half of the provided `signing_key_pair` and is signed by the private
71+
/// half of said key.
72+
///
6273
/// Example code to construct a CA:
6374
///
6475
/// ```no_run
@@ -101,7 +112,7 @@ where
101112
{
102113
/// Convenience function to avoid calling `builder().finish_builder().build()`
103114
pub fn build(
104-
self: Self,
115+
self,
105116
) -> Result<CertificateAuthority<SKP>, CreateCertificateAuthorityError<SKP::Error>> {
106117
self.finish_builder().build()
107118
}
@@ -128,6 +139,9 @@ where
128139
Some(signing_key_pair) => signing_key_pair,
129140
None => SKP::new().context(CreateSigningKeyPairSnafu)?,
130141
};
142+
143+
// By choosing a random serial number we can make the reasonable assumption that we generate
144+
// a unique serial for each CA.
131145
let serial_number = SerialNumber::from(rand::random::<u64>());
132146

133147
let spki_pem = signing_key_pair

crates/stackable-certs/src/cert_builder.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,21 @@ where
6666

6767
/// This builder builds certificates of type [`CertificatePair`].
6868
///
69-
/// Example code to construct a certificate:
69+
/// Currently you are required to specify a [`CertificateAuthority`], which is used to create a leaf
70+
/// certificate, which is signed by this CA.
71+
///
72+
/// These leaf certificates can be used for client/server authentication, because they include
73+
/// [`ID_KP_CLIENT_AUTH`] and [`ID_KP_SERVER_AUTH`] in the extended key usage extension.
74+
///
75+
/// This builder has many default values, notably;
76+
///
77+
/// - A default validity of [`DEFAULT_CERTIFICATE_VALIDITY`]
78+
/// - A randomly generated serial number
79+
/// - In case no `key_pair` was provided, a fresh keypair will be created. The algorithm
80+
/// (`rsa`/`ecdsa`) is chosen by the generic [`CertificateKeypair`] type of this struct,
81+
/// which is normally inferred from the [`CertificateAuthority`].
82+
///
83+
/// Example code to construct a CA and a signed certificate:
7084
///
7185
/// ```no_run
7286
/// use stackable_certs::{
@@ -92,7 +106,7 @@ where
92106
KP: CertificateKeypair,
93107
<KP::SigningKey as signature::Keypair>::VerifyingKey: EncodePublicKey,
94108
{
95-
/// Required subject of the certificate, usually starts with `CN=`.
109+
/// Required subject of the certificate, usually starts with `CN=`, e.g. `CN=mypod`.
96110
subject: &'a str,
97111

98112
/// Optional list of subject alternative name DNS entries
@@ -151,6 +165,9 @@ where
151165
Some(key_pair) => key_pair,
152166
None => SKP::new().context(CreateKeyPairSnafu)?,
153167
};
168+
169+
// By choosing a random serial number we can make the reasonable assumption that we generate
170+
// a unique serial for each certificate.
154171
let serial_number = SerialNumber::from(rand::random::<u64>());
155172

156173
let ca_validity = self.signed_by.ca_cert().tbs_certificate.validity;

0 commit comments

Comments
 (0)