diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-18 01:38:49 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-18 01:58:08 -0400 |
commit | 6c039cd319f15a8b5fbf771729589764be83a29d (patch) | |
tree | a37f025c5053ec28c2131277a8728eea48b0a90b | |
parent | 840f53b84206f9efe0a5cdea3414c472908a22e4 (diff) | |
download | rbw-6c039cd319f15a8b5fbf771729589764be83a29d.tar.gz rbw-6c039cd319f15a8b5fbf771729589764be83a29d.zip |
don't use locked vecs for pwgen
i'm doing all of my password generation in the client, which really
doesn't need it
-rw-r--r-- | src/bin/rbw/commands.rs | 5 | ||||
-rw-r--r-- | src/pwgen.rs | 15 |
2 files changed, 8 insertions, 12 deletions
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 360c967..3e11c88 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -198,9 +198,8 @@ pub fn generate( len: usize, ty: rbw::pwgen::Type, ) -> anyhow::Result<()> { - let pw = rbw::pwgen::pwgen(ty, len); - // unwrap is safe because pwgen is guaranteed to always return valid utf8 - println!("{}", std::str::from_utf8(pw.data()).unwrap()); + let password = rbw::pwgen::pwgen(ty, len); + println!("{}", password); if name.is_some() && user.is_some() { unlock()?; diff --git a/src/pwgen.rs b/src/pwgen.rs index 656305e..fa110d6 100644 --- a/src/pwgen.rs +++ b/src/pwgen.rs @@ -1,6 +1,5 @@ use chbs::scheme::ToScheme as _; use rand::seq::SliceRandom as _; -use zeroize::Zeroize as _; const SYMBOLS: &[u8] = b"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; const NUMBERS: &[u8] = b"0123456789"; @@ -17,17 +16,13 @@ pub enum Type { Diceware, } -pub fn pwgen(ty: Type, len: usize) -> crate::locked::Vec { +pub fn pwgen(ty: Type, len: usize) -> String { if ty == Type::Diceware { - let mut locked_pass = crate::locked::Vec::new(); let mut config = chbs::config::BasicConfig::default(); config.words = len; config.capitalize_first = chbs::probability::Probability::Never; config.capitalize_words = chbs::probability::Probability::Never; - let mut pass = config.to_scheme().generate(); - locked_pass.extend(pass.as_bytes().iter().copied()); - pass.zeroize(); - return locked_pass; + return config.to_scheme().generate(); } let alphabet = match ty { @@ -58,7 +53,9 @@ pub fn pwgen(ty: Type, len: usize) -> crate::locked::Vec { }; let mut rng = rand::thread_rng(); - let mut pass = crate::locked::Vec::new(); + let mut pass = vec![]; pass.extend(alphabet.choose_multiple(&mut rng, len).copied()); - pass + // unwrap is safe because the method of generating passwords guarantees + // valid utf8 + String::from_utf8(pass).unwrap() } |