Skip to content

Commit

Permalink
review-updates
Browse files Browse the repository at this point in the history
Signed-off-by: Firas Ghanmi <[email protected]>
  • Loading branch information
fghanmi committed Aug 17, 2024
1 parent b90cf4a commit 55b6b77
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tough/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2018"
[dependencies]
async-recursion = "1"
async-trait = "0.1"
base64 = "0.21"
bytes = "1"
chrono = { version = "0.4", default-features = false, features = ["std", "alloc", "serde", "clock"] }
dyn-clone = "1"
Expand All @@ -22,6 +23,7 @@ log = "0.4"
olpc-cjson = { version = "0.1", path = "../olpc-cjson" }
pem = "3"
percent-encoding = "2"
pkcs8 = { version = "0.7", features = ["encryption", "pem", "std"] }
reqwest = { version = "0.11", optional = true, default-features = false, features = ["stream"] }
ring = { version = "0.17", features = ["std"] }
serde = { version = "1", features = ["derive"] }
Expand All @@ -35,8 +37,6 @@ typed-path = "0.9"
untrusted = "0.9"
url = "2"
walkdir = "2"
pkcs8 = { version = "0.7", features = ["encryption", "pem", "std"] }
base64 = "0.21"

[dev-dependencies]
failure-server = { path = "../integ/failure-server" }
Expand Down
4 changes: 2 additions & 2 deletions tuftool/src/add_key_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl AddKeyArgs {
};

if new_passwords.len() > self.new_keys.len() {
panic!("More new passwords provided than new key sources");
error::MoreNewPasswordsSnafu.fail()?;
}
for (i, source) in self.new_keys.iter().enumerate() {
let password = new_passwords.get(i).unwrap_or(&default_password);
Expand All @@ -106,7 +106,7 @@ impl AddKeyArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}

for (i, source) in self.keys.iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions tuftool/src/add_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl AddRoleArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down Expand Up @@ -174,7 +174,7 @@ impl AddRoleArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down
2 changes: 1 addition & 1 deletion tuftool/src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl CreateArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down
2 changes: 1 addition & 1 deletion tuftool/src/create_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl CreateRoleArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}

for (i, source) in self.keys.iter().enumerate() {
Expand Down
6 changes: 6 additions & 0 deletions tuftool/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ pub(crate) enum Error {
source: tokio::task::JoinError,
backtrace: Backtrace,
},

#[snafu(display("More passwords provided than key sources"))]
MorePasswords { backtrace: Backtrace },

#[snafu(display("More new passwords provided than new key sources"))]
MoreNewPasswords { backtrace: Backtrace },
}

// Extracts the status code from a reqwest::Error and converts it to a string to be displayed
Expand Down
2 changes: 1 addition & 1 deletion tuftool/src/remove_key_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl RemoveKeyArgs {
};

if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down
2 changes: 1 addition & 1 deletion tuftool/src/remove_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl RemoveRoleArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down
6 changes: 3 additions & 3 deletions tuftool/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Command {
None => vec![],
};
if passwords.len() > key_sources.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in key_sources.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down Expand Up @@ -263,7 +263,7 @@ impl Command {
async fn add_key(
path: &Path,
roles: &[RoleType],
key_source: &Vec<String>,
key_source: &[String],
password: &Option<Vec<String>>,
) -> Result<()> {
let mut keys = Vec::new();
Expand All @@ -273,7 +273,7 @@ impl Command {
None => &vec![],
};
if passwords.len() > key_source.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in key_source.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down
2 changes: 1 addition & 1 deletion tuftool/src/transfer_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl TransferMetadataArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down
2 changes: 1 addition & 1 deletion tuftool/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl UpdateArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down
2 changes: 1 addition & 1 deletion tuftool/src/update_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl UpdateTargetsArgs {
None => &vec![],
};
if passwords.len() > self.keys.len() {
panic!("More passwords provided than key sources");
error::MorePasswordsSnafu.fail()?;
}
for (i, source) in self.keys.iter().enumerate() {
let password = passwords.get(i).unwrap_or(&default_password);
Expand Down

0 comments on commit 55b6b77

Please sign in to comment.