Merge branch 'chanmethod-non-exhaustive' into 'main'

Make ChannelMethod non-exhaustive

See merge request tpo/core/arti!891
This commit is contained in:
Nick Mathewson 2022-11-27 19:36:22 +00:00
commit 8cf9e2a6a4
5 changed files with 35 additions and 2 deletions

View File

@ -278,6 +278,12 @@ impl<R: TcpProvider + Send + Sync> TransportHelper for ExternalProxyPlugin<R> {
)))
}
ChannelMethod::Pluggable(target) => target,
other => {
return Err(crate::Error::UnusableTarget(bad_api_usage!(
"Used unknown, unsupported, transport {:?} for a TCP connection.",
other,
)))
}
};
let protocol = settings_to_protocol(encode_settings(pt_target.settings()))?;

View File

@ -76,7 +76,9 @@ struct Inner {
/// Address and transport via which the bridge can be reached, and
/// the parameters for those transports.
///
/// Restriction: This `addrs` may NOT contain more than one address.
/// Restriction: This `addrs` may NOT contain more than one address,
/// and it must be a variant supported by the code in this crate:
/// ie, currently, `Direct` or `Pluggable`.
addrs: ChannelMethod,
/// The RSA identity of the bridge.
@ -367,6 +369,11 @@ impl FromStr for BridgeConfigBuilder {
let (transport, addr, settings) = target.into_parts();
(transport.into_inner(), vec![addr], settings.into_inner())
}
other => {
return Err(BridgeParseError::UnsupportedChannelMethod {
method: Box::new(other),
});
}
};
let ids = chain!(
@ -519,6 +526,7 @@ impl FromStr for Inner {
source,
}
})?,
other => panic!("made ourselves an unsupported ChannelMethod {:?}", other),
}
}
@ -557,6 +565,12 @@ impl Display for BridgeConfig {
write!(f, "{} {}", target.transport(), target.addr())?;
Some(target.settings())
}
_ => {
// This shouldn't happen, but panicking seems worse than outputting this
write!(f, "[unsupported channel method, cannot display properly]")?;
return Ok(());
}
};
// * One or more identity key fingerprints,

View File

@ -5,6 +5,8 @@
use thiserror::Error;
use tor_linkspec::ChannelMethod;
/// Error when parsing a bridge line from a string
#[derive(Error, Clone, Debug)]
#[non_exhaustive]
@ -94,6 +96,16 @@ pub enum BridgeParseError {
word: String,
},
/// Channel method specified of unsupported type
///
/// This can only occur with unusual (unsupported) combinations of cargo features,
/// or building an older `tor-guardmgr` against a newer `tor-linkspec`.
#[error("Channel method specified but not of supported type ({method:?})")]
UnsupportedChannelMethod {
/// The not-understood method
method: Box<ChannelMethod>,
},
/// Parameters may only be specified with a pluggable transport
#[cfg(feature = "bridge-client")]
#[error("Parameters supplied but not valid without a pluggable transport")]

View File

@ -9,3 +9,4 @@ BREAKING: Replaced functions to strip addresses from ChanMethod.
BREAKING: Remove impl Display for OwnedCircTarget.
ADDED: Provide deconstructors for PtTargetSettings and PtTarget
MODIFIED: Renaming PtTargetAddr to BridgeAddr (in progress, will become BREAKING)
BREAKING: ChannelMethod is now non-exhaustive

View File

@ -457,7 +457,7 @@ impl PtTarget {
/// pluggable transport, this includes information about the transport, and any
/// address and settings information that transport requires.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[allow(clippy::exhaustive_enums)]
#[non_exhaustive]
pub enum ChannelMethod {
/// Connect to the relay directly at one of several addresses.
Direct(Vec<std::net::SocketAddr>),