From 9bdf6dc243936e7968a357ae7e775f2809e4847c Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 25 Feb 2020 22:32:03 +0100 Subject: [PATCH 1/2] Switch from the deprecated rand-os crate to getrandom. --- sasl/Cargo.toml | 4 ++-- sasl/src/common/scram.rs | 5 ++--- sasl/src/error.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sasl/Cargo.toml b/sasl/Cargo.toml index 957bcf15..7bf01332 100644 --- a/sasl/Cargo.toml +++ b/sasl/Cargo.toml @@ -16,11 +16,11 @@ gitlab = { repository = "lumi/sasl-rs" } [features] default = ["scram"] -scram = ["base64", "rand_os", "sha-1", "sha2", "hmac", "pbkdf2"] +scram = ["base64", "getrandom", "sha-1", "sha2", "hmac", "pbkdf2"] [dependencies] base64 = { version = "0.10", optional = true } -rand_os = { version = "0.1", optional = true } +getrandom = { version = "0.1", optional = true } sha-1 = { version = "0.8", optional = true } sha2 = { version = "0.8", optional = true } hmac = { version = "0.7", optional = true } diff --git a/sasl/src/common/scram.rs b/sasl/src/common/scram.rs index 975c95be..499eebd8 100644 --- a/sasl/src/common/scram.rs +++ b/sasl/src/common/scram.rs @@ -1,4 +1,4 @@ -use rand_os::{OsRng, rand_core::{RngCore, Error as RngError}}; +use getrandom::{getrandom, Error as RngError}; use sha1::{Sha1 as Sha1_hash, Digest}; use sha2::Sha256 as Sha256_hash; use hmac::{Hmac, Mac}; @@ -13,8 +13,7 @@ use base64; /// Generate a nonce for SCRAM authentication. pub fn generate_nonce() -> Result { let mut data = [0u8; 32]; - let mut rng = OsRng::new()?; - rng.fill_bytes(&mut data); + getrandom(&mut data)?; Ok(base64::encode(&data)) } diff --git a/sasl/src/error.rs b/sasl/src/error.rs index b5287073..eb885909 100644 --- a/sasl/src/error.rs +++ b/sasl/src/error.rs @@ -1,5 +1,5 @@ #[cfg(feature = "scram")] -use rand_os::rand_core::Error as RngError; +use getrandom::Error as RngError; /// A wrapper enum for things that could go wrong in this crate. #[derive(Debug)] From dc98ce0a3a5bc1c71ca6024533fdcd8314f18ae2 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 25 Feb 2020 22:32:24 +0100 Subject: [PATCH 2/2] Update base64 to 0.12. --- sasl/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sasl/Cargo.toml b/sasl/Cargo.toml index 7bf01332..c94be0c9 100644 --- a/sasl/Cargo.toml +++ b/sasl/Cargo.toml @@ -19,7 +19,7 @@ default = ["scram"] scram = ["base64", "getrandom", "sha-1", "sha2", "hmac", "pbkdf2"] [dependencies] -base64 = { version = "0.10", optional = true } +base64 = { version = "0.12", optional = true } getrandom = { version = "0.1", optional = true } sha-1 = { version = "0.8", optional = true } sha2 = { version = "0.8", optional = true }