From 55b6b779517ac3b55ff0edad888b1e71ac30a2d4 Mon Sep 17 00:00:00 2001 From: Firas Ghanmi Date: Sat, 17 Aug 2024 22:27:11 +0200 Subject: [PATCH] review-updates Signed-off-by: Firas Ghanmi --- tough/Cargo.toml | 4 ++-- tuftool/src/add_key_role.rs | 4 ++-- tuftool/src/add_role.rs | 4 ++-- tuftool/src/create.rs | 2 +- tuftool/src/create_role.rs | 2 +- tuftool/src/error.rs | 6 ++++++ tuftool/src/remove_key_role.rs | 2 +- tuftool/src/remove_role.rs | 2 +- tuftool/src/root.rs | 6 +++--- tuftool/src/transfer_metadata.rs | 2 +- tuftool/src/update.rs | 2 +- tuftool/src/update_targets.rs | 2 +- 12 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tough/Cargo.toml b/tough/Cargo.toml index 0d82c3c6a..77a207cca 100644 --- a/tough/Cargo.toml +++ b/tough/Cargo.toml @@ -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" @@ -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"] } @@ -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" } diff --git a/tuftool/src/add_key_role.rs b/tuftool/src/add_key_role.rs index eeb426cfe..2bf81fefc 100644 --- a/tuftool/src/add_key_role.rs +++ b/tuftool/src/add_key_role.rs @@ -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); @@ -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() { diff --git a/tuftool/src/add_role.rs b/tuftool/src/add_role.rs index 9af33227b..cbad47142 100644 --- a/tuftool/src/add_role.rs +++ b/tuftool/src/add_role.rs @@ -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); @@ -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); diff --git a/tuftool/src/create.rs b/tuftool/src/create.rs index 8d0655ad7..a72a439dc 100644 --- a/tuftool/src/create.rs +++ b/tuftool/src/create.rs @@ -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); diff --git a/tuftool/src/create_role.rs b/tuftool/src/create_role.rs index b7cae2cd8..956beba47 100644 --- a/tuftool/src/create_role.rs +++ b/tuftool/src/create_role.rs @@ -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() { diff --git a/tuftool/src/error.rs b/tuftool/src/error.rs index b2f89af01..11e399f29 100644 --- a/tuftool/src/error.rs +++ b/tuftool/src/error.rs @@ -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 diff --git a/tuftool/src/remove_key_role.rs b/tuftool/src/remove_key_role.rs index 5188be660..2f8bf1206 100644 --- a/tuftool/src/remove_key_role.rs +++ b/tuftool/src/remove_key_role.rs @@ -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); diff --git a/tuftool/src/remove_role.rs b/tuftool/src/remove_role.rs index 78d4299ac..42cd9db04 100644 --- a/tuftool/src/remove_role.rs +++ b/tuftool/src/remove_role.rs @@ -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); diff --git a/tuftool/src/root.rs b/tuftool/src/root.rs index 7d8a0cb57..2fceb613b 100644 --- a/tuftool/src/root.rs +++ b/tuftool/src/root.rs @@ -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); @@ -263,7 +263,7 @@ impl Command { async fn add_key( path: &Path, roles: &[RoleType], - key_source: &Vec, + key_source: &[String], password: &Option>, ) -> Result<()> { let mut keys = Vec::new(); @@ -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); diff --git a/tuftool/src/transfer_metadata.rs b/tuftool/src/transfer_metadata.rs index e5a42732e..818b41c23 100644 --- a/tuftool/src/transfer_metadata.rs +++ b/tuftool/src/transfer_metadata.rs @@ -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); diff --git a/tuftool/src/update.rs b/tuftool/src/update.rs index 4a4ba5d37..0b16d0f7e 100644 --- a/tuftool/src/update.rs +++ b/tuftool/src/update.rs @@ -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); diff --git a/tuftool/src/update_targets.rs b/tuftool/src/update_targets.rs index de8da9dbc..08c049c6d 100644 --- a/tuftool/src/update_targets.rs +++ b/tuftool/src/update_targets.rs @@ -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);