diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-01-29 14:04:06 +0100 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2020-02-03 10:19:21 +0100 |
commit | 4a9dab94400cb00ae1e28485ddc64d46cf27ed3c (patch) | |
tree | 2ef021b47d3c1f43918e18aa03f1e1ee6aa6dc3b /src | |
parent | 395ace0131ef6cd655a222734f2cc8d037395a3b (diff) | |
download | nitrokey-rs-4a9dab94400cb00ae1e28485ddc64d46cf27ed3c.tar.gz nitrokey-rs-4a9dab94400cb00ae1e28485ddc64d46cf27ed3c.tar.bz2 |
Implement From<&NK_status> for RawConfig
This makes it easier to parse only the config part of the NK_status
struct and avoids code duplication in the upcoming get_config
refactoring.
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 11 | ||||
-rw-r--r-- | src/device/mod.rs | 8 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs index cb678d7..9b9de3c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -83,6 +83,17 @@ impl convert::TryFrom<Config> for RawConfig { } } +impl From<&nitrokey_sys::NK_status> for RawConfig { + fn from(status: &nitrokey_sys::NK_status) -> Self { + Self { + numlock: status.config_numlock, + capslock: status.config_capslock, + scrollock: status.config_scrolllock, + user_password: status.otp_user_password, + } + } +} + impl From<[u8; 5]> for RawConfig { fn from(data: [u8; 5]) -> Self { RawConfig { diff --git a/src/device/mod.rs b/src/device/mod.rs index a25ad1b..403bb1f 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -191,13 +191,7 @@ impl From<nitrokey_sys::NK_status> for Status { minor: status.firmware_version_minor, }, serial_number: status.serial_number_smart_card, - config: RawConfig { - numlock: status.config_numlock, - capslock: status.config_capslock, - scrollock: status.config_scrolllock, - user_password: status.otp_user_password, - } - .into(), + config: RawConfig::from(&status).into(), } } } |