diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-05-20 23:10:50 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2018-05-21 01:12:28 +0200 |
commit | 0f5066ca18976c29e63e9f5c55691506c23dc7b6 (patch) | |
tree | 9b78775a2569016e203eb5d4d2f46157949bf89b | |
parent | 68f1f31595757c5018c5c243a76e94e0af5439ef (diff) | |
download | nitrokey-rs-0f5066ca18976c29e63e9f5c55691506c23dc7b6.tar.gz nitrokey-rs-0f5066ca18976c29e63e9f5c55691506c23dc7b6.tar.bz2 |
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.
-rw-r--r-- | TODO.md | 1 | ||||
-rw-r--r-- | src/lib.rs | 13 |
2 files changed, 4 insertions, 10 deletions
@@ -1,6 +1,5 @@ - Add support and tests for the Nitrokey Storage. - Add support for the currently unsupported commands: - - `NK_login_enum` - `NK_set_unencrypted_volume_rorw_pin_type_user` - `NK_lock_device` - `NK_factory_reset` @@ -679,17 +679,12 @@ pub fn connect() -> Result<UnauthenticatedDevice, CommandError> { /// } /// ``` pub fn connect_model(model: Model) -> Result<UnauthenticatedDevice, CommandError> { - 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)), }; |