rustls -> native_tls

This commit is contained in:
Martin Algesten
2018-06-14 14:17:39 +02:00
parent d4126027c8
commit ef6f8c6259
7 changed files with 176 additions and 80 deletions

View File

@@ -1,4 +1,7 @@
use std::io::Error as IoError;
use native_tls::Error as TlsError;
use native_tls::HandshakeError;
use std::net::TcpStream;
#[derive(Debug)]
pub enum Error {
@@ -10,6 +13,8 @@ pub enum Error {
BadStatus,
BadHeader,
Io(IoError),
Tls(TlsError),
TlsHandshake(HandshakeError<TcpStream>),
}
impl Error {
@@ -23,6 +28,8 @@ impl Error {
Error::BadStatus => 500,
Error::BadHeader => 500,
Error::Io(_) => 500,
Error::Tls(_) => 400,
Error::TlsHandshake(_) => 500,
}
}
pub fn status_text(&self) -> &str {
@@ -38,6 +45,8 @@ impl Error {
Error::BadStatus => "Bad Status",
Error::BadHeader => "Bad Header",
Error::Io(_) => "Network Error",
Error::Tls(_) => "TLS Error",
Error::TlsHandshake(_) => "TLS Handshake Error",
}
}
pub fn body_text(&self) -> String {
@@ -50,6 +59,8 @@ impl Error {
Error::BadStatus => "Bad Status".to_string(),
Error::BadHeader => "Bad Header".to_string(),
Error::Io(ioe) => format!("Network Error: {}", ioe),
Error::Tls(tls) => format!("TLS Error: {}", tls),
Error::TlsHandshake(he) => format!("TLS Handshake Error: {}", he),
}
}
}
@@ -59,3 +70,15 @@ impl From<IoError> for Error {
Error::Io(err)
}
}
impl From<TlsError> for Error {
fn from(err: TlsError) -> Error {
Error::Tls(err)
}
}
impl From<HandshakeError<TcpStream>> for Error {
fn from(err: HandshakeError<TcpStream>) -> Error {
Error::TlsHandshake(err)
}
}