Make tokio-rustls dependency optional

This commit is contained in:
Dirkjan Ochtman 2021-12-22 11:58:02 +01:00 committed by masalachai
parent 0db2c6d008
commit 70f3789098
2 changed files with 11 additions and 5 deletions

View File

@ -7,14 +7,16 @@ authors = ["Ritesh Chitlangi <ritesh@ayravat.com>"]
description = "EPP (Extensible Provisioning Protocol) Client Library for Domain Registration and Management"
repository = "https://github.com/masalachai/epp-client"
[features]
default = ["tokio-rustls"]
[dependencies]
celes = "2.1"
chrono = "0.4"
quick-xml = { version = "0.22", features = [ "serialize" ] }
rustls = "0.20"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.0", features = [ "full" ] }
tokio-rustls = "0.23"
tokio-rustls = { version = "0.23", optional = true }
tracing = "0.1.29"
webpki-roots = "0.22.1"

View File

@ -34,14 +34,17 @@
//! ```
use std::convert::TryInto;
use std::io;
use std::net::SocketAddr;
use std::sync::Arc;
use std::io;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::TcpStream;
#[cfg(feature = "tokio-rustls")]
use tokio_rustls::client::TlsStream;
#[cfg(feature = "tokio-rustls")]
use tokio_rustls::rustls::{ClientConfig, OwnedTrustAnchor, RootCertStore};
#[cfg(feature = "tokio-rustls")]
use tokio_rustls::TlsConnector;
use tracing::info;
@ -60,6 +63,7 @@ pub struct EppClient<IO> {
connection: EppConnection<IO>,
}
#[cfg(feature = "tokio-rustls")]
impl EppClient<TlsStream<TcpStream>> {
/// Connect to the specified `addr` and `hostname` over TLS
///
@ -94,10 +98,10 @@ impl EppClient<TlsStream<TcpStream>> {
Some((certs, key)) => {
let certs = certs
.into_iter()
.map(|cert| rustls::Certificate(cert.0))
.map(|cert| tokio_rustls::rustls::Certificate(cert.0))
.collect();
builder
.with_single_cert(certs, rustls::PrivateKey(key.0))
.with_single_cert(certs, tokio_rustls::rustls::PrivateKey(key.0))
.map_err(|e| Error::Other(e.into()))?
}
None => builder.with_no_client_auth(),