summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-12-16 17:13:28 +0000
committerRobin Krahl <robin.krahl@ireas.org>2018-12-16 18:16:37 +0100
commit4e430a735dcc079830e72a45691f39d322bbbe07 (patch)
treeafd413230b7eb495dbae17b970f52760ee2ee1d4 /src
parent9c5364a63e363a6f69afddb29453efc5e4b12cc0 (diff)
downloadnitrokey-rs-4e430a735dcc079830e72a45691f39d322bbbe07.tar.gz
nitrokey-rs-4e430a735dcc079830e72a45691f39d322bbbe07.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/util.rs13
1 files changed, 4 insertions, 9 deletions
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<Vec<u8>> {
- 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);
}