Skip to content
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

add TlsError::into_service_error #420

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions actix-tls/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* Add configurable timeout for accepting TLS connection. [#393]
* Added `TlsError::Timeout` variant. [#393]
* All TLS acceptor services now use `TlsError` for their error types. [#393]
* Added `TlsError::into_service_error`. [#420]

[#393]: https://github.com/actix/actix-net/pull/393
[#420]: https://github.com/actix/actix-net/pull/420


## 3.0.0-beta.8 - 2021-11-15
Expand Down
29 changes: 27 additions & 2 deletions actix-tls/src/accept/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! TLS acceptor services.

use std::sync::atomic::{AtomicUsize, Ordering};
use std::{
convert::Infallible,
sync::atomic::{AtomicUsize, Ordering},
};

use actix_utils::counter::Counter;

Expand Down Expand Up @@ -36,7 +39,29 @@ pub fn max_concurrent_tls_connect(num: usize) {
/// TLS error combined with service error.
#[derive(Debug)]
pub enum TlsError<TlsErr, SvcErr> {
Tls(TlsErr),
Timeout,
Tls(TlsErr),
Service(SvcErr),
}

impl<TlsErr> TlsError<TlsErr, Infallible> {
/// Casts the infallible service error type returned from acceptors into caller's type.
pub fn into_service_error<SvcErr>(self) -> TlsError<TlsErr, SvcErr> {
match self {
Self::Timeout => TlsError::Timeout,
Self::Tls(err) => TlsError::Tls(err),
Self::Service(_) => unreachable!(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn tls_service_error_inference() {
let a: TlsError<u32, Infallible> = TlsError::Tls(42);
let _b: TlsError<u32, u64> = a.into_service_error();
}
}
1 change: 0 additions & 1 deletion actix-tls/src/accept/native_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl<T: ActixStream + 'static> ServiceFactory<T> for Acceptor {
type Response = TlsStream<T>;
type Error = TlsError<Error, Infallible>;
type Config = ();

type Service = NativeTlsAcceptorService;
type InitError = ();
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
Expand Down
1 change: 0 additions & 1 deletion actix-tls/src/accept/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ impl<T: ActixStream> ServiceFactory<T> for Acceptor {
type Response = TlsStream<T>;
type Error = TlsError<io::Error, Infallible>;
type Config = ();

type Service = AcceptorService;
type InitError = ();
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
Expand Down
2 changes: 1 addition & 1 deletion actix-tls/src/connect/tls/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ where
}

pub enum RustlsConnectorServiceFuture<T, U> {
/// See issue https://github.com/briansmith/webpki/issues/54
/// See issue <https://github.com/briansmith/webpki/issues/54>
InvalidDns,
Future {
connect: Connect<U>,
Expand Down