diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-06-12 06:37:06 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-06-12 06:37:06 +0200 |
| commit | cf3f8c185cede889faccd3d55655a494ccd6f707 (patch) | |
| tree | 149bb196e2a16cb8d297d03fc16f56f03c84dcfc /mumlib/src | |
| parent | dcd70175a98c83a3334d7980e5196bc866e04efb (diff) | |
| parent | b7701a6f61b525c116e29981f122a58552751f78 (diff) | |
| download | mum-cf3f8c185cede889faccd3d55655a494ccd6f707.tar.gz | |
Merge remote-tracking branch 'origin/invalid-cert'
Diffstat (limited to 'mumlib/src')
| -rw-r--r-- | mumlib/src/config.rs | 14 | ||||
| -rw-r--r-- | mumlib/src/error.rs | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index 1bd3784..3edef37 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -10,8 +10,15 @@ use std::path::{Path, PathBuf}; use toml::value::Array; use toml::Value; +/// A TOML-friendly version of [Config]. +/// +/// Values need to be placed before tables due to how TOML works. #[derive(Debug, Deserialize, Serialize)] struct TOMLConfig { + // Values + accept_all_invalid_certs: Option<bool>, + + // Tables audio: Option<AudioConfig>, servers: Option<Array>, } @@ -20,6 +27,10 @@ struct TOMLConfig { pub struct Config { pub audio: AudioConfig, pub servers: Vec<ServerConfig>, + /// Whether we allow connecting to servers with invalid server certificates. + /// + /// None implies false but we can show a better message to the user. + pub allow_invalid_server_cert: Option<bool>, } impl Config { @@ -64,6 +75,7 @@ pub struct ServerConfig { pub port: Option<u16>, pub username: Option<String>, pub password: Option<String>, + pub accept_invalid_cert: Option<bool>, } impl ServerConfig { @@ -105,6 +117,7 @@ impl TryFrom<TOMLConfig> for Config { }) .transpose()? .unwrap_or_default(), + allow_invalid_server_cert: config.accept_all_invalid_certs, }) } } @@ -125,6 +138,7 @@ impl From<Config> for TOMLConfig { .map(|s| Value::try_from::<ServerConfig>(s).unwrap()) .collect(), ), + accept_all_invalid_certs: config.allow_invalid_server_cert, } } } diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index 2cb3927..30b61ee 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -13,6 +13,7 @@ pub enum Error { InvalidServerPassword, Unimplemented, NotConnectedToChannel, + ServerCertReject, } impl std::error::Error for Error {} @@ -30,6 +31,7 @@ impl fmt::Display for Error { Error::InvalidServerPassword => write!(f, "Invalid server password"), Error::Unimplemented => write!(f, "Unimplemented"), Error::NotConnectedToChannel => write!(f, "Not connected to a channel"), + Error::ServerCertReject => write!(f, "Invalid server certificate"), } } } |
