Skip to content

Commit

Permalink
Fix: panic if polls are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rares45 committed May 29, 2024
1 parent 298de88 commit cbf08ee
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions polybius-lib/src/password_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ impl PasswordGeneration for PasswordData {
bits.push(PasswordBit::symbol_bit());
}
1 => {
let number = self.numbers_poll.choose(&mut rng).unwrap();
bits.push(PasswordBit::number_bit(number));
if let Some(number) = self.numbers_poll.choose(&mut rng) {
bits.push(PasswordBit::number_bit(number));
}
}
// Increase the probability of choosing a string
_ => {
let text = self.text_poll.choose(&mut rng).unwrap();
bits.push(PasswordBit::string_bit(text));
if let Some(text) = self.text_poll.choose(&mut rng) {
bits.push(PasswordBit::string_bit(text));
}
}
}
}
Expand Down

0 comments on commit cbf08ee

Please sign in to comment.