Skip to content

Commit 63f5eed

Browse files
committed
Eliminate methods to pass in ruslts config directly
1 parent 6d17e58 commit 63f5eed

File tree

4 files changed

+5
-62
lines changed

4 files changed

+5
-62
lines changed

tonic/src/transport/channel/tls.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub struct ClientTlsConfig {
1414
domain: Option<String>,
1515
cert: Option<Certificate>,
1616
identity: Option<Identity>,
17-
rustls_raw: Option<tokio_rustls::rustls::ClientConfig>,
1817
}
1918

2019
#[cfg(feature = "tls")]
@@ -36,7 +35,6 @@ impl ClientTlsConfig {
3635
domain: None,
3736
cert: None,
3837
identity: None,
39-
rustls_raw: None,
4038
}
4139
}
4240

@@ -49,8 +47,6 @@ impl ClientTlsConfig {
4947
}
5048

5149
/// Sets the CA Certificate against which to verify the server's TLS certificate.
52-
///
53-
/// This has no effect if `rustls_client_config` is used to configure Rustls.
5450
pub fn ca_certificate(self, ca_certificate: Certificate) -> Self {
5551
ClientTlsConfig {
5652
cert: Some(ca_certificate),
@@ -59,35 +55,18 @@ impl ClientTlsConfig {
5955
}
6056

6157
/// Sets the client identity to present to the server.
62-
///
63-
/// This has no effect if `rustls_client_config` is used to configure Rustls.
6458
pub fn identity(self, identity: Identity) -> Self {
6559
ClientTlsConfig {
6660
identity: Some(identity),
6761
..self
6862
}
6963
}
7064

71-
/// Use options specified by the given `ClientConfig` to configure TLS.
72-
///
73-
/// This overrides all other TLS options set via other means.
74-
pub fn rustls_client_config(self, config: tokio_rustls::rustls::ClientConfig) -> Self {
75-
ClientTlsConfig {
76-
rustls_raw: Some(config),
77-
..self
78-
}
79-
}
80-
8165
pub(crate) fn tls_connector(&self, uri: Uri) -> Result<TlsConnector, crate::Error> {
8266
let domain = match &self.domain {
8367
None => uri.host().ok_or_else(Error::new_invalid_uri)?.to_string(),
8468
Some(domain) => domain.clone(),
8569
};
86-
match &self.rustls_raw {
87-
None => {
88-
TlsConnector::new_with_rustls_cert(self.cert.clone(), self.identity.clone(), domain)
89-
}
90-
Some(c) => TlsConnector::new_with_rustls_raw(c.clone(), domain),
91-
}
70+
TlsConnector::new(self.cert.clone(), self.identity.clone(), domain)
9271
}
9372
}

tonic/src/transport/server/tls.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::fmt;
1111
pub struct ServerTlsConfig {
1212
identity: Option<Identity>,
1313
client_ca_root: Option<Certificate>,
14-
rustls_raw: Option<tokio_rustls::rustls::ServerConfig>,
1514
}
1615

1716
#[cfg(feature = "tls")]
@@ -28,7 +27,6 @@ impl ServerTlsConfig {
2827
ServerTlsConfig {
2928
identity: None,
3029
client_ca_root: None,
31-
rustls_raw: None,
3230
}
3331
}
3432

@@ -48,24 +46,7 @@ impl ServerTlsConfig {
4846
}
4947
}
5048

51-
/// Use options specified by the given `ServerConfig` to configure TLS.
52-
///
53-
/// This overrides all other TLS options set via other means.
54-
pub fn rustls_server_config(
55-
&mut self,
56-
config: tokio_rustls::rustls::ServerConfig,
57-
) -> &mut Self {
58-
self.rustls_raw = Some(config);
59-
self
60-
}
61-
6249
pub(crate) fn tls_acceptor(&self) -> Result<TlsAcceptor, crate::Error> {
63-
match &self.rustls_raw {
64-
None => TlsAcceptor::new_with_rustls_identity(
65-
self.identity.clone().unwrap(),
66-
self.client_ca_root.clone(),
67-
),
68-
Some(config) => TlsAcceptor::new_with_rustls_raw(config.clone()),
69-
}
50+
TlsAcceptor::new(self.identity.clone().unwrap(), self.client_ca_root.clone())
7051
}
7152
}

tonic/src/transport/service/connector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<C> Connector<C> {
5252

5353
host.try_into()
5454
.ok()
55-
.and_then(|dns| TlsConnector::new_with_rustls_cert(None, None, dns).ok())
55+
.and_then(|dns| TlsConnector::new(None, None, dns).ok())
5656
}
5757
}
5858

tonic/src/transport/service/tls.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) struct TlsConnector {
3737

3838
impl TlsConnector {
3939
#[cfg(feature = "tls")]
40-
pub(crate) fn new_with_rustls_cert(
40+
pub(crate) fn new(
4141
ca_cert: Option<Certificate>,
4242
identity: Option<Identity>,
4343
domain: String,
@@ -82,14 +82,6 @@ impl TlsConnector {
8282
};
8383

8484
config.alpn_protocols.push(ALPN_H2.as_bytes().to_vec());
85-
Self::new_with_rustls_raw(config, domain)
86-
}
87-
88-
#[cfg(feature = "tls")]
89-
pub(crate) fn new_with_rustls_raw(
90-
config: tokio_rustls::rustls::ClientConfig,
91-
domain: String,
92-
) -> Result<Self, crate::Error> {
9385
Ok(Self {
9486
config: Arc::new(config),
9587
domain: Arc::new(domain.as_str().try_into()?),
@@ -132,7 +124,7 @@ pub(crate) struct TlsAcceptor {
132124

133125
impl TlsAcceptor {
134126
#[cfg(feature = "tls")]
135-
pub(crate) fn new_with_rustls_identity(
127+
pub(crate) fn new(
136128
identity: Identity,
137129
client_ca_root: Option<Certificate>,
138130
) -> Result<Self, crate::Error> {
@@ -157,15 +149,6 @@ impl TlsAcceptor {
157149
})
158150
}
159151

160-
#[cfg(feature = "tls")]
161-
pub(crate) fn new_with_rustls_raw(
162-
config: tokio_rustls::rustls::ServerConfig,
163-
) -> Result<Self, crate::Error> {
164-
Ok(Self {
165-
inner: Arc::new(config),
166-
})
167-
}
168-
169152
pub(crate) async fn accept<IO>(&self, io: IO) -> Result<TlsStream<IO>, crate::Error>
170153
where
171154
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,

0 commit comments

Comments
 (0)