diff --git a/boring/src/ssl/error.rs b/boring/src/ssl/error.rs index bc792c11..014eb188 100644 --- a/boring/src/ssl/error.rs +++ b/boring/src/ssl/error.rs @@ -13,6 +13,9 @@ use crate::ssl::MidHandshakeSslStream; pub struct ErrorCode(c_int); impl ErrorCode { + /// No error. + pub const NONE: ErrorCode = ErrorCode(ffi::SSL_ERROR_NONE); + /// The SSL session has been closed. pub const ZERO_RETURN: ErrorCode = ErrorCode(ffi::SSL_ERROR_ZERO_RETURN); diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index 91da2bbd..1524d8e0 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -2635,10 +2635,6 @@ impl SslRef { unsafe { ffi::SSL_write(self.as_ptr(), buf.as_ptr() as *const c_void, len) } } - fn get_error(&self, ret: c_int) -> ErrorCode { - unsafe { ErrorCode::from_raw(ffi::SSL_get_error(self.as_ptr(), ret)) } - } - #[cfg(feature = "kx-safe-default")] fn set_curves_list(&mut self, curves: &str) -> Result<(), ErrorStack> { let curves = CString::new(curves).unwrap(); @@ -2683,6 +2679,15 @@ impl SslRef { .expect("invalid default server curves list"); } + /// Returns an `ErrorCode` value for the most recent operation on this `SslRef`. + /// + /// This corresponds to [`SSL_get_error`]. + /// + /// [`SSL_get_error`]: https://github.com/google/boringssl/blob/master/include/openssl/ssl.h#L475 + pub fn error_code(&self, ret: c_int) -> ErrorCode { + unsafe { ErrorCode::from_raw(ffi::SSL_get_error(self.as_ptr(), ret)) } + } + /// Like [`SslContextBuilder::set_verify`]. /// /// This corresponds to [`SSL_set_verify`]. @@ -3762,7 +3767,7 @@ impl SslStream { fn make_error(&mut self, ret: c_int) -> Error { self.check_panic(); - let code = self.ssl.get_error(ret); + let code = self.ssl.error_code(ret); let cause = match code { ErrorCode::SSL => Some(InnerError::Ssl(ErrorStack::get())),