Skip to content

Commit 9ddf5fe

Browse files
ghedonox
authored andcommitted
Add a few WouldBlock cases
1 parent 95db9de commit 9ddf5fe

2 files changed

Lines changed: 45 additions & 29 deletions

File tree

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
@@ -3163,11 +3163,9 @@ impl<S> MidHandshakeSslStream<S> {
31633163
Ok(self.stream)
31643164
} else {
31653165
self.error = self.stream.make_error(ret);
3166-
match self.error.code() {
3167-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3168-
Err(HandshakeError::WouldBlock(self))
3169-
}
3170-
_ => Err(HandshakeError::Failure(self)),
3166+
match self.error.would_block() {
3167+
true => Err(HandshakeError::WouldBlock(self)),
3168+
false => Err(HandshakeError::Failure(self)),
31713169
}
31723170
}
31733171
}
@@ -3472,14 +3470,12 @@ where
34723470
Ok(stream)
34733471
} else {
34743472
let error = stream.make_error(ret);
3475-
match error.code() {
3476-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3477-
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3478-
stream,
3479-
error,
3480-
}))
3481-
}
3482-
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
3473+
match error.would_block() {
3474+
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3475+
stream,
3476+
error,
3477+
})),
3478+
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
34833479
stream,
34843480
error,
34853481
})),
@@ -3495,14 +3491,12 @@ where
34953491
Ok(stream)
34963492
} else {
34973493
let error = stream.make_error(ret);
3498-
match error.code() {
3499-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3500-
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3501-
stream,
3502-
error,
3503-
}))
3504-
}
3505-
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
3494+
match error.would_block() {
3495+
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3496+
stream,
3497+
error,
3498+
})),
3499+
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
35063500
stream,
35073501
error,
35083502
})),
@@ -3524,14 +3518,12 @@ where
35243518
Ok(stream)
35253519
} else {
35263520
let error = stream.make_error(ret);
3527-
match error.code() {
3528-
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
3529-
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3530-
stream,
3531-
error,
3532-
}))
3533-
}
3534-
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
3521+
match error.would_block() {
3522+
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
3523+
stream,
3524+
error,
3525+
})),
3526+
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
35353527
stream,
35363528
error,
35373529
})),

0 commit comments

Comments
 (0)