summaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/environment.rs8
-rw-r--r--src/config/file.rs13
-rw-r--r--src/config/mod.rs23
3 files changed, 19 insertions, 25 deletions
diff --git a/src/config/environment.rs b/src/config/environment.rs
index a4cb528..14559d1 100644
--- a/src/config/environment.rs
+++ b/src/config/environment.rs
@@ -111,8 +111,8 @@ impl ServerConfig for EnvironmentConfig {
self.port
}
- fn seed(&self) -> &[u8] {
- &self.seed
+ fn seed(&self) -> Vec<u8> {
+ self.seed.clone()
}
fn batch_size(&self) -> u8 {
@@ -131,7 +131,7 @@ impl ServerConfig for EnvironmentConfig {
}
}
- fn key_protection(&self) -> KeyProtection {
- self.key_protection
+ fn key_protection(&self) -> &KeyProtection {
+ &self.key_protection
}
}
diff --git a/src/config/file.rs b/src/config/file.rs
index a3b8b92..fd84404 100644
--- a/src/config/file.rs
+++ b/src/config/file.rs
@@ -86,6 +86,11 @@ impl FileConfig {
let val = value.as_i64().expect("status_interval value invalid");
config.status_interval = Duration::from_secs(val as u64)
}
+ "key_protection" => {
+ let val = value.as_str().unwrap().parse()
+ .expect(format!("invalid key_protection value: {:?}", value).as_ref());
+ config.key_protection = val
+ }
unknown => {
return Err(Error::InvalidConfiguration(format!(
"unknown config key: {}",
@@ -108,8 +113,8 @@ impl ServerConfig for FileConfig {
self.port
}
- fn seed(&self) -> &[u8] {
- &self.seed
+ fn seed(&self) -> Vec<u8> {
+ self.seed.clone()
}
fn batch_size(&self) -> u8 {
@@ -128,7 +133,7 @@ impl ServerConfig for FileConfig {
}
}
- fn key_protection(&self) -> KeyProtection {
- KeyProtection::Plaintext
+ fn key_protection(&self) -> &KeyProtection {
+ &self.key_protection
}
}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index ac903b3..f0e2a1a 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -28,14 +28,11 @@ use std::net::SocketAddr;
use std::time::Duration;
mod file;
-
pub use self::file::FileConfig;
mod environment;
-
pub use self::environment::EnvironmentConfig;
-use key;
use Error;
use KeyProtection;
@@ -74,7 +71,7 @@ pub trait ServerConfig {
/// [Required] A 32-byte hexadecimal value used to generate the server's
/// long-term key pair. **This is a secret value and must be un-guessable**,
/// treat it with care.
- fn seed(&self) -> &[u8];
+ fn seed(&self) -> Vec<u8>;
/// [Optional] The maximum number of requests to process in one batch. All
/// nonces in a batch are used to build a Merkle tree, the root of which is signed.
@@ -89,7 +86,7 @@ pub trait ServerConfig {
fn socket_addr(&self) -> Result<SocketAddr, Error>;
/// Method used to protect the long-term key pair.
- fn key_protection(&self) -> KeyProtection;
+ fn key_protection(&self) -> &KeyProtection;
}
///
@@ -127,27 +124,19 @@ pub fn is_valid_config(cfg: &Box<ServerConfig>) -> bool {
error!("seed value is missing");
is_valid = false;
}
- if !cfg.seed().is_empty() && cfg.seed().len() != 32 {
- error!("seed value must be 32 characters long");
+ if *cfg.key_protection() == KeyProtection::Plaintext && cfg.seed().len() != 32 {
+ error!("plaintext seed value must be 32 characters long");
is_valid = false;
}
if cfg.batch_size() < 1 || cfg.batch_size() > 64 {
- error!(
- "batch_size {} is invalid; valid range 1-64",
- cfg.batch_size()
- );
+ error!("batch_size {} is invalid; valid range 1-64", cfg.batch_size());
is_valid = false;
}
if is_valid {
match cfg.socket_addr() {
Err(e) => {
- error!(
- "failed to create socket {}:{} {:?}",
- cfg.interface(),
- cfg.port(),
- e
- );
+ error!("failed to create socket {}:{} {:?}", cfg.interface(), cfg.port(), e);
is_valid = false;
}
_ => (),