Align SslStream APIs with upstream
SslStream::new() is fallible, but `SslStream::from_raw_parts()` and `SslStreamBuilder::new()` now unwrap. Upstream has also deprecated the `SslStreamBuilder`, maybe we should do the same.
This commit is contained in:
parent
4cb7e260a8
commit
0fc992bd76
|
|
@ -4040,26 +4040,23 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Read + Write> SslStream<S> {
|
impl<S: Read + Write> SslStream<S> {
|
||||||
fn new_base(ssl: Ssl, stream: S) -> Self {
|
|
||||||
unsafe {
|
|
||||||
let (bio, method) = bio::new(stream).unwrap();
|
|
||||||
ffi::SSL_set_bio(ssl.as_ptr(), bio, bio);
|
|
||||||
|
|
||||||
SslStream {
|
|
||||||
ssl: ManuallyDrop::new(ssl),
|
|
||||||
method: ManuallyDrop::new(method),
|
|
||||||
_p: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new `SslStream`.
|
/// Creates a new `SslStream`.
|
||||||
///
|
///
|
||||||
/// This function performs no IO; the stream will not have performed any part of the handshake
|
/// This function performs no IO; the stream will not have performed any part of the handshake
|
||||||
/// with the peer. The `connect` and `accept` methods can be used to
|
/// with the peer. The `connect` and `accept` methods can be used to
|
||||||
/// explicitly perform the handshake.
|
/// explicitly perform the handshake.
|
||||||
pub fn new(ssl: Ssl, stream: S) -> Result<Self, ErrorStack> {
|
pub fn new(ssl: Ssl, stream: S) -> Result<Self, ErrorStack> {
|
||||||
Ok(Self::new_base(ssl, stream))
|
let (bio, method) = bio::new(stream)?;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
ffi::SSL_set_bio(ssl.as_ptr(), bio, bio);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(SslStream {
|
||||||
|
ssl: ManuallyDrop::new(ssl),
|
||||||
|
method: ManuallyDrop::new(method),
|
||||||
|
_p: PhantomData,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs an `SslStream` from a pointer to the underlying OpenSSL `SSL` struct.
|
/// Constructs an `SslStream` from a pointer to the underlying OpenSSL `SSL` struct.
|
||||||
|
|
@ -4071,7 +4068,7 @@ impl<S: Read + Write> SslStream<S> {
|
||||||
/// The caller must ensure the pointer is valid.
|
/// The caller must ensure the pointer is valid.
|
||||||
pub unsafe fn from_raw_parts(ssl: *mut ffi::SSL, stream: S) -> Self {
|
pub unsafe fn from_raw_parts(ssl: *mut ffi::SSL, stream: S) -> Self {
|
||||||
let ssl = Ssl::from_ptr(ssl);
|
let ssl = Ssl::from_ptr(ssl);
|
||||||
Self::new_base(ssl, stream)
|
Self::new(ssl, stream).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like `read`, but takes a possibly-uninitialized slice.
|
/// Like `read`, but takes a possibly-uninitialized slice.
|
||||||
|
|
@ -4338,7 +4335,7 @@ where
|
||||||
/// Begin creating an `SslStream` atop `stream`
|
/// Begin creating an `SslStream` atop `stream`
|
||||||
pub fn new(ssl: Ssl, stream: S) -> Self {
|
pub fn new(ssl: Ssl, stream: S) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: SslStream::new_base(ssl, stream),
|
inner: SslStream::new(ssl, stream).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue