Merge remote-tracking branch 'origin/mr/156'

This commit is contained in:
Nick Mathewson 2021-11-30 15:21:02 -05:00
commit 08267147ec
1 changed files with 5 additions and 2 deletions

View File

@ -95,7 +95,6 @@ pub struct TorAddr {
/// The target host. /// The target host.
host: Host, host: Host,
/// The target port number. /// The target port number.
// TODO: reject port 0.
port: u16, port: u16,
} }
@ -247,10 +246,14 @@ impl IntoTorAddr for &str {
let (host, port) = self.rsplit_once(':').ok_or(TorAddrError::NoPort)?; let (host, port) = self.rsplit_once(':').ok_or(TorAddrError::NoPort)?;
let host = host.parse()?; let host = host.parse()?;
let port = port.parse().map_err(|_| TorAddrError::BadPort)?; let port = port.parse().map_err(|_| TorAddrError::BadPort)?;
if port == 0 {
Err(TorAddrError::BadPort)
} else {
Ok(TorAddr { host, port }) Ok(TorAddr { host, port })
} }
} }
} }
}
impl IntoTorAddr for String { impl IntoTorAddr for String {
fn into_tor_addr(self) -> Result<TorAddr, TorAddrError> { fn into_tor_addr(self) -> Result<TorAddr, TorAddrError> {