1//! Error when parsing a bridge line from a string
2//
3// This module is included even if we don't have bridge support enabled,
4// but all but one of the error variants are suppressed, making the error a unit enum.
56use thiserror::Error;
78use tor_linkspec::ChannelMethod;
910/// Error when parsing a bridge line from a string
11#[derive(Error, Clone, Debug)]
12#[non_exhaustive]
13pub enum BridgeParseError {
14/// Bridge line was empty
15#[cfg(feature = "bridge-client")]
16 #[error("Bridge line was empty")]
17Empty,
1819/// Expected PT name or host:port, looked a bit like a PT name, but didn't parse
20#[cfg(feature = "bridge-client")]
21 #[error(
22"Cannot parse {word:?} as PT name ({pt_error}), nor as direct bridge IpAddress:ORPort"
23)]
24InvalidPtOrAddr {
25/// The offending word
26word: String,
27/// Why we couldn't parse it as a PT name
28pt_error: tor_linkspec::TransportIdError,
29 },
3031/// Expected PT name or host:port, looked a bit like a host:port, but didn't parse
32#[cfg(feature = "bridge-client")]
33 #[error(
34"Cannot parse {word:?} as direct bridge IpAddress:ORPort ({addr_error}), nor as PT name"
35)]
36InvalidIpAddrOrPt {
37/// The offending word
38word: String,
39/// Why we couldn't parse it as an IP address and port
40addr_error: std::net::AddrParseError,
41 },
4243/// Cannot parse pluggable transport host address
44#[cfg(feature = "pt-client")]
45 #[error("Cannot parse {word:?} as pluggable transport Host:ORPort")]
46InvalidIPtHostAddr {
47/// The offending word
48word: String,
49/// Why we couldn't parse it as a PT target Host:ORPort
50#[source]
51source: tor_linkspec::BridgeAddrError,
52 },
5354/// Cannot parse value as identity key, or PT key=value
55#[cfg(feature = "bridge-client")]
56 #[error("Cannot parse {word:?} as identity key ({id_error}), or PT key=value")]
57InvalidIdentityOrParameter {
58/// The offending word
59word: String,
60/// Why we couldn't parse it as a fingerprint
61id_error: tor_linkspec::RelayIdError,
62 },
6364/// PT key=value parameter does not contain an equals sign
65#[cfg(feature = "pt-client")]
66 #[error("Expected PT key=value parameter, found {word:?} (which lacks an equals sign)")]
67InvalidPtKeyValue {
68/// The offending word
69word: String,
70 },
7172/// Invalid pluggable transport setting syntax
73#[cfg(feature = "pt-client")]
74 #[error("Cannot parse {word:?} as a PT key=value parameter")]
75InvalidPluggableTransportSetting {
76/// The offending word
77word: String,
78/// Why we couldn't parse it
79#[source]
80source: tor_linkspec::PtTargetInvalidSetting,
81 },
8283/// More than one identity of the same type specified
84#[cfg(feature = "bridge-client")]
85 #[error("More than one identity of the same type specified, at {word:?}")]
86MultipleIdentitiesOfSameType {
87/// The offending word
88word: String,
89 },
9091/// Identity specified of unsupported type
92#[cfg(feature = "bridge-client")]
93 #[error("Identity specified but not of supported type, at {word:?}")]
94UnsupportedIdentityType {
95/// The offending word
96word: String,
97 },
9899/// Channel method specified of unsupported type
100 ///
101 /// This can only occur with unusual (unsupported) combinations of cargo features,
102 /// or building an older `tor-guardmgr` against a newer `tor-linkspec`.
103#[error("Channel method specified but not of supported type ({method:?})")]
104UnsupportedChannelMethod {
105/// The not-understood method
106method: Box<ChannelMethod>,
107 },
108109/// Parameters may only be specified with a pluggable transport
110#[cfg(feature = "bridge-client")]
111 #[error("Parameters supplied but not valid without a pluggable transport")]
112DirectParametersNotAllowed,
113114/// Every bridge must have an RSA identity
115#[cfg(feature = "bridge-client")]
116 #[error("Bridge line lacks specification of RSA identity key")]
117NoRsaIdentity,
118119/// Pluggable transport support disabled in cargo features
120// We deliberately make this one *not* configured out if PT support is enabled
121#[cfg(feature = "bridge-client")]
122 #[error("Pluggable transport requested ({word:?} is not an IpAddress:ORPort), but support disabled in cargo features")]
123PluggableTransportsNotSupported {
124/// The offending word
125word: String,
126 },
127128/// Bridge support disabled in cargo features
129// We deliberately make this one *not* configured out if bridge support is enabled
130#[error("Bridge requested, but support disabled in cargo features")]
131BridgesNotSupported,
132}