Fix rand breaking changes
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2025-02-03 20:57:49 +01:00
parent 022073f26a
commit f2e4d82f87
3 changed files with 77 additions and 31 deletions

View File

@ -21,7 +21,7 @@ pub struct TotpKey {
impl TotpKey {
/// Generate a new TOTP key
pub fn new_random() -> Self {
let random_bytes = rand::thread_rng().gen::<[u8; 20]>();
let random_bytes = rand::rng().random::<[u8; 20]>();
Self {
encoded: base32::encode(BASE32_ALPHABET, &random_bytes),
}

View File

@ -1,14 +1,9 @@
use lazy_regex::regex_find;
use rand::distributions::Alphanumeric;
use rand::Rng;
use rand::distr::{Alphanumeric, SampleString};
/// Generate a random string of a given size
pub fn rand_str(len: usize) -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.map(char::from)
.take(len)
.collect()
Alphanumeric.sample_string(&mut rand::rng(), len)
}
/// Parse environment variables