diff options
Diffstat (limited to 'src/otp.rs')
-rw-r--r-- | src/otp.rs | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -1,6 +1,6 @@ use nitrokey_sys; use std::ffi::CString; -use util::{get_command_result, result_from_string, CommandError}; +use util::{get_command_result, get_cstring, result_from_string, CommandError}; /// Modes for one-time password generation. #[derive(Debug, PartialEq)] @@ -389,22 +389,19 @@ impl OtpSlotData { impl RawOtpSlotData { pub fn new(data: OtpSlotData) -> Result<RawOtpSlotData, CommandError> { - let name = CString::new(data.name); - let secret = CString::new(data.secret); + let name = get_cstring(data.name)?; + let secret = get_cstring(data.secret)?; let use_token_id = data.token_id.is_some(); - let token_id = CString::new(data.token_id.unwrap_or_else(String::new)); - if name.is_err() || secret.is_err() || token_id.is_err() { - return Err(CommandError::InvalidString); - } + let token_id = get_cstring(data.token_id.unwrap_or_else(String::new))?; Ok(RawOtpSlotData { number: data.number, - name: name.unwrap(), - secret: secret.unwrap(), + name, + secret, mode: data.mode, use_enter: data.use_enter, use_token_id, - token_id: token_id.unwrap(), + token_id, }) } } |