diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-11-22 18:59:48 +0100 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-11-29 11:53:55 +0100 |
commit | 192460a201a631a03e8e5a00469343fbe73fb437 (patch) | |
tree | 309950ae109511a5e62391e8b3cf3591f79d6f39 /sq | |
parent | b2ffb4401fad2f5c51f35d56a4408c23c10a3450 (diff) |
Prefer vec! macro.
- The vec![] macro is more performant and often easier to read than
multiple push calls.
- Allow push to a Vec straight after creation in tests. Performance
is not that great of an issue in tests, and the fix would impact
legibility.
- Found by clippy::vec_init_then_push.
Diffstat (limited to 'sq')
-rw-r--r-- | sq/src/commands/key.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sq/src/commands/key.rs b/sq/src/commands/key.rs index fc1c5a85..23cae863 100644 --- a/sq/src/commands/key.rs +++ b/sq/src/commands/key.rs @@ -216,10 +216,11 @@ fn password(config: Config, m: &ArgMatches) -> Result<()> { // First, decrypt all secrets. let passwords = &mut Vec::new(); - let mut decrypted: Vec<Packet> = Vec::new(); - decrypted.push(decrypt_key( + let mut decrypted: Vec<Packet> = vec![decrypt_key( key.primary_key().key().clone().parts_into_secret()?, - passwords)?.into()); + passwords, + )? + .into()]; for ka in key.keys().subkeys().secret() { decrypted.push(decrypt_key( ka.key().clone().parts_into_secret()?, @@ -252,10 +253,10 @@ fn password(config: Config, m: &ArgMatches) -> Result<()> { }; if let Some(new) = new_password { - let mut encrypted: Vec<Packet> = Vec::new(); - encrypted.push( + let mut encrypted: Vec<Packet> = vec![ key.primary_key().key().clone().parts_into_secret()? - .encrypt_secret(&new)?.into()); + .encrypt_secret(&new)?.into() + ]; for ka in key.keys().subkeys().unencrypted_secret() { encrypted.push( ka.key().clone().parts_into_secret()? |