Skip to content

Commit

Permalink
Changes to keep Clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
int08h committed Oct 21, 2018
1 parent 608e43e commit 68788da
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 29 deletions.
29 changes: 15 additions & 14 deletions src/bin/roughenough-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ impl ResponseHandler {
.as_slice()
.read_u32::<LittleEndian>()
.unwrap();
let mut verified = false;

if self.pub_key.is_some() {
let verified = if self.pub_key.is_some() {
self.validate_dele();
self.validate_srep();
self.validate_merkle();
self.validate_midpoint(midpoint);
verified = true;
}
true
} else {
false
};

ParsedResponse {
verified,
Expand Down Expand Up @@ -161,11 +162,7 @@ impl ResponseHandler {

let hash = root_from_paths(index as usize, &self.nonce, paths);

assert_eq!(
Vec::from(hash),
srep[&Tag::ROOT],
"Nonce not in merkle tree!"
);
assert_eq!(hash, srep[&Tag::ROOT], "Nonce not in merkle tree!");
}

fn validate_midpoint(&self, midpoint: u64) {
Expand All @@ -180,11 +177,13 @@ impl ResponseHandler {

assert!(
midpoint >= mint,
"Response midpoint {} lies before delegation span ({}, {})"
"Response midpoint {} lies before delegation span ({}, {})",
midpoint, mint, maxt
);
assert!(
midpoint <= maxt,
"Response midpoint {} lies after delegation span ({}, {})"
"Response midpoint {} lies after delegation span ({}, {})",
midpoint, mint, maxt
);
}

Expand Down Expand Up @@ -279,13 +278,15 @@ fn main() {
let nonce = create_nonce();
let mut socket = UdpSocket::bind("0.0.0.0:0").expect("Couldn't open UDP socket");
let request = make_request(&nonce);
file.as_mut()
.map(|f| f.write_all(&request).expect("Failed to write to file!"));

if let Some(f) = file.as_mut() {
f.write_all(&request).expect("Failed to write to file!")
}

requests.push((nonce, request, socket));
}

for &mut (_, ref request, ref mut socket) in requests.iter_mut() {
for &mut (_, ref request, ref mut socket) in &mut requests {
socket.send_to(request, addr).unwrap();
}

Expand Down
3 changes: 2 additions & 1 deletion src/bin/roughenough-kms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub fn main() {
#[cfg(feature = "gcpkms")]
gcp_kms(kms_key, &plaintext_seed);
} else {
warn!("KMS support is not enabled, nothing to do");
warn!("KMS support was not compiled, nothing to do.");
warn!("For information on KMS support see the Roughenough documentation.");
}
}
10 changes: 5 additions & 5 deletions src/config/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl EnvironmentConfig {
if let Ok(port) = env::var(ROUGHENOUGH_PORT) {
cfg.port = port
.parse()
.expect(format!("invalid port: {}", port).as_ref());
.unwrap_or_else(|_| panic!("invalid port: {}", port));
};

if let Ok(interface) = env::var(ROUGHENOUGH_INTERFACE) {
Expand All @@ -80,21 +80,21 @@ impl EnvironmentConfig {
if let Ok(batch_size) = env::var(ROUGHENOUGH_BATCH_SIZE) {
cfg.batch_size = batch_size
.parse()
.expect(format!("invalid batch_size: {}", batch_size).as_ref());
.unwrap_or_else(|_| panic!("invalid batch_size: {}", batch_size));
};

if let Ok(status_interval) = env::var(ROUGHENOUGH_STATUS_INTERVAL) {
let val: u16 = status_interval
.parse()
.expect(format!("invalid status_interval: {}", status_interval).as_ref());
.unwrap_or_else(|_| panic!("invalid status_interval: {}", status_interval));

cfg.status_interval = Duration::from_secs(val as u64);
cfg.status_interval = Duration::from_secs(u64::from(val));
};

if let Ok(key_protection) = env::var(ROUGHENOUGH_KEY_PROTECTION) {
cfg.key_protection = key_protection
.parse()
.expect(format!("invalid key_protection value: {}", key_protection).as_ref());
.unwrap_or_else(|_| panic!("invalid key_protection value: {}", key_protection));
}

Ok(cfg)
Expand Down
2 changes: 1 addition & 1 deletion src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl FileConfig {
.as_str()
.unwrap()
.parse()
.expect(format!("invalid key_protection value: {:?}", value).as_ref());
.unwrap_or_else(|_| panic!("invalid key_protection value: {:?}", value));
config.key_protection = val
}
unknown => {
Expand Down
2 changes: 1 addition & 1 deletion src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl MerkleTree {

pub fn compute_root(&mut self) -> Hash {
assert!(
self.levels[0].len() > 0,
!self.levels[0].is_empty(),
"Must have at least one leaf to hash!"
);

Expand Down
3 changes: 2 additions & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ impl RtMessage {
return Some(&self.values[i]);
}
}
return None;

None
}

/// Returns the number of tag/value pairs in the message
Expand Down
8 changes: 4 additions & 4 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Server {

/// Returns a reference counted pointer the this server's `keep_running` value.
pub fn get_keep_running(&self) -> Arc<AtomicBool> {
return self.keep_running.clone();
self.keep_running.clone()
}

// extract the client's nonce from its request
Expand Down Expand Up @@ -316,17 +316,17 @@ impl Server {

/// Returns a reference to the server's long-term public key
pub fn get_public_key(&self) -> &str {
return &self.public_key;
&self.public_key
}

/// Returns a reference to the server's on-line (delegated) key
pub fn get_online_key(&self) -> &OnlineKey {
return &self.online_key;
&self.online_key
}

/// Returns a reference to the `ServerConfig` this server was configured with
pub fn get_config(&self) -> &Box<ServerConfig> {
return &self.config;
&self.config
}

#[cfg(fuzzing)]
Expand Down
4 changes: 2 additions & 2 deletions src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub enum Tag {

impl Tag {
/// Translates a tag into its on-the-wire representation
pub fn wire_value(&self) -> &'static [u8] {
match *self {
pub fn wire_value(self) -> &'static [u8] {
match self {
Tag::CERT => b"CERT",
Tag::DELE => b"DELE",
Tag::INDX => b"INDX",
Expand Down

0 comments on commit 68788da

Please sign in to comment.