Skip to content

Commit

Permalink
refactor(client+transport)!: split tls into tls and
Browse files Browse the repository at this point in the history
`tls-rustls-platform-verifier` features
  • Loading branch information
oleonardolima committed Jun 28, 2024
1 parent 9ebc4c1 commit 7bd0601
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion client/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ gloo-net = { version = "0.5.0", default-features = false, features = ["json", "w
futures-channel = { version = "0.3.14", default-features = false, optional = true }

[features]
tls = ["tokio-rustls", "rustls-pki-types", "rustls-platform-verifier", "rustls"]
tls = ["rustls", "tokio-rustls", "rustls-pki-types"]
tls-rustls-platform-verifier = ["tls", "rustls-platform-verifier"]
default = ["tls-rustls-platform-verifier"]

ws = [
"base64",
Expand Down
4 changes: 3 additions & 1 deletion client/transport/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub type CustomCertStore = rustls::ClientConfig;
#[cfg(feature = "tls")]
#[derive(Debug, Clone)]
pub enum CertificateStore {
#[cfg(feature = "tls-rustls-platform-verifier")]
/// Native.
Native,
/// Custom certificate store.
Expand Down Expand Up @@ -103,7 +104,7 @@ pub struct WsTransportClientBuilder {
impl Default for WsTransportClientBuilder {
fn default() -> Self {
Self {
#[cfg(feature = "tls")]
#[cfg(feature = "tls-rustls-platform-verifier")]
certificate_store: CertificateStore::Native,
max_request_size: TEN_MB_SIZE_BYTES,
max_response_size: TEN_MB_SIZE_BYTES,
Expand Down Expand Up @@ -614,6 +615,7 @@ impl TryFrom<url::Url> for Target {
#[cfg(feature = "tls")]
fn build_tls_config(cert_store: &CertificateStore) -> Result<tokio_rustls::TlsConnector, WsHandshakeError> {
let config = match cert_store {
#[cfg(feature = "tls-rustls-platform-verifier")]
CertificateStore::Native => rustls_platform_verifier::tls_config(),
CertificateStore::Custom(cfg) => cfg.clone(),
};
Expand Down
3 changes: 2 additions & 1 deletion client/ws-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ rustls = { version = "0.23.7", default-features = false, features = ["logging",

[features]
tls = ["jsonrpsee-client-transport/tls"]
default = ["tls"]
tls-rustls-platform-verifier = ["jsonrpsee-client-transport/tls-rustls-platform-verifier"]
default = ["tls-rustls-platform-verifier"]

[package.metadata.docs.rs]
all-features = true
Expand Down
10 changes: 5 additions & 5 deletions client/ws-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use url::Url;
#[cfg(feature = "tls")]
pub use jsonrpsee_client_transport::ws::CustomCertStore;

#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))]
use jsonrpsee_client_transport::ws::CertificateStore;

/// Builder for [`WsClient`].
Expand Down Expand Up @@ -83,7 +83,7 @@ use jsonrpsee_client_transport::ws::CertificateStore;
/// ```
#[derive(Clone, Debug)]
pub struct WsClientBuilder {
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))]
certificate_store: CertificateStore,
max_request_size: u32,
max_response_size: u32,
Expand All @@ -102,7 +102,7 @@ pub struct WsClientBuilder {
impl Default for WsClientBuilder {
fn default() -> Self {
Self {
#[cfg(feature = "tls")]
#[cfg(feature = "tls-rustls-platform-verifier")]
certificate_store: CertificateStore::Native,
max_request_size: TEN_MB_SIZE_BYTES,
max_response_size: TEN_MB_SIZE_BYTES,
Expand Down Expand Up @@ -320,7 +320,7 @@ impl WsClientBuilder {
T: AsyncRead + AsyncWrite + Unpin + MaybeSend + 'static,
{
let transport_builder = WsTransportClientBuilder {
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))]
certificate_store: self.certificate_store.clone(),
connection_timeout: self.connection_timeout,
headers: self.headers.clone(),
Expand All @@ -346,7 +346,7 @@ impl WsClientBuilder {
/// Panics if being called outside of `tokio` runtime context.
pub async fn build(self, url: impl AsRef<str>) -> Result<WsClient, Error> {
let transport_builder = WsTransportClientBuilder {
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))]
certificate_store: self.certificate_store.clone(),
connection_timeout: self.connection_timeout,
headers: self.headers.clone(),
Expand Down

0 comments on commit 7bd0601

Please sign in to comment.