aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl/mod.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2018-08-08 12:44:16 -0700
committerSteven Fackler <[email protected]>2018-08-08 13:19:55 -0700
commit1396143c661a9f9775328d60bc38b6fdec2a4c8a (patch)
tree176d7cd23ede4490083db0dcfa64b10c5c4b1299 /openssl/src/ssl/mod.rs
parentMerge pull request #972 from sfackler/err-unspecified-cfg (diff)
downloadrust-openssl-1396143c661a9f9775328d60bc38b6fdec2a4c8a.tar.xz
rust-openssl-1396143c661a9f9775328d60bc38b6fdec2a4c8a.zip
Add get_shutdown and set_shutdown
Diffstat (limited to 'openssl/src/ssl/mod.rs')
-rw-r--r--openssl/src/ssl/mod.rs64
1 files changed, 53 insertions, 11 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 666a97bb..7732765a 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -2734,8 +2734,7 @@ impl SslRef {
self.as_ptr(),
p as *mut c_uchar,
response.len() as c_long,
- ) as c_int)
- .map(|_| ())
+ ) as c_int).map(|_| ())
}
}
@@ -3016,6 +3015,30 @@ impl<S: Read + Write> SslStream<S> {
n => Err(self.make_error(n)),
}
}
+
+ /// Returns the session's shutdown state.
+ ///
+ /// This corresponds to [`SSL_get_shutdown`].
+ ///
+ /// [`SSL_get_shutdown`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_set_shutdown.html
+ pub fn get_shutdown(&mut self) -> ShutdownState {
+ unsafe {
+ let bits = ffi::SSL_get_shutdown(self.ssl.as_ptr());
+ ShutdownState { bits }
+ }
+ }
+
+ /// Sets the session's shutdown state.
+ ///
+ /// This can be used to tell OpenSSL that the session should be cached even if a full two-way
+ /// shutdown was not completed.
+ ///
+ /// This corresponds to [`SSL_set_shutdown`].
+ ///
+ /// [`SSL_set_shutdown`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_set_shutdown.html
+ pub fn set_shutdown(&mut self, state: ShutdownState) {
+ unsafe { ffi::SSL_set_shutdown(self.ssl.as_ptr(), state.bits()) }
+ }
}
impl<S> SslStream<S> {
@@ -3188,9 +3211,12 @@ where
} else {
let error = stream.make_error(ret);
match error.code() {
- ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => Err(HandshakeError::WouldBlock(
- MidHandshakeSslStream { stream, error },
- )),
+ ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
+ Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
+ stream,
+ error,
+ }))
+ }
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream,
error,
@@ -3208,9 +3234,12 @@ where
} else {
let error = stream.make_error(ret);
match error.code() {
- ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => Err(HandshakeError::WouldBlock(
- MidHandshakeSslStream { stream, error },
- )),
+ ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
+ Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
+ stream,
+ error,
+ }))
+ }
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream,
error,
@@ -3234,9 +3263,12 @@ where
} else {
let error = stream.make_error(ret);
match error.code() {
- ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => Err(HandshakeError::WouldBlock(
- MidHandshakeSslStream { stream, error },
- )),
+ ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
+ Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
+ stream,
+ error,
+ }))
+ }
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream,
error,
@@ -3344,6 +3376,16 @@ pub enum ShutdownResult {
Received,
}
+bitflags! {
+ /// The shutdown state of a session.
+ pub struct ShutdownState: c_int {
+ /// A close notify message has been sent to the peer.
+ const SENT = ffi::SSL_SENT_SHUTDOWN;
+ /// A close notify message has been received from the peer.
+ const RECEIVED = ffi::SSL_RECEIVED_SHUTDOWN;
+ }
+}
+
cfg_if! {
if #[cfg(any(ossl110, libressl273))] {
use ffi::{SSL_CTX_up_ref, SSL_SESSION_get_master_key, SSL_SESSION_up_ref, SSL_is_server};