summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Stock <stuart@int08h.com>2019-08-11 18:09:26 -0500
committerStuart Stock <stuart@int08h.com>2019-08-11 18:09:26 -0500
commit266f1adc99f780edab22096ed13f624bfdcb6674 (patch)
tree8185063cc9653105067c1e9caaf2495c289054bc
parenta0165c01946efbedd2f274bad02a33ab52c01e32 (diff)
downloadroughenough-266f1adc99f780edab22096ed13f624bfdcb6674.zip
Address clippy lints
* More consistent use of `dyn` * Add default implementations * Misc clippy changes
-rw-r--r--src/bin/roughenough-server.rs2
-rw-r--r--src/config/file.rs6
-rw-r--r--src/config/mod.rs22
-rw-r--r--src/key/online.rs6
-rw-r--r--src/kms/envelope.rs4
-rw-r--r--src/kms/mod.rs6
-rw-r--r--src/merkle.rs6
-rw-r--r--src/server.rs6
-rw-r--r--src/sign.rs6
-rw-r--r--src/stats/aggregated.rs6
-rw-r--r--src/stats/per_client.rs6
11 files changed, 52 insertions, 24 deletions
diff --git a/src/bin/roughenough-server.rs b/src/bin/roughenough-server.rs
index b0b5819..c9301d1 100644
--- a/src/bin/roughenough-server.rs
+++ b/src/bin/roughenough-server.rs
@@ -101,7 +101,7 @@ pub fn main() {
error!("{:?}", e);
process::exit(1)
}
- Ok(ref cfg) if !config::is_valid_config(&cfg) => process::exit(1),
+ Ok(ref cfg) if !config::is_valid_config(cfg.as_ref()) => process::exit(1),
Ok(cfg) => cfg,
};
diff --git a/src/config/file.rs b/src/config/file.rs
index 0e69571..f523fed 100644
--- a/src/config/file.rs
+++ b/src/config/file.rs
@@ -49,15 +49,15 @@ pub struct FileConfig {
impl FileConfig {
pub fn new(config_file: &str) -> Result<Self, Error> {
let mut infile = File::open(config_file)
- .expect(&format!("failed to open config file '{}'", config_file));
+ .unwrap_or_else(|_| panic!("failed to open config file '{}'", config_file));
let mut contents = String::new();
infile
.read_to_string(&mut contents)
- .expect(&format!("could not read config file '{}'", config_file));
+ .unwrap_or_else(|_| panic!("could not read config file '{}'", config_file));
let cfg = YamlLoader::load_from_str(&contents)
- .expect(&format!("could not parse config file '{}'", config_file));
+ .unwrap_or_else(|_| panic!("could not parse config file '{}'", config_file));
if cfg.len() != 1 {
return Err(Error::InvalidConfiguration(
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 1d1d149..6ce542a 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -141,7 +141,8 @@ pub fn make_config(arg: &str) -> Result<Box<dyn ServerConfig>, Error> {
///
/// Validate configuration settings. Returns `true` if the config is valid, `false` otherwise.
///
-pub fn is_valid_config(cfg: &Box<dyn ServerConfig>) -> bool {
+#[allow(clippy::useless_let_if_seq)]
+pub fn is_valid_config(cfg: &dyn ServerConfig) -> bool {
let mut is_valid = true;
if cfg.port() == 0 {
@@ -179,17 +180,14 @@ pub fn is_valid_config(cfg: &Box<dyn ServerConfig>) -> bool {
}
if is_valid {
- match cfg.udp_socket_addr() {
- Err(e) => {
- error!(
- "failed to create UDP socket {}:{} {:?}",
- cfg.interface(),
- cfg.port(),
- e
- );
- is_valid = false;
- }
- _ => (),
+ if let Err(e) = cfg.udp_socket_addr() {
+ error!(
+ "failed to create UDP socket {}:{} {:?}",
+ cfg.interface(),
+ cfg.port(),
+ e
+ );
+ is_valid = false;
}
}
diff --git a/src/key/online.rs b/src/key/online.rs
index 0c0c80f..a78ac91 100644
--- a/src/key/online.rs
+++ b/src/key/online.rs
@@ -31,6 +31,12 @@ pub struct OnlineKey {
signer: Signer,
}
+impl Default for OnlineKey {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl OnlineKey {
pub fn new() -> Self {
OnlineKey {
diff --git a/src/kms/envelope.rs b/src/kms/envelope.rs
index d83aa64..5533450 100644
--- a/src/kms/envelope.rs
+++ b/src/kms/envelope.rs
@@ -62,7 +62,7 @@ pub struct EnvelopeEncryption;
impl EnvelopeEncryption {
/// Decrypt a seed previously encrypted with `encrypt_seed()`
- pub fn decrypt_seed(kms: &KmsProvider, ciphertext_blob: &[u8]) -> Result<Vec<u8>, KmsError> {
+ pub fn decrypt_seed(kms: &dyn KmsProvider, ciphertext_blob: &[u8]) -> Result<Vec<u8>, KmsError> {
if ciphertext_blob.len() < MIN_PAYLOAD_SIZE {
return Err(KmsError::InvalidData(format!(
"ciphertext too short: min {}, found {}",
@@ -121,7 +121,7 @@ impl EnvelopeEncryption {
///
/// The returned encrypted byte blob is safe to store on unsecured media.
///
- pub fn encrypt_seed(kms: &KmsProvider, plaintext_seed: &[u8]) -> Result<Vec<u8>, KmsError> {
+ pub fn encrypt_seed(kms: &dyn KmsProvider, plaintext_seed: &[u8]) -> Result<Vec<u8>, KmsError> {
// Generate random DEK and nonce
let rng = SystemRandom::new();
let mut dek = [0u8; DEK_SIZE_BYTES];
diff --git a/src/kms/mod.rs b/src/kms/mod.rs
index 96d732c..37793e8 100644
--- a/src/kms/mod.rs
+++ b/src/kms/mod.rs
@@ -144,7 +144,7 @@ pub use crate::kms::awskms::inner::AwsKms;
/// the plaintext seed value.
///
#[cfg(feature = "awskms")]
-pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
+pub fn load_seed(config: &dyn ServerConfig) -> Result<Vec<u8>, error::Error> {
match config.kms_protection() {
KmsProtection::Plaintext => Ok(config.seed()),
KmsProtection::AwsKmsEnvelope(key_id) => {
@@ -178,7 +178,7 @@ pub use crate::kms::gcpkms::inner::GcpKms;
/// the plaintext seed value.
///
#[cfg(feature = "gcpkms")]
-pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
+pub fn load_seed(config: &dyn ServerConfig) -> Result<Vec<u8>, error::Error> {
match config.kms_protection() {
KmsProtection::Plaintext => Ok(config.seed()),
KmsProtection::GoogleKmsEnvelope(resource_id) => {
@@ -205,7 +205,7 @@ pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
/// * `config.seed()` is used as-is and assumed to be a 32-byte hexadecimal value
///
#[cfg(not(any(feature = "awskms", feature = "gcpkms")))]
-pub fn load_seed(config: &Box<ServerConfig>) -> Result<Vec<u8>, error::Error> {
+pub fn load_seed(config: &dyn ServerConfig) -> Result<Vec<u8>, error::Error> {
match config.kms_protection() {
KmsProtection::Plaintext => Ok(config.seed()),
v => Err(error::Error::InvalidConfiguration(format!(
diff --git a/src/merkle.rs b/src/merkle.rs
index 7284839..e7b1999 100644
--- a/src/merkle.rs
+++ b/src/merkle.rs
@@ -29,6 +29,12 @@ pub struct MerkleTree {
levels: Vec<Vec<Data>>,
}
+impl Default for MerkleTree {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl MerkleTree {
///
/// Create a new empty Merkle Tree
diff --git a/src/server.rs b/src/server.rs
index f23b6b5..8ae0641 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -105,7 +105,7 @@ impl Server {
let public_key: String;
let cert_bytes = {
- let seed = match kms::load_seed(&config) {
+ let seed = match kms::load_seed(config.as_ref()) {
Ok(seed) => seed,
Err(e) => {
error!("Failed to load seed: {:#?}", e);
@@ -197,8 +197,8 @@ impl Server {
}
/// Returns a reference to the `ServerConfig` this server was configured with
- pub fn get_config(&self) -> &Box<dyn ServerConfig> {
- &self.config
+ pub fn get_config(&self) -> &dyn ServerConfig {
+ self.config.as_ref()
}
/// Returns a reference counted pointer the this server's `keep_running` value.
diff --git a/src/sign.rs b/src/sign.rs
index 43d3b51..a8d7a5a 100644
--- a/src/sign.rs
+++ b/src/sign.rs
@@ -65,6 +65,12 @@ pub struct Signer {
buf: Vec<u8>,
}
+impl Default for Signer {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Signer {
pub fn new() -> Self {
let rng = rand::SystemRandom::new();
diff --git a/src/stats/aggregated.rs b/src/stats/aggregated.rs
index 389a99d..d79c6e3 100644
--- a/src/stats/aggregated.rs
+++ b/src/stats/aggregated.rs
@@ -34,6 +34,12 @@ pub struct AggregatedStats {
empty_map: HashMap<IpAddr, ClientStatEntry>,
}
+impl Default for AggregatedStats {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl AggregatedStats {
#[allow(dead_code)]
diff --git a/src/stats/per_client.rs b/src/stats/per_client.rs
index 8641fde..4905823 100644
--- a/src/stats/per_client.rs
+++ b/src/stats/per_client.rs
@@ -33,6 +33,12 @@ pub struct PerClientStats {
max_clients: usize,
}
+impl Default for PerClientStats {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl PerClientStats {
/// Maximum number of entries to prevent unbounded memory growth.