#![cfg(feature = "alloc")]
use alloc::string::String;
pub(crate) mod algos;
pub mod client;
pub(crate) mod glob;
pub(crate) mod host_port;
#[cfg(feature = "std")]
pub(crate) mod include;
pub(crate) mod match_block;
pub(crate) mod parser;
pub mod server;
pub use algos::{
AlgoCategory, default_list as default_algorithms, known_names as supported_algorithms,
};
pub use client::{
AddressFamily, CanonicalizeHostname, ClientOptions, ControlMaster, ControlPersist,
DynamicForwardSpec, ForwardEndpoint, ForwardSpec, GatewayPorts, IdentityAgent, KnockSetting,
LocalForwardSpec, ObscureKeystrokeTiming, RemoteForwardSpec, RequestTty, SessionType,
SshClientConfig, StrictMode, parse_escape_char, parse_forward,
};
pub use glob::{HostPattern, host_matches};
pub use host_port::{parse_host_port, parse_host_port_pattern};
#[cfg(feature = "std")]
pub use include::{glob_paths, tokenize_file_with_includes};
pub use match_block::{
AddressKind, AddressPattern, ExecPolicy, MatchCondition, MatchContext, address_matches,
};
pub use parser::{ParsedLine, tokenize};
pub use server::{
Compression, HostPort, PerSourcePenalties, PermitRootLogin, RekeyLimit, ServerMatchBlock,
ServerOptions, SshServerConfig, TcpForwarding,
};
pub use server::{AddressFamily as ServerAddressFamily, GatewayPorts as ServerGatewayPorts};
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ConfigError {
Syntax {
line: usize,
msg: String,
},
UnknownKeyword {
line: usize,
keyword: String,
},
BadValue {
line: usize,
keyword: String,
msg: String,
},
Unsupported {
line: usize,
msg: String,
},
InFile {
file: String,
error: alloc::boxed::Box<ConfigError>,
},
}
impl ConfigError {
pub(crate) fn in_file(self, file: Option<&str>) -> Self {
match file {
Some(f) if !matches!(self, ConfigError::InFile { .. }) => ConfigError::InFile {
file: f.into(),
error: alloc::boxed::Box::new(self),
},
_ => self,
}
}
fn write_located(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ConfigError::Syntax { line, msg } => write!(f, "line {line}: syntax: {msg}"),
ConfigError::UnknownKeyword { line, keyword } => {
write!(f, "line {line}: unknown keyword: {keyword}")
}
ConfigError::BadValue { line, keyword, msg } => {
write!(f, "line {line}: bad value for {keyword}: {msg}")
}
ConfigError::Unsupported { line, msg } => {
write!(f, "line {line}: unsupported: {msg}")
}
ConfigError::InFile { file, error } => {
write!(f, "{file} ")?;
error.write_located(f)
}
}
}
}
impl core::fmt::Display for ConfigError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("config: ")?;
self.write_located(f)
}
}
#[cfg(feature = "std")]
impl std::error::Error for ConfigError {}