summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-03 00:23:13 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-03 01:24:00 +0100
commit248f8b209b0150e70e82ab15b73bf32b0f47341d (patch)
tree2c18d6e200bd258883cb5bf08962db8690bac66c
parent52afed9c6a17ec9c120a5a91b445afa74be87f0e (diff)
downloadnitrokey-rs-248f8b209b0150e70e82ab15b73bf32b0f47341d.tar.gz
nitrokey-rs-248f8b209b0150e70e82ab15b73bf32b0f47341d.tar.bz2
Remove CommandError::RngError
We switched to rand::thread_rng() which cannot fail. Therefore the CommandError::RngError is no longer needed and removed in this patch.
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/auth.rs5
-rw-r--r--src/util.rs7
3 files changed, 4 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 34f9ac9..7878d74 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
# Unreleased
- Add a `force` argument to `ConfigureOtp::set_time`.
+- Remove the obsolete `CommandError::RngError`.
# v0.2.3 (2018-12-31)
diff --git a/src/auth.rs b/src/auth.rs
index 017cdbb..a129bd8 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -149,10 +149,7 @@ where
A: AuthenticatedDevice<D>,
T: Fn(*const i8, *const i8) -> c_int,
{
- let temp_password = match generate_password(TEMPORARY_PASSWORD_LENGTH) {
- Ok(pw) => pw,
- Err(_) => return Err((device, CommandError::RngError)),
- };
+ let temp_password = generate_password(TEMPORARY_PASSWORD_LENGTH);
let password = match get_cstring(password) {
Ok(password) => password,
Err(err) => return Err((device, err)),
diff --git a/src/util.rs b/src/util.rs
index a2e957e..ccec5e6 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -35,8 +35,6 @@ pub enum CommandError {
InvalidString,
/// You passed an invalid slot.
InvalidSlot,
- /// An error occured during random number generation.
- RngError,
}
/// Log level for libnitrokey.
@@ -99,10 +97,10 @@ pub fn get_last_error() -> CommandError {
};
}
-pub fn generate_password(length: usize) -> std::io::Result<Vec<u8>> {
+pub fn generate_password(length: usize) -> Vec<u8> {
let mut data = vec![0u8; length];
rand::thread_rng().fill(&mut data[..]);
- return Ok(data);
+ return data;
}
pub fn get_cstring<T: Into<Vec<u8>>>(s: T) -> Result<CString, CommandError> {
@@ -127,7 +125,6 @@ impl fmt::Display for CommandError {
CommandError::Unknown => "An unknown error occured",
CommandError::InvalidString => "You passed a string containing a null byte",
CommandError::InvalidSlot => "The given slot is invalid",
- CommandError::RngError => "An error occured during random number generation",
};
write!(f, "{}", msg)
}