From 4e430a735dcc079830e72a45691f39d322bbbe07 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 16 Dec 2018 17:13:28 +0000 Subject: Update to rand v0.6 This patch updates the rand dependecy to version 0.6. It also replaces the OsRng, which is guaranteed to use OS/hardware entropy, with the thread_rng, which is likely to use OS/hardware entropy as a seed. The choice of RNG and the handling of password should be reviewed at a later point. --- Cargo.toml | 2 +- src/util.rs | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f3560a2..663e596 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,4 +19,4 @@ test-storage = [] [dependencies] libc = "0.2" nitrokey-sys = "3.4.1" -rand = "0.4" +rand = "0.6" diff --git a/src/util.rs b/src/util.rs index 2a75634..d98e675 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,11 +1,10 @@ -use libc::{c_void, free}; -use nitrokey_sys; -use rand::{OsRng, Rng}; -use std; use std::ffi::{CStr, CString}; use std::fmt; use std::os::raw::{c_char, c_int}; +use libc::{c_void, free}; +use rand::Rng; + /// Error types returned by Nitrokey device or by the library. #[derive(Debug, PartialEq)] pub enum CommandError { @@ -101,12 +100,8 @@ pub fn get_last_error() -> CommandError { } pub fn generate_password(length: usize) -> std::io::Result> { - let mut rng = match OsRng::new() { - Ok(rng) => rng, - Err(err) => return Err(err), - }; let mut data = vec![0u8; length]; - rng.fill_bytes(&mut data[..]); + rand::thread_rng().fill(&mut data[..]); return Ok(data); } -- cgit v1.2.3