diff options
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/util.rs b/src/util.rs index 1608952..75de799 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,7 +2,7 @@ use libc::{c_void, free}; use nitrokey_sys; use rand::{OsRng, Rng}; use std; -use std::ffi::CStr; +use std::ffi::{CStr, CString}; use std::os::raw::{c_char, c_int}; /// Error types returned by Nitrokey device or by the library. @@ -110,6 +110,10 @@ pub fn generate_password(length: usize) -> std::io::Result<Vec<u8>> { return Ok(data); } +pub fn get_cstring<T: Into<Vec<u8>>>(s: T) -> Result<CString, CommandError> { + CString::new(s).or(Err(CommandError::InvalidString)) +} + impl From<c_int> for CommandError { fn from(value: c_int) -> Self { match value { |