Browse Source

Impl From<native_tls::Error> to TaurusError::InvalidCertificate

This patch adds `#[from]` to `TaurusError::InvalidCertificate` which
means that any `native_tls::Error` can be converted (using `From` and
`Into`) to a `TaurusError::InvalidCertificate`.

From what I can see, [here][native_tls_error_docs], the
`native_tls::Error` type is kind of a catch all for errors from that lib
rather than being broken down into suberrors (like `io::Error`)

[native_tls_error_docs]: https://docs.rs/native-tls/0.2.6/native_tls/struct.Error.html

Signed-off-by: Josh Leeb-du Toit <mail@joshleeb.com>
master
Josh Leeb-du Toit 4 years ago committed by Garrit Franke
parent
commit
8a83095654
  1. 2
      src/error.rs
  2. 5
      src/main.rs

2
src/error.rs

@ -10,7 +10,7 @@ pub enum TaurusError {
NoIdentity(io::Error),
#[error("failed parse certificate: {0:#?}")]
InvalidCertificate(native_tls::Error),
InvalidCertificate(#[from] native_tls::Error),
#[error("failed to bind: {0}")]
BindFailed(io::Error),

5
src/main.rs

@ -57,11 +57,10 @@ fn run() -> Result<(), error::TaurusError> {
// Read certificate
let identity = read_file(&cert_file).map_err(error::TaurusError::NoIdentity)?;
let identity = Identity::from_pkcs12(&identity, &config.certificate_password)
.map_err(error::TaurusError::InvalidCertificate)?;
let identity = Identity::from_pkcs12(&identity, &config.certificate_password)?;
let address = format!("0.0.0.0:{}", port);
let listener = TcpListener::bind(address).map_err(|err| error::TaurusError::BindFailed(err))?;
let listener = TcpListener::bind(address).map_err(error::TaurusError::BindFailed)?;
let acceptor = TlsAcceptor::new(identity).unwrap();
let acceptor = Arc::new(acceptor);

Loading…
Cancel
Save