-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tokio-boring: Add additional accessors to HandshakeError
#57
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,6 +307,40 @@ impl<S> HandshakeError<S> { | |
_ => None, | ||
} | ||
} | ||
|
||
/// Returns a reference to the inner SSL error, if this error was caused by | ||
/// a SSL error. | ||
pub fn as_ssl_error(&self) -> Option<&boring::error::ErrorStack> { | ||
match &self.0 { | ||
ssl::HandshakeError::Failure(s) => s.error().ssl_error(), | ||
ssl::HandshakeError::SetupFailure(ref s) => Some(s), | ||
_ => None, | ||
} | ||
} | ||
|
||
/// Consumes `self` and returns the inner I/O error by value, if this error | ||
/// was caused by an I/O error. | ||
pub fn into_io_error(self) -> Option<io::Error> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I'm not sure that this is valuable for us... If it's not an Io error we lose the original error? I guess we'd have to use something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about adding an Unfortunately, we can't return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @olix0r okay, I've modified these to return error
.into_ssl_error()
.map(Into::into)
.or_else(|error| error.into_io_error().map(Into::into)) or similar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome! |
||
match self.0 { | ||
ssl::HandshakeError::Failure(s) => s.into_error().into_io_error().ok(), | ||
_ => None, | ||
} | ||
} | ||
|
||
/// Consumes `self` and returns the inner SSL error by value, if this error | ||
/// was caused by n SSL error. | ||
pub fn into_ssl_error(self) -> Option<boring::error::ErrorStack> { | ||
match self.0 { | ||
// TODO(eliza): it's not great that we have to clone in this case, | ||
// but `boring::ssl::Error` doesn't currently expose an | ||
// `into_ssl_error` the way it does for `io::Error`s. We could add | ||
// that in a separate PR, but adding that here would make | ||
// `tokio-boring` depend on a new release of `boring`... | ||
ssl::HandshakeError::Failure(s) => s.into_error().ssl_error().cloned(), | ||
ssl::HandshakeError::SetupFailure(stack) => Some(stack), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl<S> fmt::Debug for HandshakeError<S> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also handle
HandshakeError::WouldBlock
? Or is it impossible somehow for WouldBlock to be an SSL error?