tor_guardmgr/bridge/config/
err.rs

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.
5
6use thiserror::Error;
7
8use tor_linkspec::ChannelMethod;
9
10/// 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")]
17    Empty,
18
19    /// 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    )]
24    InvalidPtOrAddr {
25        /// The offending word
26        word: String,
27        /// Why we couldn't parse it as a PT name
28        pt_error: tor_linkspec::TransportIdError,
29    },
30
31    /// 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    )]
36    InvalidIpAddrOrPt {
37        /// The offending word
38        word: String,
39        /// Why we couldn't parse it as an IP address and port
40        addr_error: std::net::AddrParseError,
41    },
42
43    /// Cannot parse pluggable transport host address
44    #[cfg(feature = "pt-client")]
45    #[error("Cannot parse {word:?} as pluggable transport Host:ORPort")]
46    InvalidIPtHostAddr {
47        /// The offending word
48        word: String,
49        /// Why we couldn't parse it as a PT target Host:ORPort
50        #[source]
51        source: tor_linkspec::BridgeAddrError,
52    },
53
54    /// 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")]
57    InvalidIdentityOrParameter {
58        /// The offending word
59        word: String,
60        /// Why we couldn't parse it as a fingerprint
61        id_error: tor_linkspec::RelayIdError,
62    },
63
64    /// 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)")]
67    InvalidPtKeyValue {
68        /// The offending word
69        word: String,
70    },
71
72    /// Invalid pluggable transport setting syntax
73    #[cfg(feature = "pt-client")]
74    #[error("Cannot parse {word:?} as a PT key=value parameter")]
75    InvalidPluggableTransportSetting {
76        /// The offending word
77        word: String,
78        /// Why we couldn't parse it
79        #[source]
80        source: tor_linkspec::PtTargetInvalidSetting,
81    },
82
83    /// 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:?}")]
86    MultipleIdentitiesOfSameType {
87        /// The offending word
88        word: String,
89    },
90
91    /// Identity specified of unsupported type
92    #[cfg(feature = "bridge-client")]
93    #[error("Identity specified but not of supported type, at {word:?}")]
94    UnsupportedIdentityType {
95        /// The offending word
96        word: String,
97    },
98
99    /// 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:?})")]
104    UnsupportedChannelMethod {
105        /// The not-understood method
106        method: Box<ChannelMethod>,
107    },
108
109    /// 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")]
112    DirectParametersNotAllowed,
113
114    /// Every bridge must have an RSA identity
115    #[cfg(feature = "bridge-client")]
116    #[error("Bridge line lacks specification of RSA identity key")]
117    NoRsaIdentity,
118
119    /// 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")]
123    PluggableTransportsNotSupported {
124        /// The offending word
125        word: String,
126    },
127
128    /// 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")]
131    BridgesNotSupported,
132}