-
Notifications
You must be signed in to change notification settings - Fork 144
tokio-boring: Add additional accessors to HandshakeError
#57
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
base: master
Are you sure you want to change the base?
Changes from all commits
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,58 @@ 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. | ||||||
| /// | ||||||
| /// If this error was not caused by an I/O error, returns `Err(self)` so | ||||||
| /// that the error value can be reused. | ||||||
| pub fn into_io_error(self) -> Result<io::Error, Self> { | ||||||
| match self.0 { | ||||||
| ssl::HandshakeError::Failure(s) => { | ||||||
|
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.
Suggested change
|
||||||
| if s.error().io_error().is_some() { | ||||||
| Ok(s.into_error().into_io_error().expect( | ||||||
| "if `s.error().io_error().is_some()`, `into_io_error()` must succeed", | ||||||
| )) | ||||||
|
Comment on lines
+330
to
+332
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 think you could avoid the |
||||||
| } else { | ||||||
| Err(Self(ssl::HandshakeError::Failure(s))) | ||||||
| } | ||||||
| } | ||||||
| _ => Err(self), | ||||||
|
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.
Suggested change
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Consumes `self` and returns the inner SSL error by value, if this error | ||||||
| /// was caused by a SSL error. | ||||||
| /// | ||||||
| /// If this error was not caused by a SSL error, returns `Err(self)` so | ||||||
| /// that the error value can be reused. | ||||||
| pub fn into_ssl_error(self) -> Result<boring::error::ErrorStack, Self> { | ||||||
| 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 | ||||||
| .error() | ||||||
| .ssl_error() | ||||||
| .cloned() | ||||||
| .ok_or_else(|| Self(ssl::HandshakeError::Failure(s))), | ||||||
|
Comment on lines
+348
to
+357
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'd rather add 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. Sure! I was trying to limit the API additions because I wasn't sure what would be preferred by the maintainers, but I'm happy to change that. |
||||||
| ssl::HandshakeError::SetupFailure(stack) => Ok(stack), | ||||||
| _ => Err(self), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| 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?