From 7445ee40f8930c2f72e87d5809d2ff584b0c4d30 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 13 Nov 2022 10:03:04 +0100 Subject: [PATCH] Remove get_random_64() Its uses are replaced by get_randm_bytes() or encode_random_bytes(). --- src/config.rs | 3 +-- src/crypto.rs | 4 ---- src/db/models/send.rs | 2 +- src/db/models/user.rs | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 9c31d231..4f2779d9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -981,8 +981,7 @@ impl Config { if let Some(akey) = self._duo_akey() { akey } else { - let akey = crate::crypto::get_random_64(); - let akey_s = data_encoding::BASE64.encode(&akey); + let akey_s = crate::crypto::encode_random_bytes::<64>(data_encoding::BASE64); // Save the new value let builder = ConfigBuilder { diff --git a/src/crypto.rs b/src/crypto.rs index daf5124d..99f0fb91 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -37,10 +37,6 @@ pub fn hmac_sign(key: &str, data: &str) -> String { // Random values // -pub fn get_random_64() -> Vec { - get_random_bytes::<64>().to_vec() -} - /// Return an array holding `N` random bytes. pub fn get_random_bytes() -> [u8; N] { use ring::rand::{SecureRandom, SystemRandom}; diff --git a/src/db/models/send.rs b/src/db/models/send.rs index effc5dfc..49756125 100644 --- a/src/db/models/send.rs +++ b/src/db/models/send.rs @@ -81,7 +81,7 @@ impl Send { if let Some(password) = password { self.password_iter = Some(PASSWORD_ITER); - let salt = crate::crypto::get_random_64(); + let salt = crate::crypto::get_random_bytes::<64>().to_vec(); let hash = crate::crypto::hash_password(password.as_bytes(), &salt, PASSWORD_ITER as u32); self.password_salt = Some(salt); self.password_hash = Some(hash); diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 826e00fa..68fb96f6 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -93,7 +93,7 @@ impl User { email_new_token: None, password_hash: Vec::new(), - salt: crypto::get_random_64(), + salt: crypto::get_random_bytes::<64>().to_vec(), password_iterations: CONFIG.password_iterations(), security_stamp: crate::util::get_uuid(),