Skip to content

Commit dd55052

Browse files
committed
Drop OnionV2 parser
1 parent 0caa19e commit dd55052

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lightning/src/ln/msgs.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,8 @@ pub enum SocketAddressParseError {
918918
InvalidInput,
919919
/// Invalid port
920920
InvalidPort,
921-
/// Invalid onion address
922-
InvalidOnion,
921+
/// Invalid onion v3 address
922+
InvalidOnionV3,
923923
}
924924

925925
impl fmt::Display for SocketAddressParseError {
@@ -929,7 +929,7 @@ impl fmt::Display for SocketAddressParseError {
929929
SocketAddressParseError::InvalidInput => write!(f, "Invalid input format. \
930930
Expected: \"<ipv4>:<port>\", \"[<ipv6>]:<port>\", \"<onion address>.onion:<port>\" or \"<hostname>:<port>\""),
931931
SocketAddressParseError::InvalidPort => write!(f, "Invalid port"),
932-
SocketAddressParseError::InvalidOnion => write!(f, "Invalid onion address"),
932+
SocketAddressParseError::InvalidOnionV3 => write!(f, "Invalid onion v3 address"),
933933
}
934934
}
935935
}
@@ -964,18 +964,12 @@ impl From<std::net::SocketAddr> for SocketAddress {
964964
pub fn parse_onion_address(host: &str, port: u16) -> Result<SocketAddress, SocketAddressParseError> {
965965
if host.ends_with(".onion") {
966966
let domain = &host[..host.len() - ".onion".len()];
967-
if domain.len() != 56 && domain.len() != 16 {
968-
return Err(SocketAddressParseError::InvalidOnion);
969-
}
970-
let mut onion = base32::Alphabet::RFC4648 { padding: false }.decode(&domain).map_err(|_| SocketAddressParseError::InvalidOnion)?;
971-
if onion.len() == 10 {
972-
onion.extend_from_slice(&port.to_be_bytes());
973-
let mut bytes = [0; 12];
974-
bytes.copy_from_slice(&onion);
975-
return Ok(SocketAddress::OnionV2(bytes));
967+
if domain.len() != 56 {
968+
return Err(SocketAddressParseError::InvalidOnionV3);
976969
}
970+
let onion = base32::Alphabet::RFC4648 { padding: false }.decode(&domain).map_err(|_| SocketAddressParseError::InvalidOnionV3)?;
977971
if onion.len() != 35 {
978-
return Err(SocketAddressParseError::InvalidOnion);
972+
return Err(SocketAddressParseError::InvalidOnionV3);
979973
}
980974
let version = onion[0];
981975
let first_checksum_flag = onion[1];
@@ -4129,8 +4123,8 @@ mod tests {
41294123
assert_eq!(hostname, SocketAddress::from_str(&hostname.to_string()).unwrap());
41304124

41314125
let onion_v2 = SocketAddress::OnionV2 ([40, 4, 64, 185, 202, 19, 162, 75, 90, 200, 38, 7],);
4132-
assert_eq!(onion_v2, SocketAddress::from_str("facebookcorewwwi.onion:9735").unwrap());
4133-
assert_eq!(onion_v2, SocketAddress::from_str(&onion_v2.to_string()).unwrap());
4126+
assert_eq!("FACEBOOKCOREWWWI.onion:9735", &onion_v2.to_string());
4127+
assert_eq!(Err(SocketAddressParseError::InvalidOnionV3), SocketAddress::from_str("FACEBOOKCOREWWWI.onion:9735"));
41344128

41354129
let onion_v3 = SocketAddress::OnionV3 {
41364130
ed25519_pubkey: [37, 24, 75, 5, 25, 73, 117, 194, 139, 102, 182, 107, 4, 105, 247, 246, 85,
@@ -4142,7 +4136,7 @@ mod tests {
41424136
assert_eq!(onion_v3, SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:1234").unwrap());
41434137
assert_eq!(onion_v3, SocketAddress::from_str(&onion_v3.to_string()).unwrap());
41444138

4145-
assert_eq!(Err(SocketAddressParseError::InvalidOnion), SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6.onion:1234"));
4139+
assert_eq!(Err(SocketAddressParseError::InvalidOnionV3), SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6.onion:1234"));
41464140
assert_eq!(Err(SocketAddressParseError::InvalidInput), SocketAddress::from_str("127.0.0.1@1234"));
41474141
assert_eq!(Err(SocketAddressParseError::InvalidInput), "".parse::<SocketAddress>());
41484142
assert!(SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion.onion:9735:94").is_err());

0 commit comments

Comments
 (0)