Expose SSL_get_error

This commit is contained in:
Evan Rittenhouse 2024-01-08 08:43:46 -06:00 committed by Anthony Ramine
parent 20f9991c18
commit 0f5731b1d8
2 changed files with 13 additions and 5 deletions

View File

@ -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);

View File

@ -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<S> SslStream<S> {
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())),