From 709b3e4c3a7aac2565687579bff62601b141362f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 9 Aug 2016 17:42:12 +0200 Subject: Merged library exceptions declaration Signed-off-by: Szczepan Zalega --- CMakeLists.txt | 2 +- CommandFailedException.cpp | 5 ----- NK_C_API.cc | 2 +- NitrokeyManager.cc | 3 +-- TooLongStringException.cpp | 5 ----- include/InvalidSlotException.h | 31 --------------------------- include/LibraryException.h | 45 ++++++++++++++++++++++++++++++++++++---- include/TooLongStringException.h | 34 ------------------------------ 8 files changed, 44 insertions(+), 83 deletions(-) delete mode 100644 CommandFailedException.cpp delete mode 100644 TooLongStringException.cpp delete mode 100644 include/InvalidSlotException.h delete mode 100644 include/TooLongStringException.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 265e737..39c0c34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,6 @@ set(SOURCE_FILES log.cc misc.cc NitrokeyManager.cc - NK_C_API.cc CommandFailedException.cpp include/CommandFailedException.h TooLongStringException.cpp include/TooLongStringException.h include/InvalidSlotException.h include/LibraryException.h) + NK_C_API.cc include/CommandFailedException.h include/LibraryException.h) add_executable(libnitrokey ${SOURCE_FILES}) \ No newline at end of file diff --git a/CommandFailedException.cpp b/CommandFailedException.cpp deleted file mode 100644 index ccc780c..0000000 --- a/CommandFailedException.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by sz on 23.07.16. -// - -#include "include/CommandFailedException.h" diff --git a/NK_C_API.cc b/NK_C_API.cc index ea63f36..b755c70 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -1,6 +1,6 @@ #include #include "NK_C_API.h" -#include "include/TooLongStringException.h" +#include "include/LibraryException.h" using namespace nitrokey; diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 81d27aa..161f7aa 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -1,8 +1,7 @@ #include #include #include "include/NitrokeyManager.h" -#include "include/TooLongStringException.h" -#include "include/InvalidSlotException.h" +#include "include/LibraryException.h" namespace nitrokey{ diff --git a/TooLongStringException.cpp b/TooLongStringException.cpp deleted file mode 100644 index 96c5132..0000000 --- a/TooLongStringException.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by sz on 09.08.16. -// - -#include "include/TooLongStringException.h" diff --git a/include/InvalidSlotException.h b/include/InvalidSlotException.h deleted file mode 100644 index e97d993..0000000 --- a/include/InvalidSlotException.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by sz on 09.08.16. -// - -#ifndef LIBNITROKEY_INVALIDSLOTEXCEPTION_H -#define LIBNITROKEY_INVALIDSLOTEXCEPTION_H - - -#include -#include -#include "LibraryException.h" - - -class InvalidSlotException : public LibraryException { -public: - virtual uint8_t exception_id() override { - return 201; - } - -public: - uint8_t slot_selected; - - InvalidSlotException(uint8_t slot_selected) : slot_selected(slot_selected) {} - - virtual const char *what() const throw() override { - return "Wrong slot selected"; - } - -}; - -#endif //LIBNITROKEY_INVALIDSLOTEXCEPTION_H diff --git a/include/LibraryException.h b/include/LibraryException.h index ef81624..5036320 100644 --- a/include/LibraryException.h +++ b/include/LibraryException.h @@ -1,12 +1,9 @@ -// -// Created by sz on 09.08.16. -// - #ifndef LIBNITROKEY_LIBRARYEXCEPTION_H #define LIBNITROKEY_LIBRARYEXCEPTION_H #include #include +#include class LibraryException: std::exception { public: @@ -14,4 +11,44 @@ public: }; + +class InvalidSlotException : public LibraryException { +public: + virtual uint8_t exception_id() override { + return 201; + } + +public: + uint8_t slot_selected; + + InvalidSlotException(uint8_t slot_selected) : slot_selected(slot_selected) {} + + virtual const char *what() const throw() override { + return "Wrong slot selected"; + } + +}; + + + +class TooLongStringException : public LibraryException { +public: + virtual uint8_t exception_id() override { + return 200; + } + + std::size_t size_source; + std::size_t size_destination; + std::string message; + + TooLongStringException(size_t size_source, size_t size_destination, const std::string &message = "") : size_source( + size_source), size_destination(size_destination), message(message) {} + + virtual const char *what() const throw() override { + //TODO add sizes and message data to final message + return "Too long string has been supplied as an argument"; + } + +}; + #endif //LIBNITROKEY_LIBRARYEXCEPTION_H diff --git a/include/TooLongStringException.h b/include/TooLongStringException.h deleted file mode 100644 index 58f5801..0000000 --- a/include/TooLongStringException.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by sz on 09.08.16. -// - -#ifndef LIBNITROKEY_TOOLONGSTRINGEXCEPTION_H -#define LIBNITROKEY_TOOLONGSTRINGEXCEPTION_H - - -#include -#include -#include "LibraryException.h" - -class TooLongStringException : public LibraryException { -public: - virtual uint8_t exception_id() override { - return 200; - } - - std::size_t size_source; - std::size_t size_destination; - std::string message; - - TooLongStringException(size_t size_source, size_t size_destination, const std::string &message = "") : size_source( - size_source), size_destination(size_destination), message(message) {} - - virtual const char *what() const throw() override { - //TODO add sizes and message data to final message - return "Too long string has been supplied as an argument"; - } - -}; - - -#endif //LIBNITROKEY_TOOLONGSTRINGEXCEPTION_H -- cgit v1.2.3