From c6ba90ba1ca606b63373caaba16cb4fcc65d00f9 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 9 Jan 2017 18:30:29 +0100 Subject: Remove unused inttypes Signed-off-by: Szczepan Zalega --- include/CommandFailedException.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/CommandFailedException.h') diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h index 9b0c59e..8bcdcae 100644 --- a/include/CommandFailedException.h +++ b/include/CommandFailedException.h @@ -7,7 +7,7 @@ #include #include -#include +#include "log.h" class CommandFailedException : public std::exception { public: -- cgit v1.2.1 From c551b27792774b87a1be7fd0dcfd9e209eaef5ec Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 14 Jan 2017 13:37:29 +0100 Subject: Method to get commands failure cause Signed-off-by: Szczepan Zalega --- include/CommandFailedException.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include/CommandFailedException.h') diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h index 8bcdcae..3753ad4 100644 --- a/include/CommandFailedException.h +++ b/include/CommandFailedException.h @@ -11,8 +11,8 @@ class CommandFailedException : public std::exception { public: - uint8_t last_command_code; - uint8_t last_command_status; + const uint8_t last_command_code; + const uint8_t last_command_status; CommandFailedException(uint8_t last_command_code, uint8_t last_command_status) : last_command_code(last_command_code), @@ -24,6 +24,10 @@ public: return "Command execution has failed on device"; } + bool reason_slot_not_programmed() const throw(){ + return last_command_status == 3; //FIXME use enum status codes + } + }; -- cgit v1.2.1 From 56bd3e2c4353cfc1b902c6dfb55df0ef563c5372 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 17 Jan 2017 15:35:44 +0100 Subject: Check command's fail reason within exception Signed-off-by: Szczepan Zalega --- include/CommandFailedException.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/CommandFailedException.h') diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h index 3753ad4..190eabc 100644 --- a/include/CommandFailedException.h +++ b/include/CommandFailedException.h @@ -8,6 +8,9 @@ #include #include #include "log.h" +#include "command_id.h" + +using cs = nitrokey::proto::stick10::command_status; class CommandFailedException : public std::exception { public: @@ -25,7 +28,11 @@ public: } bool reason_slot_not_programmed() const throw(){ - return last_command_status == 3; //FIXME use enum status codes + return last_command_status == static_cast(cs::slot_not_programmed); + } + + bool reason_wrong_password() const throw(){ + return last_command_status == static_cast(cs::wrong_password); } }; -- cgit v1.2.1 From 03f444905d3a7af3091c2401280e83146f08443a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 31 Jan 2017 18:17:23 +0100 Subject: Add more shortcuts for checking devices error code Signed-off-by: Szczepan Zalega --- include/CommandFailedException.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'include/CommandFailedException.h') diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h index 190eabc..6ff9a2d 100644 --- a/include/CommandFailedException.h +++ b/include/CommandFailedException.h @@ -14,11 +14,11 @@ using cs = nitrokey::proto::stick10::command_status; class CommandFailedException : public std::exception { public: - const uint8_t last_command_code; + const uint8_t last_command_id; const uint8_t last_command_status; - CommandFailedException(uint8_t last_command_code, uint8_t last_command_status) : - last_command_code(last_command_code), + CommandFailedException(uint8_t last_command_id, uint8_t last_command_status) : + last_command_id(last_command_id), last_command_status(last_command_status){ nitrokey::log::Log::instance()(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); } @@ -27,6 +27,19 @@ public: return "Command execution has failed on device"; } + + bool reason_timestamp_warning() const throw(){ + return last_command_status == static_cast(cs::timestamp_warning); + } + + bool reason_AES_not_initialized() const throw(){ + return last_command_status == static_cast(cs::AES_dec_failed); + } + + bool reason_not_authorized() const throw(){ + return last_command_status == static_cast(cs::not_authorized); + } + bool reason_slot_not_programmed() const throw(){ return last_command_status == static_cast(cs::slot_not_programmed); } -- cgit v1.2.1 From 29fc4839b7aaf76c3587cf0d268546fd1d1390c4 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 21 Feb 2017 14:56:07 +0100 Subject: Build debug-log-free library for increased security Signed-off-by: Szczepan Zalega --- include/CommandFailedException.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/CommandFailedException.h') diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h index 6ff9a2d..417e850 100644 --- a/include/CommandFailedException.h +++ b/include/CommandFailedException.h @@ -20,7 +20,7 @@ public: CommandFailedException(uint8_t last_command_id, uint8_t last_command_status) : last_command_id(last_command_id), last_command_status(last_command_status){ - nitrokey::log::Log::instance()(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); + LOG(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); } virtual const char *what() const throw() { -- cgit v1.2.1