Skip to main content

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("Cannot parse {word:?} as PT name ({pt_error}), nor as direct bridge IpAddress:ORPort")]
22    InvalidPtOrAddr {
23        /// The offending word
24        word: String,
25        /// Why we couldn't parse it as a PT name
26        pt_error: tor_linkspec::TransportIdError,
27    },
28
29    /// Expected PT name or host:port, looked a bit like a host:port, but didn't parse
30    #[cfg(feature = "bridge-client")]
31    #[error(
32        "Cannot parse {word:?} as direct bridge IpAddress:ORPort ({addr_error}), nor as PT name"
33    )]
34    InvalidIpAddrOrPt {
35        /// The offending word
36        word: String,
37        /// Why we couldn't parse it as an IP address and port
38        addr_error: std::net::AddrParseError,
39    },
40
41    /// Cannot parse pluggable transport host address
42    #[cfg(feature = "pt-client")]
43    #[error("Cannot parse {word:?} as pluggable transport Host:ORPort")]
44    InvalidIPtHostAddr {
45        /// The offending word
46        word: String,
47        /// Why we couldn't parse it as a PT target Host:ORPort
48        #[source]
49        source: tor_linkspec::BridgeAddrError,
50    },
51
52    /// Cannot parse value as identity key, or PT key=value
53    #[cfg(feature = "bridge-client")]
54    #[error("Cannot parse {word:?} as identity key ({id_error}), or PT key=value")]
55    InvalidIdentityOrParameter {
56        /// The offending word
57        word: String,
58        /// Why we couldn't parse it as a fingerprint
59        id_error: tor_linkspec::RelayIdError,
60    },
61
62    /// PT key=value parameter does not contain an equals sign
63    #[cfg(feature = "pt-client")]
64    #[error("Expected PT key=value parameter, found {word:?} (which lacks an equals sign)")]
65    InvalidPtKeyValue {
66        /// The offending word
67        word: String,
68    },
69
70    /// Invalid pluggable transport setting syntax
71    #[cfg(feature = "pt-client")]
72    #[error("Cannot parse {word:?} as a PT key=value parameter")]
73    InvalidPluggableTransportSetting {
74        /// The offending word
75        word: String,
76        /// Why we couldn't parse it
77        #[source]
78        source: tor_linkspec::PtTargetInvalidSetting,
79    },
80
81    /// More than one identity of the same type specified
82    #[cfg(feature = "bridge-client")]
83    #[error("More than one identity of the same type specified, at {word:?}")]
84    MultipleIdentitiesOfSameType {
85        /// The offending word
86        word: String,
87    },
88
89    /// Identity specified of unsupported type
90    #[cfg(feature = "bridge-client")]
91    #[error("Identity specified but not of supported type, at {word:?}")]
92    UnsupportedIdentityType {
93        /// The offending word
94        word: String,
95    },
96
97    /// Channel method specified of unsupported type
98    ///
99    /// This can only occur with unusual (unsupported) combinations of cargo features,
100    /// or building an older `tor-guardmgr` against a newer `tor-linkspec`.
101    #[error("Channel method specified but not of supported type ({method:?})")]
102    UnsupportedChannelMethod {
103        /// The not-understood method
104        method: Box<ChannelMethod>,
105    },
106
107    /// Parameters may only be specified with a pluggable transport
108    #[cfg(feature = "bridge-client")]
109    #[error("Parameters supplied but not valid without a pluggable transport")]
110    DirectParametersNotAllowed,
111
112    /// Every bridge must have an RSA identity
113    #[cfg(feature = "bridge-client")]
114    #[error("Bridge line lacks specification of RSA identity key")]
115    NoRsaIdentity,
116
117    /// Pluggable transport support disabled in cargo features
118    // We deliberately make this one *not* configured out if PT support is enabled
119    #[cfg(feature = "bridge-client")]
120    #[error(
121        "Pluggable transport requested ({word:?} is not an IpAddress:ORPort), but support disabled in cargo features"
122    )]
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}