diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-02-18 13:40:42 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-02-18 15:54:11 +0100 |
commit | a754aea27f208bab0b1badc0d85f2dd161e6eae7 (patch) | |
tree | 4da06556246cc10572c32fe7429c0b239d8776bd /src | |
parent | 1f425191758e862946d89998316e53f4ce64f142 (diff) | |
download | ntw-a754aea27f208bab0b1badc0d85f2dd161e6eae7.tar.gz ntw-a754aea27f208bab0b1badc0d85f2dd161e6eae7.tar.bz2 |
Add simple ReadSlotName command implementation
This patch adds a simple implementation for the command ReadSlotName
that provides access to the names of TOTP and HOTP slots. It returns
the name test for the first TOTP slot and the SlotNotProgrammed error
for all other slots.
Diffstat (limited to 'src')
-rw-r--r-- | src/device.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/device.rs b/src/device.rs index 960f698..9ffc39a 100644 --- a/src/device.rs +++ b/src/device.rs @@ -50,6 +50,7 @@ enum_u8! { #[derive(Clone, Copy, Debug, PartialEq)] pub enum CommandId { GetStatus = 0, + ReadSlotName = 2, } } @@ -69,7 +70,6 @@ impl Nitrokey { command_id: CommandId, data: &[u8], ) -> Result<[u8; 53], CommandStatus> { - let _ = data; match command_id { CommandId::GetStatus => { let mut data = [0u8; 53]; @@ -85,6 +85,20 @@ impl Nitrokey { data[9] = 0; // delete_user_password Ok(data) } + CommandId::ReadSlotName => { + assert!(data.len() > 1); + let slot_number = data[0]; + if slot_number != 0x20 { + Err(CommandStatus::SlotNotProgrammed) + } else { + let mut data = [0u8; 53]; + data[0] = 0x74; // t + data[1] = 0x65; // e + data[2] = 0x73; // s + data[3] = 0x74; // t + Ok(data) + } + } } } } |