From 0f5066ca18976c29e63e9f5c55691506c23dc7b6 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 20 May 2018 23:10:50 +0000 Subject: Use NK_login_enum instead of NK_login NK_login used a string to identify the model to connect to. Since libnitrokey v3.3, we can use NK_login_enum together with an enum value as a more type-safe alternative. --- src/lib.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 259ff89..471d481 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -679,17 +679,12 @@ pub fn connect() -> Result { /// } /// ``` pub fn connect_model(model: Model) -> Result { - let model_string = match model { - Model::Storage => "S", - Model::Pro => "P", + let model = match model { + Model::Storage => nitrokey_sys::NK_device_model_NK_STORAGE, + Model::Pro => nitrokey_sys::NK_device_model_NK_PRO, }; - let model_cstring = CString::new(model_string); - if model_cstring.is_err() { - return Err(CommandError::InvalidString); - } - let model = model_cstring.unwrap(); unsafe { - return match nitrokey_sys::NK_login(model.as_ptr()) { + return match nitrokey_sys::NK_login_enum(model) { 1 => Ok(UnauthenticatedDevice {}), rv => Err(CommandError::from(rv)), }; -- cgit v1.2.3