aboutsummaryrefslogtreecommitdiff
path: root/src/auth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/auth.rs b/src/auth.rs
index 62b851f..8460fae 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -2,10 +2,9 @@ use config::{Config, RawConfig};
use device::{Device, DeviceWrapper, Pro, Storage};
use nitrokey_sys;
use otp::{ConfigureOtp, GenerateOtp, OtpMode, OtpSlotData, RawOtpSlotData};
-use std::ffi::CString;
use std::ops::Deref;
use std::os::raw::c_int;
-use util::{generate_password, get_command_result, result_from_string, CommandError};
+use util::{generate_password, get_command_result, get_cstring, result_from_string, CommandError};
static TEMPORARY_PASSWORD_LENGTH: usize = 25;
@@ -150,13 +149,11 @@ where
Ok(pw) => pw,
Err(_) => return Err((device, CommandError::RngError)),
};
- let password = CString::new(password);
- if password.is_err() {
- return Err((device, CommandError::InvalidString));
- }
-
- let pw = password.unwrap();
- let password_ptr = pw.as_ptr();
+ let password = match get_cstring(password) {
+ Ok(password) => password,
+ Err(err) => return Err((device, err)),
+ };
+ let password_ptr = password.as_ptr();
let temp_password_ptr = temp_password.as_ptr() as *const i8;
return match callback(password_ptr, temp_password_ptr) {
0 => Ok(A::new(device, temp_password)),