From 4029f6d2e06ce42af7177bf185de5a0b867d13a8 Mon Sep 17 00:00:00 2001 From: Charles Samuels Date: Fri, 3 Jan 2025 11:39:12 -0800 Subject: [PATCH] make it possible to have use-native-tls without use-rustls --- rumqttc/CHANGELOG.md | 1 + rumqttc/src/lib.rs | 24 ++++++++++++++++++++---- rumqttc/src/v5/state.rs | 22 +++++++++++++++++----- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/rumqttc/CHANGELOG.md b/rumqttc/CHANGELOG.md index 03eb79556..c1357c435 100644 --- a/rumqttc/CHANGELOG.md +++ b/rumqttc/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Replace `Vec>` with `FixedBitSet` for managing packet ids of released QoS 2 publishes and incoming QoS 2 publishes in `MqttState`. * Accept `native_tls::TlsConnector` as input for `Transport::tls_with_config`. * Update `thiserror` to `2.0.8`, `tokio-rustls` to `0.26.0`, `rustls-webpki` to `0.102.8`, `rustls-pemfile` to `2.2.0`, `rustls-native-certs` to `0.8.1`, `async-tungstenite` to `0.28.0`, `ws_stream_tungstenite` to `0.14.0`, `native-tls` to `0.2.12` and `tokio-stream` to `0.1.16`. +* `use-native-tls` and `url` can be used without rustls. ### Deprecated diff --git a/rumqttc/src/lib.rs b/rumqttc/src/lib.rs index 07694ffaf..27bb7a8f3 100644 --- a/rumqttc/src/lib.rs +++ b/rumqttc/src/lib.rs @@ -250,7 +250,7 @@ impl Transport { Self::Tcp } - #[cfg(feature = "use-rustls")] + #[cfg(any(feature = "use-rustls", feature = "use-native-tls"))] pub fn tls_with_default_config() -> Self { Self::tls_with_config(Default::default()) } @@ -311,8 +311,17 @@ impl Transport { Self::Wss(tls_config) } - #[cfg(all(feature = "use-rustls", feature = "websocket"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "use-rustls", feature = "websocket"))))] + #[cfg(all( + any(feature = "use-rustls", feature = "use-native-tls"), + feature = "websocket" + ))] + #[cfg_attr( + docsrs, + doc(cfg(all( + any(feature = "use-rustls", feature = "use-native-tls"), + feature = "websocket" + ))) + )] pub fn wss_with_default_config() -> Self { Self::Wss(Default::default()) } @@ -365,6 +374,13 @@ impl Default for TlsConfiguration { } } +#[cfg(all(feature = "use-native-tls", not(feature = "use-rustls")))] +impl Default for TlsConfiguration { + fn default() -> Self { + Self::Native + } +} + #[cfg(feature = "use-rustls")] impl From for TlsConfiguration { fn from(config: ClientConfig) -> Self { @@ -783,7 +799,7 @@ impl std::convert::TryFrom for MqttOptions { // Encrypted connections are supported, but require explicit TLS configuration. We fall // back to the unencrypted transport layer, so that `set_transport` can be used to // configure the encrypted transport layer with the provided TLS configuration. - #[cfg(feature = "use-rustls")] + #[cfg(any(feature = "use-rustls", feature = "use-native-tls"))] "mqtts" | "ssl" => (Transport::tls_with_default_config(), 8883), "mqtt" | "tcp" => (Transport::Tcp, 1883), #[cfg(feature = "websocket")] diff --git a/rumqttc/src/v5/state.rs b/rumqttc/src/v5/state.rs index 0f08a33b8..9a7485f3b 100644 --- a/rumqttc/src/v5/state.rs +++ b/rumqttc/src/v5/state.rs @@ -242,7 +242,7 @@ impl MqttState { } _ => { warn!("SubAck Pkid = {:?}, Reason = {:?}", suback.pkid, reason); - }, + } } } Ok(None) @@ -364,7 +364,10 @@ impl MqttState { if puback.reason != PubAckReason::Success && puback.reason != PubAckReason::NoMatchingSubscribers { - warn!("PubAck Pkid = {:?}, reason: {:?}", puback.pkid, puback.reason); + warn!( + "PubAck Pkid = {:?}, reason: {:?}", + puback.pkid, puback.reason + ); return Ok(None); } @@ -397,7 +400,10 @@ impl MqttState { if pubrec.reason != PubRecReason::Success && pubrec.reason != PubRecReason::NoMatchingSubscribers { - warn!("PubRec Pkid = {:?}, reason: {:?}", pubrec.pkid, pubrec.reason); + warn!( + "PubRec Pkid = {:?}, reason: {:?}", + pubrec.pkid, pubrec.reason + ); return Ok(None); } @@ -417,7 +423,10 @@ impl MqttState { self.incoming_pub.set(pubrel.pkid as usize, false); if pubrel.reason != PubRelReason::Success { - warn!("PubRel Pkid = {:?}, reason: {:?}", pubrel.pkid, pubrel.reason); + warn!( + "PubRel Pkid = {:?}, reason: {:?}", + pubrel.pkid, pubrel.reason + ); return Ok(None); } @@ -444,7 +453,10 @@ impl MqttState { self.outgoing_rel.set(pubcomp.pkid as usize, false); if pubcomp.reason != PubCompReason::Success { - warn!("PubComp Pkid = {:?}, reason: {:?}", pubcomp.pkid, pubcomp.reason); + warn!( + "PubComp Pkid = {:?}, reason: {:?}", + pubcomp.pkid, pubcomp.reason + ); return Ok(None); }