Skip to content

Commit 6fcd97f

Browse files
ghedonox
authored andcommitted
Add a few WouldBlock cases
1 parent 98cd0a0 commit 6fcd97f

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

boring/src/ssl/error.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ impl ErrorCode {
2727
/// Wait for write readiness and retry the operation.
2828
pub const WANT_WRITE: ErrorCode = ErrorCode(ffi::SSL_ERROR_WANT_WRITE);
2929

30+
pub const WANT_X509_LOOKUP: ErrorCode = ErrorCode(ffi::SSL_ERROR_WANT_X509_LOOKUP);
31+
32+
pub const PENDING_SESSION: ErrorCode = ErrorCode(ffi::SSL_ERROR_PENDING_SESSION);
33+
34+
pub const PENDING_CERTIFICATE: ErrorCode = ErrorCode(ffi::SSL_ERROR_PENDING_CERTIFICATE);
35+
36+
pub const WANT_PRIVATE_KEY_OPERATION: ErrorCode =
37+
ErrorCode(ffi::SSL_ERROR_WANT_PRIVATE_KEY_OPERATION);
38+
39+
pub const PENDING_TICKET: ErrorCode = ErrorCode(ffi::SSL_ERROR_PENDING_TICKET);
40+
3041
/// A non-recoverable IO error occurred.
3142
pub const SYSCALL: ErrorCode = ErrorCode(ffi::SSL_ERROR_SYSCALL);
3243

@@ -81,6 +92,19 @@ impl Error {
8192
_ => None,
8293
}
8394
}
95+
96+
pub fn would_block(&self) -> bool {
97+
matches!(
98+
self.code,
99+
ErrorCode::WANT_READ
100+
| ErrorCode::WANT_WRITE
101+
| ErrorCode::WANT_X509_LOOKUP
102+
| ErrorCode::PENDING_SESSION
103+
| ErrorCode::PENDING_CERTIFICATE
104+
| ErrorCode::WANT_PRIVATE_KEY_OPERATION
105+
| ErrorCode::PENDING_TICKET
106+
)
107+
}
84108
}
85109

86110
impl From<ErrorStack> for Error {

boring/src/ssl/mod.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,11 +3167,9 @@ impl<S> MidHandshakeSslStream<S> {
31673167
Ok(self.stream)
31683168
} else {
31693169
self.error = self.stream.make_error(ret);
3170-
match self.error.code() {
3171-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3172-
Err(HandshakeError::WouldBlock(self))
3173-
}
3174-
_ => Err(HandshakeError::Failure(self)),
3170+
match self.error.would_block() {
3171+
true => Err(HandshakeError::WouldBlock(self)),
3172+
false => Err(HandshakeError::Failure(self)),
31753173
}
31763174
}
31773175
}
@@ -3476,14 +3474,12 @@ where
34763474
Ok(stream)
34773475
} else {
34783476
let error = stream.make_error(ret);
3479-
match error.code() {
3480-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3481-
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3482-
stream,
3483-
error,
3484-
}))
3485-
}
3486-
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
3477+
match error.would_block() {
3478+
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3479+
stream,
3480+
error,
3481+
})),
3482+
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
34873483
stream,
34883484
error,
34893485
})),
@@ -3499,14 +3495,12 @@ where
34993495
Ok(stream)
35003496
} else {
35013497
let error = stream.make_error(ret);
3502-
match error.code() {
3503-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3504-
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3505-
stream,
3506-
error,
3507-
}))
3508-
}
3509-
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
3498+
match error.would_block() {
3499+
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3500+
stream,
3501+
error,
3502+
})),
3503+
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
35103504
stream,
35113505
error,
35123506
})),
@@ -3528,14 +3522,12 @@ where
35283522
Ok(stream)
35293523
} else {
35303524
let error = stream.make_error(ret);
3531-
match error.code() {
3532-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3533-
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3534-
stream,
3535-
error,
3536-
}))
3537-
}
3538-
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
3525+
match error.would_block() {
3526+
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3527+
stream,
3528+
error,
3529+
})),
3530+
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
35393531
stream,
35403532
error,
35413533
})),

0 commit comments

Comments
 (0)