From 090af48ee1c49c8655610c7b529b2ca256d9e8ae Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 10 Apr 2018 07:51:15 +0200 Subject: Correct validation functions for GetStatus and WriteGeneralConfig structs Signed-off-by: Szczepan Zalega --- libnitrokey/stick10_commands_0.8.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libnitrokey/stick10_commands_0.8.h') diff --git a/libnitrokey/stick10_commands_0.8.h b/libnitrokey/stick10_commands_0.8.h index a04946f..4614f16 100644 --- a/libnitrokey/stick10_commands_0.8.h +++ b/libnitrokey/stick10_commands_0.8.h @@ -322,7 +322,9 @@ namespace nitrokey { }; uint8_t temporary_admin_password[25]; - std::string dissect() const { + bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } + + std::string dissect() const { std::stringstream ss; ss << "numlock:\t" << (int)numlock << std::endl; ss << "capslock:\t" << (int)capslock << std::endl; -- cgit v1.2.1 From 7f3d4ce81a0a38d9591dc4c746bcb75edfe80caa Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 10 Apr 2018 07:55:38 +0200 Subject: Name magic numbers in validation functions Signed-off-by: Szczepan Zalega --- libnitrokey/stick10_commands_0.8.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libnitrokey/stick10_commands_0.8.h') diff --git a/libnitrokey/stick10_commands_0.8.h b/libnitrokey/stick10_commands_0.8.h index 4614f16..9477890 100644 --- a/libnitrokey/stick10_commands_0.8.h +++ b/libnitrokey/stick10_commands_0.8.h @@ -322,7 +322,9 @@ namespace nitrokey { }; uint8_t temporary_admin_password[25]; - bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } + static constexpr uint8_t special_HOTP_slots = 3; + bool isValid() const { return numlock < special_HOTP_slots && capslock < special_HOTP_slots + && scrolllock < special_HOTP_slots && enable_user_password < 2; } std::string dissect() const { std::stringstream ss; -- cgit v1.2.1