@@ -4,51 +4,61 @@ use rustls::server::{Accepted, AcceptedAlert, Acceptor};
44use crate :: connection:: rustls_connection;
55use crate :: error:: { map_error, rustls_io_result, rustls_result} ;
66use crate :: ffi:: {
7- box_castable , free_box, set_boxed_mut_ptr, to_box, to_boxed_mut_ptr, try_callback,
7+ Castable , OwnershipBox , free_box, set_boxed_mut_ptr, to_box, to_boxed_mut_ptr, try_callback,
88 try_clone_arc, try_mut_from_ptr, try_mut_from_ptr_ptr, try_ref_from_ptr, try_take,
99} ;
1010use crate :: io:: { CallbackReader , CallbackWriter , rustls_read_callback, rustls_write_callback} ;
1111use crate :: panic:: ffi_panic_boundary;
1212use crate :: rslice:: { rustls_slice_bytes, rustls_str} ;
1313use crate :: server:: rustls_server_config;
1414
15- box_castable ! {
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.
28- ///
29- /// The general flow is:
30- /// - rustls_acceptor_new()
31- /// - Loop:
32- /// - Read bytes from the network it with rustls_acceptor_read_tls ().
33- /// - If successful, parse those bytes with rustls_acceptor_accept() .
34- /// - If that returns RUSTLS_RESULT_ACCEPTOR_NOT_READY, continue .
35- /// - Otherwise, break.
36- /// - If rustls_acceptor_accept() returned RUSTLS_RESULT_OK:
37- /// - Examine the resulting rustls_accepted .
38- /// - Create or select a rustls_server_config .
39- /// - Call rustls_accepted_into_connection().
40- /// - Otherwise, there was a problem with the ClientHello data and the
41- /// connection should be rejected.
42- pub struct rustls_acceptor ( Acceptor ) ;
15+ /// A buffer and parser for ClientHello bytes.
16+ ///
17+ /// This allows reading ClientHello before choosing a rustls_server_config.
18+ ///
19+ /// It's useful when the server config will be based on parameters in the
20+ /// ClientHello: server name indication (SNI), ALPN protocols, signature
21+ /// schemes, and cipher suites.
22+ ///
23+ /// In particular, if a server wants to do some potentially expensive work
24+ /// to load a certificate for a given hostname, rustls_acceptor allows doing
25+ /// that asynchronously, as opposed to rustls_server_config_builder_set_hello_callback(),
26+ /// which doesn't work well for asynchronous I/O.
27+ ///
28+ /// The general flow is:
29+ /// - rustls_acceptor_new()
30+ /// - Loop:
31+ /// - Read bytes from the network it with rustls_acceptor_read_tls().
32+ /// - If successful, parse those bytes with rustls_acceptor_accept ().
33+ /// - If that returns RUSTLS_RESULT_ACCEPTOR_NOT_READY, continue .
34+ /// - Otherwise, break .
35+ /// - If rustls_acceptor_accept() returned RUSTLS_RESULT_OK:
36+ /// - Examine the resulting rustls_accepted.
37+ /// - Create or select a rustls_server_config .
38+ /// - Call rustls_accepted_into_connection() .
39+ /// - Otherwise, there was a problem with the ClientHello data and the
40+ /// connection should be rejected.
41+ pub struct rustls_acceptor {
42+ _private : [ u8 ; 0 ] ,
4343}
4444
45- box_castable ! {
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`.
51- pub struct rustls_accepted( Option <Accepted >) ;
45+ impl Castable for rustls_acceptor {
46+ type Ownership = OwnershipBox ;
47+ type RustType = Acceptor ;
48+ }
49+
50+ /// A parsed ClientHello produced by a rustls_acceptor.
51+ ///
52+ /// It is used to check server name indication (SNI), ALPN protocols,
53+ /// signature schemes, and cipher suites. It can be combined with a
54+ /// `rustls_server_config` to build a `rustls_connection`.
55+ pub struct rustls_accepted {
56+ _private : [ u8 ; 0 ] ,
57+ }
58+
59+ impl Castable for rustls_accepted {
60+ type Ownership = OwnershipBox ;
61+ type RustType = Option < Accepted > ;
5262}
5363
5464impl rustls_acceptor {
@@ -446,9 +456,14 @@ impl rustls_accepted {
446456 }
447457}
448458
449- box_castable ! {
450- /// Represents a TLS alert resulting from accepting a client.
451- pub struct rustls_accepted_alert( AcceptedAlert ) ;
459+ /// Represents a TLS alert resulting from accepting a client.
460+ pub struct rustls_accepted_alert {
461+ _private : [ u8 ; 0 ] ,
462+ }
463+
464+ impl Castable for rustls_accepted_alert {
465+ type Ownership = OwnershipBox ;
466+ type RustType = AcceptedAlert ;
452467}
453468
454469impl rustls_accepted_alert {
0 commit comments