aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src
diff options
context:
space:
mode:
Diffstat (limited to 'mumlib/src')
-rw-r--r--mumlib/src/config.rs14
-rw-r--r--mumlib/src/error.rs2
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"),
}
}
}