Skip to content

Commit

Permalink
Expose SSL_get_error
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse authored and nox committed Jan 9, 2024
1 parent 20f9991 commit 0f5731b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions boring/src/ssl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 10 additions & 5 deletions boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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`].
Expand Down Expand Up @@ -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())),
Expand Down

0 comments on commit 0f5731b

Please sign in to comment.