From a754aea27f208bab0b1badc0d85f2dd161e6eae7 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 18 Feb 2019 13:40:42 +0000 Subject: 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. --- src/device.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') 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) + } + } } } } -- cgit v1.2.3