From c99cf581f7aed9078abea8f984c06b16cbc2e69f Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Sat, 12 Sep 2026 15:24:50 -0700 Subject: [PATCH 1/3] feat(esp-radio): make Ssid::as_bytes public Ssid::as_str truncates at the first invalid UTF-8 byte and the Wi-Fi standard allows any 32 bytes, so a scanned non-UTF-8 network name has no public way to be read back out as bytes for storage. `Ssid` already implements `TryFrom<&[u8]>` publicly, which covers rebuilding an SSID from stored bytes; only the accessor to get the bytes out was missing. --- esp-radio/src/wifi/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 8734a373483..4f8ce516845 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -782,7 +782,13 @@ impl Ssid { }) } - pub(crate) fn as_bytes(&self) -> &[u8] { + /// The SSID as raw bytes. + /// + /// An SSID is at most 32 bytes and is not required to be valid UTF-8 + /// (the Wi-Fi standard allows arbitrary bytes). Use this to round-trip + /// an SSID that [`as_str`][Self::as_str] would otherwise lossily + /// truncate at the first invalid byte. + pub fn as_bytes(&self) -> &[u8] { &self.ssid[..self.len as usize] } From d965e59430a1e0a67b123c41aea5abd8c7a8c75c Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Thu, 17 Sep 2026 02:03:00 -0700 Subject: [PATCH 2/3] fix(esp-radio): mark Ssid::as_bytes unstable, document UTF-8 on as_str Review feedback on #6322: the new accessor is gated behind the `unstable` feature, and the note about lossy UTF-8 handling moves to `as_str`, the method whose behavior it describes. --- esp-radio/src/wifi/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 4f8ce516845..b0f527a6660 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -784,10 +784,8 @@ impl Ssid { /// The SSID as raw bytes. /// - /// An SSID is at most 32 bytes and is not required to be valid UTF-8 - /// (the Wi-Fi standard allows arbitrary bytes). Use this to round-trip - /// an SSID that [`as_str`][Self::as_str] would otherwise lossily - /// truncate at the first invalid byte. + /// An SSID is at most 32 bytes and is not required to be valid UTF-8. + #[instability::unstable] pub fn as_bytes(&self) -> &[u8] { &self.ssid[..self.len as usize] } @@ -803,6 +801,9 @@ impl Ssid { } /// The SSID as a string slice. + /// + /// An SSID is not required to be valid UTF-8; the result stops at the + /// first invalid byte. Use [`as_bytes`][Self::as_bytes] for the full bytes. pub fn as_str(&self) -> &str { let part = &self.ssid[..self.len as usize]; match str::from_utf8(part) { From b057b37a09f6ee524da8689997f120b6aded8b91 Mon Sep 17 00:00:00 2001 From: Juraj Sadel Date: Fri, 18 Sep 2026 13:25:42 +0200 Subject: [PATCH 3/3] Apply suggestion from @JurajSadel --- esp-radio/src/wifi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index b0f527a6660..eb2af5dc7ad 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -803,7 +803,7 @@ impl Ssid { /// The SSID as a string slice. /// /// An SSID is not required to be valid UTF-8; the result stops at the - /// first invalid byte. Use [`as_bytes`][Self::as_bytes] for the full bytes. + /// first invalid byte. Use `as_bytes` for the full bytes. pub fn as_str(&self) -> &str { let part = &self.ssid[..self.len as usize]; match str::from_utf8(part) {