Skip to content

Commit d00b035

Browse files
committed
Docs pass
This was motivated by the new `clippy::too_long_first_doc_paragraph` in clippy nightly. Aside from fixing those, this also splits other long docs into paragraphs, fixes some parameter names, and adds some extra backticks in various places.
1 parent 0eb62c7 commit d00b035

File tree

10 files changed

+669
-373
lines changed

10 files changed

+669
-373
lines changed

src/acceptor.rs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ use crate::{
1313
};
1414

1515
box_castable! {
16-
/// A buffer and parser for ClientHello bytes. This allows reading ClientHello
17-
/// before choosing a rustls_server_config. It's useful when the server
18-
/// config will be based on parameters in the ClientHello: server name
19-
/// indication (SNI), ALPN protocols, signature schemes, and cipher suites. In
20-
/// particular, if a server wants to do some potentially expensive work to load a
21-
/// certificate for a given hostname, rustls_acceptor allows doing that asynchronously,
22-
/// as opposed to rustls_server_config_builder_set_hello_callback(), which doesn't
23-
/// work well for asynchronous I/O.
16+
/// A buffer and parser for ClientHello bytes.
17+
///
18+
/// This allows reading ClientHello before choosing a rustls_server_config.
19+
///
20+
/// It's useful when the server config will be based on parameters in the
21+
/// ClientHello: server name indication (SNI), ALPN protocols, signature
22+
/// schemes, and cipher suites.
23+
///
24+
/// In particular, if a server wants to do some potentially expensive work
25+
/// to load a certificate for a given hostname, rustls_acceptor allows doing
26+
/// that asynchronously, as opposed to rustls_server_config_builder_set_hello_callback(),
27+
/// which doesn't work well for asynchronous I/O.
2428
///
2529
/// The general flow is:
2630
/// - rustls_acceptor_new()
@@ -39,10 +43,11 @@ box_castable! {
3943
}
4044

4145
box_castable! {
42-
/// A parsed ClientHello produced by a rustls_acceptor. It is used to check
43-
/// server name indication (SNI), ALPN protocols, signature schemes, and
44-
/// cipher suites. It can be combined with a rustls_server_config to build a
45-
/// rustls_connection.
46+
/// A parsed ClientHello produced by a rustls_acceptor.
47+
///
48+
/// It is used to check server name indication (SNI), ALPN protocols,
49+
/// signature schemes, and cipher suites. It can be combined with a
50+
/// `rustls_server_config` to build a `rustls_connection`.
4651
pub struct rustls_accepted(Option<Accepted>);
4752
}
4853

@@ -72,10 +77,12 @@ impl rustls_acceptor {
7277
}
7378
}
7479

75-
/// Read some TLS bytes from the network into internal buffers. The actual network
76-
/// I/O is performed by `callback`, which you provide. Rustls will invoke your
77-
/// callback with a suitable buffer to store the read bytes into. You don't have
78-
/// to fill it up, just fill with as many bytes as you get in one syscall.
80+
/// Read some TLS bytes from the network into internal buffers.
81+
///
82+
/// The actual network I/O is performed by `callback`, which you provide.
83+
/// Rustls will invoke your callback with a suitable buffer to store the
84+
/// read bytes into. You don't have to fill it up, just fill with as many
85+
/// bytes as you get in one syscall.
7986
///
8087
/// Parameters:
8188
///
@@ -125,8 +132,9 @@ impl rustls_acceptor {
125132
}
126133
}
127134

128-
/// Parse all TLS bytes read so far. If those bytes make up a ClientHello,
129-
/// create a rustls_accepted from them.
135+
/// Parse all TLS bytes read so far.
136+
///
137+
/// If those bytes make up a ClientHello, create a rustls_accepted from them.
130138
///
131139
/// Parameters:
132140
///
@@ -232,6 +240,7 @@ impl rustls_accepted {
232240
}
233241

234242
/// Get the i'th in the list of signature schemes offered in the ClientHello.
243+
///
235244
/// This is useful in selecting a server certificate when there are multiple
236245
/// available for the same server name, for instance when selecting
237246
/// between an RSA and an ECDSA certificate.
@@ -443,13 +452,17 @@ box_castable! {
443452
}
444453

445454
impl rustls_accepted_alert {
446-
/// Write some TLS bytes (an alert) to the network. The actual network I/O is
447-
/// performed by `callback`, which you provide. Rustls will invoke your callback with a
448-
/// suitable buffer containing TLS bytes to send. You don't have to write them
449-
/// all, just as many as you can in one syscall.
455+
/// Write some TLS bytes (an alert) to the network.
456+
///
457+
/// The actual network I/O is performed by `callback`, which you provide.
458+
/// Rustls will invoke your callback with a suitable buffer containing TLS
459+
/// bytes to send. You don't have to write them all, just as many as you can
460+
/// in one syscall.
461+
///
450462
/// The `userdata` parameter is passed through directly to `callback`. Note that
451463
/// this is distinct from the `userdata` parameter set with
452464
/// `rustls_connection_set_userdata`.
465+
///
453466
/// Returns 0 for success, or an errno value on error. Passes through return values
454467
/// from callback. See [`rustls_write_callback`] or [`AcceptedAlert`] for
455468
/// more details.

src/cipher.rs

Lines changed: 79 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ref_castable! {
6565
impl rustls_supported_ciphersuite {
6666
/// Return a 16-bit unsigned integer corresponding to this cipher suite's assignment from
6767
/// <https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4>.
68+
///
6869
/// The bytes from the assignment are interpreted in network order.
6970
#[no_mangle]
7071
pub extern "C" fn rustls_supported_ciphersuite_get_suite(
@@ -81,10 +82,11 @@ impl rustls_supported_ciphersuite {
8182
}
8283
}
8384

84-
/// Returns the name of the ciphersuite as a `rustls_str`. If the provided
85-
/// ciphersuite is invalid, the rustls_str will contain the empty string. The
86-
/// lifetime of the `rustls_str` is the lifetime of the program, it does not
87-
/// need to be freed.
85+
/// Returns the name of the ciphersuite as a `rustls_str`.
86+
///
87+
/// If the provided ciphersuite is invalid, the `rustls_str` will contain the
88+
/// empty string. The lifetime of the `rustls_str` is the lifetime of the program,
89+
/// it does not need to be freed.
8890
#[no_mangle]
8991
pub extern "C" fn rustls_supported_ciphersuite_get_name(
9092
supported_ciphersuite: *const rustls_supported_ciphersuite,
@@ -103,10 +105,12 @@ pub extern "C" fn rustls_all_ciphersuites_len() -> usize {
103105
ALL_CIPHER_SUITES.len()
104106
}
105107

106-
/// Get a pointer to a member of rustls' list of supported cipher suites. This will return non-NULL
107-
/// for i < rustls_all_ciphersuites_len().
108-
/// The returned pointer is valid for the lifetime of the program and may be used directly when
109-
/// building a ClientConfig or ServerConfig.
108+
/// Get a pointer to a member of rustls' list of supported cipher suites.
109+
///
110+
/// This will return non-NULL for i < rustls_all_ciphersuites_len().
111+
///
112+
/// The returned pointer is valid for the lifetime of the program and may
113+
/// be used directly when building a ClientConfig or ServerConfig.
110114
#[no_mangle]
111115
pub extern "C" fn rustls_all_ciphersuites_get_entry(
112116
i: size_t,
@@ -123,10 +127,12 @@ pub extern "C" fn rustls_default_ciphersuites_len() -> usize {
123127
DEFAULT_CIPHER_SUITES.len()
124128
}
125129

126-
/// Get a pointer to a member of rustls' list of supported cipher suites. This will return non-NULL
127-
/// for i < rustls_default_ciphersuites_len().
128-
/// The returned pointer is valid for the lifetime of the program and may be used directly when
129-
/// building a ClientConfig or ServerConfig.
130+
/// Get a pointer to a member of rustls' list of supported cipher suites.
131+
///
132+
/// This will return non-NULL for i < rustls_default_ciphersuites_len().
133+
///
134+
/// The returned pointer is valid for the lifetime of the program and may
135+
/// be used directly when building a ClientConfig or ServerConfig.
130136
#[no_mangle]
131137
pub extern "C" fn rustls_default_ciphersuites_get_entry(
132138
i: size_t,
@@ -137,10 +143,11 @@ pub extern "C" fn rustls_default_ciphersuites_get_entry(
137143
}
138144
}
139145

140-
/// Rustls' list of supported cipher suites. This is an array of pointers, and
141-
/// its length is given by `RUSTLS_ALL_CIPHER_SUITES_LEN`. The pointers will
142-
/// always be valid. The contents and order of this array may change between
143-
/// releases.
146+
/// Rustls' list of supported cipher suites.
147+
///
148+
/// This is an array of pointers, and its length is given by
149+
/// `RUSTLS_ALL_CIPHER_SUITES_LEN`. The pointers will always be valid.
150+
/// The contents and order of this array may change between releases.
144151
#[no_mangle]
145152
pub static mut RUSTLS_ALL_CIPHER_SUITES: [*const rustls_supported_ciphersuite; 9] = [
146153
&rustls::crypto::ring::cipher_suite::TLS13_AES_256_GCM_SHA384 as *const SupportedCipherSuite
@@ -167,10 +174,11 @@ pub static mut RUSTLS_ALL_CIPHER_SUITES: [*const rustls_supported_ciphersuite; 9
167174
#[no_mangle]
168175
pub static RUSTLS_ALL_CIPHER_SUITES_LEN: usize = unsafe { RUSTLS_ALL_CIPHER_SUITES.len() };
169176

170-
/// Rustls' list of default cipher suites. This is an array of pointers, and
171-
/// its length is given by `RUSTLS_DEFAULT_CIPHER_SUITES_LEN`. The pointers
172-
/// will always be valid. The contents and order of this array may change
173-
/// between releases.
177+
/// Rustls' list of default cipher suites.
178+
///
179+
/// This is an array of pointers, and its length is given by
180+
/// `RUSTLS_DEFAULT_CIPHER_SUITES_LEN`. The pointers will always be valid.
181+
/// The contents and order of this array may change between releases.
174182
#[no_mangle]
175183
pub static mut RUSTLS_DEFAULT_CIPHER_SUITES: [*const rustls_supported_ciphersuite; 9] = [
176184
&rustls::crypto::ring::cipher_suite::TLS13_AES_256_GCM_SHA384 as *const SupportedCipherSuite
@@ -200,13 +208,15 @@ pub static RUSTLS_DEFAULT_CIPHER_SUITES_LEN: usize = unsafe { RUSTLS_DEFAULT_CIP
200208
arc_castable! {
201209
/// The complete chain of certificates to send during a TLS handshake,
202210
/// plus a private key that matches the end-entity (leaf) certificate.
211+
///
203212
/// Corresponds to `CertifiedKey` in the Rust API.
204213
/// <https://docs.rs/rustls/latest/rustls/sign/struct.CertifiedKey.html>
205214
pub struct rustls_certified_key(CertifiedKey);
206215
}
207216

208217
impl rustls_certified_key {
209218
/// Build a `rustls_certified_key` from a certificate chain and a private key.
219+
///
210220
/// `cert_chain` must point to a buffer of `cert_chain_len` bytes, containing
211221
/// a series of PEM-encoded certificates, with the end-entity (leaf)
212222
/// certificate first.
@@ -262,8 +272,10 @@ impl rustls_certified_key {
262272
}
263273
}
264274

265-
/// Return the i-th rustls_certificate in the rustls_certified_key. 0 gives the
266-
/// end-entity certificate. 1 and higher give certificates from the chain.
275+
/// Return the i-th rustls_certificate in the rustls_certified_key.
276+
///
277+
/// 0 gives the end-entity certificate. 1 and higher give certificates from the chain.
278+
///
267279
/// Indexes higher than the last available certificate return NULL.
268280
///
269281
/// The returned certificate is valid until the rustls_certified_key is freed.
@@ -282,8 +294,11 @@ impl rustls_certified_key {
282294
}
283295

284296
/// Create a copy of the rustls_certified_key with the given OCSP response data
285-
/// as DER encoded bytes. The OCSP response may be given as NULL to clear any
286-
/// possibly present OCSP data from the cloned key.
297+
/// as DER encoded bytes.
298+
///
299+
/// The OCSP response may be given as NULL to clear any possibly present OCSP
300+
/// data from the cloned key.
301+
///
287302
/// The cloned key is independent from its original and needs to be freed
288303
/// by the application.
289304
#[no_mangle]
@@ -312,11 +327,13 @@ impl rustls_certified_key {
312327
}
313328
}
314329

315-
/// "Free" a certified_key previously returned from
316-
/// rustls_certified_key_build. Since certified_key is actually an
317-
/// atomically reference-counted pointer, extant certified_key may still
318-
/// hold an internal reference to the Rust object. However, C code must
319-
/// consider this pointer unusable after "free"ing it.
330+
/// "Free" a certified_key previously returned from `rustls_certified_key_build`.
331+
///
332+
/// Since certified_key is actually an atomically reference-counted pointer,
333+
/// extant certified_key may still hold an internal reference to the Rust object.
334+
///
335+
/// However, C code must consider this pointer unusable after "free"ing it.
336+
///
320337
/// Calling with NULL is fine. Must not be called twice with the same value.
321338
#[no_mangle]
322339
pub extern "C" fn rustls_certified_key_free(key: *const rustls_certified_key) {
@@ -528,8 +545,9 @@ impl rustls_root_cert_store_builder {
528545
}
529546

530547
/// Free a `rustls_root_cert_store_builder` previously returned from
531-
/// `rustls_root_cert_store_builder_new`. Calling with NULL is fine. Must not be
532-
/// called twice with the same value.
548+
/// `rustls_root_cert_store_builder_new`.
549+
///
550+
/// Calling with NULL is fine. Must not be called twice with the same value.
533551
#[no_mangle]
534552
pub extern "C" fn rustls_root_cert_store_builder_free(
535553
builder: *mut rustls_root_cert_store_builder,
@@ -548,6 +566,7 @@ arc_castable! {
548566

549567
impl rustls_root_cert_store {
550568
/// Free a rustls_root_cert_store previously returned from rustls_root_cert_store_builder_build.
569+
///
551570
/// Calling with NULL is fine. Must not be called twice with the same value.
552571
#[no_mangle]
553572
pub extern "C" fn rustls_root_cert_store_free(store: *const rustls_root_cert_store) {
@@ -590,21 +609,25 @@ pub(crate) struct ClientCertVerifierBuilder {
590609
}
591610

592611
box_castable! {
593-
/// A client certificate verifier being constructed. A builder can be modified by,
594-
/// e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`. Once you're
595-
/// done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build`
596-
/// to turn it into a `rustls_client_cert_verifier`. This object is not safe
597-
/// for concurrent mutation.
612+
/// A client certificate verifier being constructed.
613+
///
614+
/// A builder can be modified by, e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`.
615+
///
616+
/// Once you're done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build`
617+
/// to turn it into a `rustls_client_cert_verifier`.
618+
///
619+
/// This object is not safe for concurrent mutation.
598620
///
599621
/// See <https://docs.rs/rustls/latest/rustls/server/struct.ClientCertVerifierBuilder.html>
600622
/// for more information.
601623
pub struct rustls_web_pki_client_cert_verifier_builder(Option<ClientCertVerifierBuilder>);
602624
}
603625

604626
impl rustls_web_pki_client_cert_verifier_builder {
605-
/// Create a `rustls_web_pki_client_cert_verifier_builder`. Caller owns the memory and may
606-
/// eventually call `rustls_web_pki_client_cert_verifier_builder_free` to free it, whether or
607-
/// not `rustls_web_pki_client_cert_verifier_builder_build` was called.
627+
/// Create a `rustls_web_pki_client_cert_verifier_builder`.
628+
///
629+
/// Caller owns the memory and may eventually call `rustls_web_pki_client_cert_verifier_builder_free`
630+
/// to free it, whether or not `rustls_web_pki_client_cert_verifier_builder_build` was called.
608631
///
609632
/// Without further modification the builder will produce a client certificate verifier that
610633
/// will require a client present a client certificate that chains to one of the trust anchors
@@ -838,8 +861,9 @@ impl rustls_web_pki_client_cert_verifier_builder {
838861
}
839862

840863
/// Free a `rustls_client_cert_verifier_builder` previously returned from
841-
/// `rustls_client_cert_verifier_builder_new`. Calling with NULL is fine. Must not be
842-
/// called twice with the same value.
864+
/// `rustls_client_cert_verifier_builder_new`.
865+
///
866+
/// Calling with NULL is fine. Must not be called twice with the same value.
843867
#[no_mangle]
844868
pub extern "C" fn rustls_web_pki_client_cert_verifier_builder_free(
845869
builder: *mut rustls_web_pki_client_cert_verifier_builder,
@@ -851,11 +875,12 @@ impl rustls_web_pki_client_cert_verifier_builder {
851875
}
852876

853877
box_castable! {
854-
/// A server certificate verifier being constructed. A builder can be modified by,
855-
/// e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`. Once you're
856-
/// done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build`
857-
/// to turn it into a `rustls_server_cert_verifier`. This object is not safe
858-
/// for concurrent mutation.
878+
/// A server certificate verifier being constructed.
879+
///
880+
/// A builder can be modified by, e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`.
881+
///
882+
/// Once you're done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build`
883+
/// to turn it into a `rustls_server_cert_verifier`. This object is not safe for concurrent mutation.
859884
///
860885
/// See <https://docs.rs/rustls/latest/rustls/client/struct.ServerCertVerifierBuilder.html>
861886
/// for more information.
@@ -870,9 +895,10 @@ pub(crate) struct ServerCertVerifierBuilder {
870895
}
871896

872897
impl ServerCertVerifierBuilder {
873-
/// Create a `rustls_web_pki_server_cert_verifier_builder`. Caller owns the memory and may
874-
/// free it with `rustls_web_pki_server_cert_verifier_builder_free`, regardless of whether
875-
/// `rustls_web_pki_server_cert_verifier_builder_build` was called.
898+
/// Create a `rustls_web_pki_server_cert_verifier_builder`.
899+
///
900+
/// Caller owns the memory and may free it with `rustls_web_pki_server_cert_verifier_builder_free`,
901+
/// regardless of whether `rustls_web_pki_server_cert_verifier_builder_build` was called.
876902
///
877903
/// Without further modification the builder will produce a server certificate verifier that
878904
/// will require a server present a certificate that chains to one of the trust anchors
@@ -1031,8 +1057,9 @@ impl ServerCertVerifierBuilder {
10311057
}
10321058

10331059
/// Free a `rustls_server_cert_verifier_builder` previously returned from
1034-
/// `rustls_server_cert_verifier_builder_new`. Calling with NULL is fine. Must not be
1035-
/// called twice with the same value.
1060+
/// `rustls_server_cert_verifier_builder_new`.
1061+
///
1062+
/// Calling with NULL is fine. Must not be called twice with the same value.
10361063
#[no_mangle]
10371064
pub extern "C" fn rustls_web_pki_server_cert_verifier_builder_free(
10381065
builder: *mut rustls_web_pki_server_cert_verifier_builder,
@@ -1076,6 +1103,7 @@ impl rustls_server_cert_verifier {
10761103

10771104
/// Free a `rustls_server_cert_verifier` previously returned from
10781105
/// `rustls_server_cert_verifier_builder_build` or `rustls_platform_server_cert_verifier`.
1106+
///
10791107
/// Calling with NULL is fine. Must not be called twice with the same value.
10801108
#[no_mangle]
10811109
pub extern "C" fn rustls_server_cert_verifier_free(verifier: *mut rustls_server_cert_verifier) {

0 commit comments

Comments
 (0)