15
15
//! let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
16
16
//!
17
17
//! let stream = TcpStream::connect("google.com:443").unwrap();
18
- //! let mut stream = connector.connect("google.com", stream).unwrap();
18
+ //! let mut stream = connector
19
+ //! .setup_connect("google.com", stream)
20
+ //! .unwrap()
21
+ //! .handshake()
22
+ //! .unwrap();
19
23
//!
20
24
//! stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
21
25
//! let mut res = vec![];
49
53
//! Ok(stream) => {
50
54
//! let acceptor = acceptor.clone();
51
55
//! thread::spawn(move || {
52
- //! let stream = acceptor.accept(stream).unwrap();
56
+ //! let stream = acceptor
57
+ //! .setup_accept(stream)
58
+ //! .unwrap()
59
+ //! .handshake()
60
+ //! .unwrap();
61
+ //!
53
62
//! handle_client(stream);
54
63
//! });
55
64
//! }
@@ -98,7 +107,7 @@ use crate::{cvt, cvt_0i, cvt_n, cvt_p, init};
98
107
pub use crate :: ssl:: connector:: {
99
108
ConnectConfiguration , SslAcceptor , SslAcceptorBuilder , SslConnector , SslConnectorBuilder ,
100
109
} ;
101
- pub use crate :: ssl:: error:: { Error , ErrorCode , HandshakeError } ;
110
+ pub use crate :: ssl:: error:: { Error , ErrorCode } ;
102
111
103
112
mod bio;
104
113
mod callbacks;
@@ -2324,22 +2333,6 @@ impl Ssl {
2324
2333
SslStreamBuilder :: new ( self , stream) . setup_connect ( )
2325
2334
}
2326
2335
2327
- /// Attempts a client-side TLS handshake.
2328
- ///
2329
- /// This is a convenience method which combines [`Self::setup_connect`] and
2330
- /// [`MidHandshakeSslStream::handshake`].
2331
- ///
2332
- /// # Warning
2333
- ///
2334
- /// OpenSSL's default configuration is insecure. It is highly recommended to use
2335
- /// [`SslConnector`] rather than `Ssl` directly, as it manages that configuration.
2336
- pub fn connect < S > ( self , stream : S ) -> Result < SslStream < S > , HandshakeError < S > >
2337
- where
2338
- S : Read + Write ,
2339
- {
2340
- self . setup_connect ( stream) . handshake ( )
2341
- }
2342
-
2343
2336
/// Initiates a server-side TLS handshake.
2344
2337
///
2345
2338
/// This method is guaranteed to return without calling any callback defined
@@ -2372,24 +2365,6 @@ impl Ssl {
2372
2365
2373
2366
SslStreamBuilder :: new ( self , stream) . setup_accept ( )
2374
2367
}
2375
-
2376
- /// Attempts a server-side TLS handshake.
2377
- ///
2378
- /// This is a convenience method which combines [`Self::setup_accept`] and
2379
- /// [`MidHandshakeSslStream::handshake`].
2380
- ///
2381
- /// # Warning
2382
- ///
2383
- /// OpenSSL's default configuration is insecure. It is highly recommended to use
2384
- /// `SslAcceptor` rather than `Ssl` directly, as it manages that configuration.
2385
- ///
2386
- /// [`SSL_accept`]: https://www.openssl.org/docs/manmaster/man3/SSL_accept.html
2387
- pub fn accept < S > ( self , stream : S ) -> Result < SslStream < S > , HandshakeError < S > >
2388
- where
2389
- S : Read + Write ,
2390
- {
2391
- self . setup_accept ( stream) . handshake ( )
2392
- }
2393
2368
}
2394
2369
2395
2370
impl fmt:: Debug for SslRef {
@@ -3192,16 +3167,14 @@ impl<S> MidHandshakeSslStream<S> {
3192
3167
/// This corresponds to [`SSL_do_handshake`].
3193
3168
///
3194
3169
/// [`SSL_do_handshake`]: https://www.openssl.org/docs/manmaster/man3/SSL_do_handshake.html
3195
- pub fn handshake ( mut self ) -> Result < SslStream < S > , HandshakeError < S > > {
3170
+ pub fn handshake ( mut self ) -> Result < SslStream < S > , MidHandshakeSslStream < S > > {
3196
3171
let ret = unsafe { ffi:: SSL_do_handshake ( self . stream . ssl . as_ptr ( ) ) } ;
3197
3172
if ret > 0 {
3198
3173
Ok ( self . stream )
3199
3174
} else {
3200
3175
self . error = self . stream . make_error ( ret) ;
3201
- match self . error . would_block ( ) {
3202
- true => Err ( HandshakeError :: WouldBlock ( self ) ) ,
3203
- false => Err ( HandshakeError :: Failure ( self ) ) ,
3204
- }
3176
+
3177
+ Err ( self )
3205
3178
}
3206
3179
}
3207
3180
}
@@ -3484,7 +3457,7 @@ where
3484
3457
/// This corresponds to [`SSL_set_connect_state`].
3485
3458
///
3486
3459
/// [`SSL_set_connect_state`]: https://www.openssl.org/docs/manmaster/man3/SSL_set_connect_state.html
3487
- pub fn set_connect_state ( & mut self ) {
3460
+ fn set_connect_state ( & mut self ) {
3488
3461
unsafe { ffi:: SSL_set_connect_state ( self . inner . ssl . as_ptr ( ) ) }
3489
3462
}
3490
3463
@@ -3493,15 +3466,14 @@ where
3493
3466
/// This corresponds to [`SSL_set_accept_state`].
3494
3467
///
3495
3468
/// [`SSL_set_accept_state`]: https://www.openssl.org/docs/manmaster/man3/SSL_set_accept_state.html
3496
- pub fn set_accept_state ( & mut self ) {
3469
+ fn set_accept_state ( & mut self ) {
3497
3470
unsafe { ffi:: SSL_set_accept_state ( self . inner . ssl . as_ptr ( ) ) }
3498
3471
}
3499
3472
3500
3473
/// Initiates a client-side TLS handshake, returning a [`MidHandshakeSslStream`].
3501
3474
///
3502
- /// This method calls [`Self::set_connect_state`] and returns without actually
3503
- /// initiating the handshake. The caller is then free to call
3504
- /// [`MidHandshakeSslStream`] and loop on [`HandshakeError::WouldBlock`].
3475
+ /// The caller is then free to call [`MidHandshakeSslStream::handshake`] and retry
3476
+ /// on blocking errors.
3505
3477
pub fn setup_connect ( mut self ) -> MidHandshakeSslStream < S > {
3506
3478
self . set_connect_state ( ) ;
3507
3479
@@ -3517,19 +3489,10 @@ where
3517
3489
}
3518
3490
}
3519
3491
3520
- /// Attempts a client-side TLS handshake.
3521
- ///
3522
- /// This is a convenience method which combines [`Self::setup_connect`] and
3523
- /// [`MidHandshakeSslStream::handshake`].
3524
- pub fn connect ( self ) -> Result < SslStream < S > , HandshakeError < S > > {
3525
- self . setup_connect ( ) . handshake ( )
3526
- }
3527
-
3528
3492
/// Initiates a server-side TLS handshake, returning a [`MidHandshakeSslStream`].
3529
3493
///
3530
- /// This method calls [`Self::set_accept_state`] and returns without actually
3531
- /// initiating the handshake. The caller is then free to call
3532
- /// [`MidHandshakeSslStream`] and loop on [`HandshakeError::WouldBlock`].
3494
+ /// The caller is then free to call [`MidHandshakeSslStream::handshake`] and retry
3495
+ /// on blocking errors.
3533
3496
pub fn setup_accept ( mut self ) -> MidHandshakeSslStream < S > {
3534
3497
self . set_accept_state ( ) ;
3535
3498
@@ -3544,41 +3507,6 @@ where
3544
3507
} ,
3545
3508
}
3546
3509
}
3547
-
3548
- /// Attempts a server-side TLS handshake.
3549
- ///
3550
- /// This is a convenience method which combines [`Self::setup_accept`] and
3551
- /// [`MidHandshakeSslStream::handshake`].
3552
- pub fn accept ( self ) -> Result < SslStream < S > , HandshakeError < S > > {
3553
- self . setup_accept ( ) . handshake ( )
3554
- }
3555
-
3556
- /// Initiates the handshake.
3557
- ///
3558
- /// This will fail if `set_accept_state` or `set_connect_state` was not called first.
3559
- ///
3560
- /// This corresponds to [`SSL_do_handshake`].
3561
- ///
3562
- /// [`SSL_do_handshake`]: https://www.openssl.org/docs/manmaster/man3/SSL_do_handshake.html
3563
- pub fn handshake ( self ) -> Result < SslStream < S > , HandshakeError < S > > {
3564
- let mut stream = self . inner ;
3565
- let ret = unsafe { ffi:: SSL_do_handshake ( stream. ssl . as_ptr ( ) ) } ;
3566
- if ret > 0 {
3567
- Ok ( stream)
3568
- } else {
3569
- let error = stream. make_error ( ret) ;
3570
- match error. would_block ( ) {
3571
- true => Err ( HandshakeError :: WouldBlock ( MidHandshakeSslStream {
3572
- stream,
3573
- error,
3574
- } ) ) ,
3575
- false => Err ( HandshakeError :: Failure ( MidHandshakeSslStream {
3576
- stream,
3577
- error,
3578
- } ) ) ,
3579
- }
3580
- }
3581
- }
3582
3510
}
3583
3511
3584
3512
impl < S > SslStreamBuilder < S > {
0 commit comments