Fix connection string length checks
Some checks failed
Rust Checks / checks (push) Failing after 7s
Rust Checks / checks (pull_request) Failing after 7s

This commit is contained in:
Tipragot 2024-02-07 17:46:33 +01:00
parent f984920dbd
commit ddf5b38905

View file

@ -101,7 +101,7 @@ impl Connection {
let data = BASE64_URL_SAFE_NO_PAD let data = BASE64_URL_SAFE_NO_PAD
.decode(connection_string) .decode(connection_string)
.map_err(io::Error::other)?; .map_err(io::Error::other)?;
if data.len() != 6 { if data.len() != 22 {
return Err(io::Error::new( return Err(io::Error::new(
io::ErrorKind::InvalidInput, io::ErrorKind::InvalidInput,
format!("invalid connection string: {}", connection_string), format!("invalid connection string: {}", connection_string),
@ -372,9 +372,10 @@ impl Listener {
/// Returns the connection string that can be used to connect to th /// Returns the connection string that can be used to connect to th
/// listener. /// listener.
pub fn connection_string(&self) -> String { pub fn connection_string(&self) -> String {
let mut data = Vec::with_capacity(24); let mut data = Vec::with_capacity(22);
data.extend(self.2.ip().octets()); data.extend(self.2.ip().octets());
data.extend(self.2.port().to_ne_bytes()); data.extend(self.2.port().to_ne_bytes());
data.extend(self.3);
BASE64_URL_SAFE_NO_PAD.encode(&data) BASE64_URL_SAFE_NO_PAD.encode(&data)
} }
} }