From e210ef75de4a62aa086e43cc9297d464b4d75be8 Mon Sep 17 00:00:00 2001 From: David Seifert Date: Sun, 7 Aug 2022 14:20:57 +0200 Subject: [PATCH 1/6] Fix `-Wextra-semi` --- libnitrokey/DeviceCommunicationExceptions.h | 14 +++++++------- libnitrokey/command.h | 2 +- libnitrokey/device.h | 12 ++++++------ libnitrokey/stick10_commands.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libnitrokey/DeviceCommunicationExceptions.h b/libnitrokey/DeviceCommunicationExceptions.h index f5d95a6..26fb89a 100644 --- a/libnitrokey/DeviceCommunicationExceptions.h +++ b/libnitrokey/DeviceCommunicationExceptions.h @@ -37,36 +37,36 @@ class DeviceCommunicationException: public std::runtime_error explicit DeviceCommunicationException(const std::string& _msg): std::runtime_error(_msg), message(_msg){ ++occurred; } - uint8_t getType() const {return 1;}; + uint8_t getType() const {return 1;} // virtual const char* what() const throw() override { // return message.c_str(); // } - static bool has_occurred(){ return occurred > 0; }; - static void reset_occurred_flag(){ occurred = 0; }; + static bool has_occurred(){ return occurred > 0; } + static void reset_occurred_flag(){ occurred = 0; } }; class DeviceNotConnected: public DeviceCommunicationException { public: DeviceNotConnected(std::string msg) : DeviceCommunicationException(msg){} - uint8_t getType() const {return 2;}; + uint8_t getType() const {return 2;} }; class DeviceSendingFailure: public DeviceCommunicationException { public: DeviceSendingFailure(std::string msg) : DeviceCommunicationException(msg){} - uint8_t getType() const {return 3;}; + uint8_t getType() const {return 3;} }; class DeviceReceivingFailure: public DeviceCommunicationException { public: DeviceReceivingFailure(std::string msg) : DeviceCommunicationException(msg){} - uint8_t getType() const {return 4;}; + uint8_t getType() const {return 4;} }; class InvalidCRCReceived: public DeviceReceivingFailure { public: InvalidCRCReceived(std::string msg) : DeviceReceivingFailure(msg){} - uint8_t getType() const {return 5;}; + uint8_t getType() const {return 5;} }; diff --git a/libnitrokey/command.h b/libnitrokey/command.h index b1e610c..9e19b88 100644 --- a/libnitrokey/command.h +++ b/libnitrokey/command.h @@ -96,7 +96,7 @@ namespace stick20{ set_kind_admin_prefixed(); break; } - }; + } } __packed; diff --git a/libnitrokey/device.h b/libnitrokey/device.h index f419b11..a4eb9ba 100644 --- a/libnitrokey/device.h +++ b/libnitrokey/device.h @@ -176,14 +176,14 @@ class Device { void show_stats(); // ErrorCounters get_stats(){ return m_counters; } - int get_retry_receiving_count() const { return m_retry_receiving_count; }; - int get_retry_sending_count() const { return m_retry_sending_count; }; - std::chrono::milliseconds get_retry_timeout() const { return m_retry_timeout; }; + int get_retry_receiving_count() const { return m_retry_receiving_count; } + int get_retry_sending_count() const { return m_retry_sending_count; } + std::chrono::milliseconds get_retry_timeout() const { return m_retry_timeout; } std::chrono::milliseconds get_send_receive_delay() const {return m_send_receive_delay;} - int get_last_command_status() {int a = std::atomic_exchange(&last_command_status, static_cast(0)); return a;}; - void set_last_command_status(uint8_t _err) { last_command_status = _err;} ; - bool last_command_sucessfull() const {return last_command_status == 0;}; + int get_last_command_status() {int a = std::atomic_exchange(&last_command_status, static_cast(0)); return a;} + void set_last_command_status(uint8_t _err) { last_command_status = _err;} + bool last_command_sucessfull() const {return last_command_status == 0;} DeviceModel get_device_model() const {return m_model;} void set_receiving_delay(std::chrono::milliseconds delay); void set_retry_delay(std::chrono::milliseconds delay); diff --git a/libnitrokey/stick10_commands.h b/libnitrokey/stick10_commands.h index fc43426..eee2f65 100644 --- a/libnitrokey/stick10_commands.h +++ b/libnitrokey/stick10_commands.h @@ -470,7 +470,7 @@ class GetUserPasswordRetryCount ss << std::hex << std::setfill('0') << std::setw(2) << (int)arr[i] << " "; } ss << std::endl; - }; + } class GetPasswordSafeSlotStatus : Command { From aa3e558101a3ff11ee6dc1e5100c9cc8f62a109a Mon Sep 17 00:00:00 2001 From: David Seifert Date: Sun, 7 Aug 2022 14:20:58 +0200 Subject: [PATCH 2/6] Fix `-Wold-style-cast` * Also recommended by the C++ Core Guidelines: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es49-if-you-must-use-a-cast-use-a-named-cast --- NK_C_API.cc | 8 +-- NitrokeyManager.cc | 12 ++-- device.cc | 4 +- libnitrokey/command.h | 10 ++-- libnitrokey/device_proto.h | 8 +-- libnitrokey/dissect.h | 10 ++-- libnitrokey/misc.h | 2 +- libnitrokey/stick10_commands.h | 88 +++++++++++++++--------------- libnitrokey/stick10_commands_0.8.h | 38 ++++++------- libnitrokey/stick20_commands.h | 84 ++++++++++++++-------------- log.cc | 2 +- misc.cc | 4 +- 12 files changed, 135 insertions(+), 135 deletions(-) diff --git a/NK_C_API.cc b/NK_C_API.cc index 9602be3..b8159b2 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -554,15 +554,15 @@ extern "C" { NK_C_API int NK_is_AES_supported(const char *user_password) { auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return (uint8_t)m->is_AES_supported(user_password); + return get_with_result([&]() -> uint8_t { + return m->is_AES_supported(user_password); }); } NK_C_API int NK_login_auto() { auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return (uint8_t)m->connect(); + return get_with_result([&]() -> uint8_t { + return m->connect(); }); } diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 82a6ebe..5c99997 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -479,8 +479,8 @@ using nitrokey::misc::strcpyT; bool NitrokeyManager::is_internal_hotp_slot_number(uint8_t slot_number) const { return slot_number < 0x20; } bool NitrokeyManager::is_valid_hotp_slot_number(uint8_t slot_number) const { return slot_number < 3; } bool NitrokeyManager::is_valid_totp_slot_number(uint8_t slot_number) const { return slot_number < 0x10-1; } //15 - uint8_t NitrokeyManager::get_internal_slot_number_for_totp(uint8_t slot_number) const { return (uint8_t) (0x20 + slot_number); } - uint8_t NitrokeyManager::get_internal_slot_number_for_hotp(uint8_t slot_number) const { return (uint8_t) (0x10 + slot_number); } + uint8_t NitrokeyManager::get_internal_slot_number_for_totp(uint8_t slot_number) const { return 0x20 + slot_number; } + uint8_t NitrokeyManager::get_internal_slot_number_for_hotp(uint8_t slot_number) const { return 0x10 + slot_number; } @@ -706,7 +706,7 @@ using nitrokey::misc::strcpyT; auto payload = get_payload(); payload.slot_number = slot_number; auto resp = GetSlotName::CommandTransaction::run(device, payload); - return strndup((const char *) resp.data().slot_name, max_string_field_length); + return strndup(reinterpret_cast(resp.data().slot_name), max_string_field_length); } bool NitrokeyManager::first_authenticate(const char *pin, const char *temporary_password) { @@ -821,7 +821,7 @@ using nitrokey::misc::strcpyT; auto p = get_payload(); p.slot_number = slot_number; auto response = GetPasswordSafeSlotName::CommandTransaction::run(device, p); - return strndup((const char *) response.data().slot_name, max_string_field_length); + return strndup(reinterpret_cast(response.data().slot_name), max_string_field_length); } bool NitrokeyManager::is_valid_password_safe_slot_number(uint8_t slot_number) const { return slot_number < 16; } @@ -831,7 +831,7 @@ using nitrokey::misc::strcpyT; auto p = get_payload(); p.slot_number = slot_number; auto response = GetPasswordSafeSlotLogin::CommandTransaction::run(device, p); - return strndup((const char *) response.data().slot_login, max_string_field_length); + return strndup(reinterpret_cast(response.data().slot_login), max_string_field_length); } char * NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number) { @@ -839,7 +839,7 @@ using nitrokey::misc::strcpyT; auto p = get_payload(); p.slot_number = slot_number; auto response = GetPasswordSafeSlotPassword::CommandTransaction::run(device, p); - return strndup((const char *) response.data().slot_password, max_string_field_length); //FIXME use secure way + return strndup(reinterpret_cast(response.data().slot_password), max_string_field_length); //FIXME use secure way } void NitrokeyManager::write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, diff --git a/device.cc b/device.cc index dfcd2c0..b007fe9 100644 --- a/device.cc +++ b/device.cc @@ -179,7 +179,7 @@ int Device::send(const void *packet) { throw DeviceNotConnected("Attempted HID send on an invalid descriptor."); } send_feature_report = hid_send_feature_report( - mp_devhandle, (const unsigned char *)(packet), HID_REPORT_SIZE); + mp_devhandle, static_cast(packet), HID_REPORT_SIZE); if (send_feature_report < 0) _reconnect(); //add thread sleep? LOG(std::string("Sending attempt: ")+std::to_string(i+1) + " / 3" , Loglevel::DEBUG_L2); @@ -200,7 +200,7 @@ int Device::recv(void *packet) { throw DeviceNotConnected("Attempted HID receive on an invalid descriptor."); } - status = (hid_get_feature_report(mp_devhandle, (unsigned char *)(packet), + status = (hid_get_feature_report(mp_devhandle, static_cast(packet), HID_REPORT_SIZE)); auto pwherr = hid_error(mp_devhandle); diff --git a/libnitrokey/command.h b/libnitrokey/command.h index 9e19b88..67fc289 100644 --- a/libnitrokey/command.h +++ b/libnitrokey/command.h @@ -26,14 +26,14 @@ #include "cxx_semantics.h" #define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); -#define print_to_ss_int(x) ( ss << " " << (#x) <<":\t" << (int)(x) << std::endl ); +#define print_to_ss_int(x) ( ss << " " << (#x) <<":\t" << static_cast(x) << std::endl ); #ifdef LOG_VOLATILE_DATA #define print_to_ss_volatile(x) print_to_ss(x); #else #define print_to_ss_volatile(x) ( ss << " " << (#x) <<":\t" << "***********" << std::endl ); #endif #define hexdump_to_ss(x) (ss << #x":\n"\ - << ::nitrokey::misc::hexdump((const uint8_t *) (&x), sizeof x, false)); + << ::nitrokey::misc::hexdump(reinterpret_cast(&x), sizeof x, false)); namespace nitrokey { namespace proto { @@ -71,13 +71,13 @@ namespace stick20{ return ss.str(); } void set_kind_admin() { - kind = (uint8_t) 'A'; + kind = 'A'; } void set_kind_admin_prefixed() { - kind = (uint8_t) 'P'; + kind = 'P'; } void set_kind_user() { - kind = (uint8_t) 'P'; + kind = 'P'; } void set_defaults(){ diff --git a/libnitrokey/device_proto.h b/libnitrokey/device_proto.h index 0cc15df..ed8bb54 100644 --- a/libnitrokey/device_proto.h +++ b/libnitrokey/device_proto.h @@ -91,8 +91,8 @@ namespace nitrokey { uint32_t calculate_CRC() const { // w/o leading zero, a part of each HID packet // w/o 4-byte crc - return misc::stm_crc32((const uint8_t *) (this) + 1, - (size_t) (HID_REPORT_SIZE - 5)); + return misc::stm_crc32(reinterpret_cast(this) + 1, + static_cast(HID_REPORT_SIZE - 5)); } void update_CRC() { crc = calculate_CRC(); } @@ -156,8 +156,8 @@ namespace nitrokey { uint32_t calculate_CRC() const { // w/o leading zero, a part of each HID packet // w/o 4-byte crc - return misc::stm_crc32((const uint8_t *) (this) + 1, - (size_t) (HID_REPORT_SIZE - 5)); + return misc::stm_crc32(reinterpret_cast(this) + 1, + static_cast(HID_REPORT_SIZE - 5)); } void update_CRC() { crc = calculate_CRC(); } diff --git a/libnitrokey/dissect.h b/libnitrokey/dissect.h index 690b5b7..dde8794 100644 --- a/libnitrokey/dissect.h +++ b/libnitrokey/dissect.h @@ -43,11 +43,11 @@ class QueryDissector : semantics::non_constructible { #ifdef LOG_VOLATILE_DATA out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); + out << ::nitrokey::misc::hexdump(reinterpret_cast(&pod), sizeof pod); #endif out << "Contents:" << std::endl; - out << "Command ID:\t" << commandid_to_string((CommandID)(pod.command_id)) + out << "Command ID:\t" << commandid_to_string(static_cast(pod.command_id)) << std::endl; out << "CRC:\t" << std::hex << std::setw(2) << std::setfill('0') @@ -108,12 +108,12 @@ class ResponseDissector : semantics::non_constructible { #ifdef LOG_VOLATILE_DATA out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); + out << ::nitrokey::misc::hexdump(reinterpret_cast(&pod), sizeof pod); #endif out << "Device status:\t" << pod.device_status + 0 << " " << status_translate_device(pod.device_status) << std::endl; - out << "Command ID:\t" << commandid_to_string((CommandID)(pod.command_id)) << " hex: " << std::hex << (int)pod.command_id + out << "Command ID:\t" << commandid_to_string(static_cast(pod.command_id)) << " hex: " << std::hex << static_cast(pod.command_id) << std::endl; out << "Last command CRC:\t" << std::hex << std::setw(2) << std::setfill('0') @@ -123,7 +123,7 @@ class ResponseDissector : semantics::non_constructible { out << "CRC:\t" << std::hex << std::setw(2) << std::setfill('0') << pod.crc << std::endl; - if((int)pod.command_id == pod.storage_status.command_id){ + if(static_cast(pod.command_id) == pod.storage_status.command_id){ out << "Storage stick status (where applicable):" << std::endl; #define d(x) out << " "#x": \t"<< std::hex << std::setw(2) \ << std::setfill('0')<< static_cast(x) << std::endl; diff --git a/libnitrokey/misc.h b/libnitrokey/misc.h index a9c4672..4630585 100644 --- a/libnitrokey/misc.h +++ b/libnitrokey/misc.h @@ -91,7 +91,7 @@ class Option { if (src_strlen > s_dest){ throw TooLongStringException(src_strlen, s_dest, src); } - strncpy((char*) &dest, src, s_dest); + strncpy(reinterpret_cast(&dest), src, s_dest); } #define bzero(b,len) (memset((b), '\0', (len)), (void) 0) diff --git a/libnitrokey/stick10_commands.h b/libnitrokey/stick10_commands.h index eee2f65..c7d499e 100644 --- a/libnitrokey/stick10_commands.h +++ b/libnitrokey/stick10_commands.h @@ -50,7 +50,7 @@ class GetSlotName : public Command { bool isValid() const { return slot_number<0x10+3; } std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -78,7 +78,7 @@ class EraseSlot : Command { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -96,7 +96,7 @@ class SetTime : Command { bool isValid() const { return reset && reset != 1; } std::string dissect() const { std::stringstream ss; - ss << "reset:\t" << (int)(reset) << std::endl; + ss << "reset:\t" << static_cast(reset) << std::endl; ss << "time:\t" << (time) << std::endl; return ss.str(); } @@ -138,20 +138,20 @@ class WriteToHOTPSlot : Command { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; print_to_ss_volatile(slot_name); print_to_ss_volatile(slot_secret); - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; ss << "\tuse_enter(1):\t" << use_enter << std::endl; ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; ss << "slot_token_id:\t"; for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; + ss << std::hex << std::setw(2) << std::setfill('0')<< static_cast(i) << " " ; ss << std::endl; - ss << "slot_counter:\t[" << (int)slot_counter << "]\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); + ss << "slot_counter:\t[" << static_cast(slot_counter) << "]\t" + << ::nitrokey::misc::hexdump(reinterpret_cast(&slot_counter), sizeof slot_counter, false); return ss.str(); } @@ -189,15 +189,15 @@ class WriteToTOTPSlot : Command { bool isValid() const { return !(slot_number & 0xF0); } //TODO check std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; print_to_ss_volatile(slot_name); print_to_ss_volatile(slot_secret); - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "slot_token_id:\t"; for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; + ss << std::hex << std::setw(2) << std::setfill('0')<< static_cast(i) << " " ; ss << std::endl; - ss << "slot_interval:\t" << (int)slot_interval << std::endl; + ss << "slot_interval:\t" << static_cast(slot_interval) << std::endl; return ss.str(); } } __packed; @@ -217,10 +217,10 @@ class GetTOTP : Command { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; ss << "challenge:\t" << (challenge) << std::endl; ss << "last_totp_time:\t" << (last_totp_time) << std::endl; - ss << "last_interval:\t" << (int)(last_interval) << std::endl; + ss << "last_interval:\t" << static_cast(last_interval) << std::endl; return ss.str(); } } __packed; @@ -245,7 +245,7 @@ class GetTOTP : Command { std::string dissect() const { std::stringstream ss; ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; ss << "\tuse_enter(1):\t" << use_enter << std::endl; ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; @@ -265,7 +265,7 @@ class GetHOTP : Command { bool isValid() const { return (slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -290,7 +290,7 @@ class GetHOTP : Command { std::string dissect() const { std::stringstream ss; ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; ss << "\tuse_enter(1):\t" << use_enter << std::endl; ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; @@ -316,7 +316,7 @@ class ReadSlot : Command { std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -350,17 +350,17 @@ class ReadSlot : Command { std::string dissect() const { std::stringstream ss; print_to_ss_volatile(slot_name); - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; ss << "\tuse_enter(1):\t" << use_enter << std::endl; ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; ss << "slot_token_id:\t"; for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; + ss << std::hex << std::setw(2) << std::setfill('0')<< static_cast(i) << " " ; ss << std::endl; - ss << "slot_counter:\t[" << (int)slot_counter << "]\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); + ss << "slot_counter:\t[" << static_cast(slot_counter) << "]\t" + << ::nitrokey::misc::hexdump(reinterpret_cast(&slot_counter), sizeof slot_counter, false); return ss.str(); } } __packed; @@ -407,19 +407,19 @@ class GetStatus : Command { ss << "firmware_version:\t" << "[" << firmware_version << "]" << "\t" << ::nitrokey::misc::hexdump( - (const uint8_t *)(&firmware_version), sizeof firmware_version, false); + reinterpret_cast(&firmware_version), sizeof firmware_version, false); ss << "card_serial_u32:\t" << std::hex << card_serial_u32 << std::endl; ss << "card_serial:\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(card_serial), + << ::nitrokey::misc::hexdump(reinterpret_cast(card_serial), sizeof card_serial, false); ss << "general_config:\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(general_config), + << ::nitrokey::misc::hexdump(reinterpret_cast(general_config), sizeof general_config, false); - ss << "numlock:\t" << (int)numlock << std::endl; - ss << "capslock:\t" << (int)capslock << std::endl; - ss << "scrolllock:\t" << (int)scrolllock << std::endl; - ss << "enable_user_password:\t" << (bool) enable_user_password << std::endl; - ss << "delete_user_password:\t" << (bool) delete_user_password << std::endl; + ss << "numlock:\t" << static_cast(numlock) << std::endl; + ss << "capslock:\t" << static_cast(capslock) << std::endl; + ss << "scrolllock:\t" << static_cast(scrolllock) << std::endl; + ss << "enable_user_password:\t" << static_cast(enable_user_password) << std::endl; + ss << "delete_user_password:\t" << static_cast(delete_user_password) << std::endl; return ss.str(); } @@ -437,7 +437,7 @@ class GetPasswordRetryCount : Command { bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; - ss << " password_retry_count\t" << (int)password_retry_count << std::endl; + ss << " password_retry_count\t" << static_cast(password_retry_count) << std::endl; return ss.str(); } } __packed; @@ -455,7 +455,7 @@ class GetUserPasswordRetryCount bool isValid() const { return true; } std::string dissect() const { std::stringstream ss; - ss << " password_retry_count\t" << (int)password_retry_count << std::endl; + ss << " password_retry_count\t" << static_cast(password_retry_count) << std::endl; return ss.str(); } } __packed; @@ -467,7 +467,7 @@ class GetUserPasswordRetryCount template void write_array(T &ss, Q (&arr)[N]){ for (int i=0; i(arr[i]) << " "; } ss << std::endl; } @@ -499,7 +499,7 @@ class GetPasswordSafeSlotName : Command { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << "slot_number\t" << (int)slot_number << std::endl; + ss << "slot_number\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -528,7 +528,7 @@ class GetPasswordSafeSlotPassword bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; + ss << " slot_number\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -557,7 +557,7 @@ class GetPasswordSafeSlotLogin bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; + ss << " slot_number\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -587,7 +587,7 @@ class SetPasswordSafeSlotData : Command { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; + ss << " slot_number\t" << static_cast(slot_number) << std::endl; print_to_ss_volatile(slot_name); print_to_ss_volatile(slot_password); return ss.str(); @@ -607,7 +607,7 @@ class SetPasswordSafeSlotData2 : Command { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; + ss << " slot_number\t" << static_cast(slot_number) << std::endl; print_to_ss_volatile(slot_login_name); return ss.str(); } @@ -625,7 +625,7 @@ class ErasePasswordSafeSlot : Command { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; + ss << " slot_number\t" << static_cast(slot_number) << std::endl; return ss.str(); } @@ -696,11 +696,11 @@ class WriteGeneralConfig : Command { std::string dissect() const { std::stringstream ss; - ss << "numlock:\t" << (int)numlock << std::endl; - ss << "capslock:\t" << (int)capslock << std::endl; - ss << "scrolllock:\t" << (int)scrolllock << std::endl; - ss << "enable_user_password:\t" << (bool) enable_user_password << std::endl; - ss << "delete_user_password:\t" << (bool) delete_user_password << std::endl; + ss << "numlock:\t" << static_cast(numlock) << std::endl; + ss << "capslock:\t" << static_cast(capslock) << std::endl; + ss << "scrolllock:\t" << static_cast(scrolllock) << std::endl; + ss << "enable_user_password:\t" << static_cast(enable_user_password) << std::endl; + ss << "delete_user_password:\t" << static_cast(delete_user_password) << std::endl; return ss.str(); } } __packed; diff --git a/libnitrokey/stick10_commands_0.8.h b/libnitrokey/stick10_commands_0.8.h index 9477890..6127c16 100644 --- a/libnitrokey/stick10_commands_0.8.h +++ b/libnitrokey/stick10_commands_0.8.h @@ -77,7 +77,7 @@ namespace nitrokey { bool isValid() const { return !(slot_number & 0xF0); } std::string dissect() const { std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; hexdump_to_ss(temporary_admin_password); return ss.str(); } @@ -109,10 +109,10 @@ namespace nitrokey { std::stringstream ss; hexdump_to_ss(temporary_admin_password); ss << "type:\t" << type << std::endl; - ss << "id:\t" << (int)id << std::endl; + ss << "id:\t" << static_cast(id) << std::endl; #ifdef LOG_VOLATILE_DATA ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); + << ::nitrokey::misc::hexdump(reinterpret_cast(&data), sizeof data); #else ss << " Volatile data not logged" << std::endl; #endif @@ -131,7 +131,7 @@ namespace nitrokey { std::stringstream ss; #ifdef LOG_VOLATILE_DATA ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); + << ::nitrokey::misc::hexdump(reinterpret_cast&data), sizeof data); #else ss << " Volatile data not logged" << std::endl; #endif @@ -177,17 +177,17 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; hexdump_to_ss(temporary_admin_password); - ss << "slot_config:\t" << std::bitset<8>((int) _slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; ss << "\tuse_enter(1):\t" << use_enter << std::endl; ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - ss << "slot_number:\t" << (int) (slot_number) << std::endl; - ss << "slot_counter_or_interval:\t[" << (int) slot_counter_or_interval << "]\t" - << ::nitrokey::misc::hexdump((const uint8_t *) (&slot_counter_or_interval), sizeof slot_counter_or_interval, false); + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; + ss << "slot_counter_or_interval:\t[" << static_cast(slot_counter_or_interval) << "]\t" + << ::nitrokey::misc::hexdump(reinterpret_cast(&slot_counter_or_interval), sizeof slot_counter_or_interval, false); ss << "slot_token_id:\t"; for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0') << (int) i << " "; + ss << std::hex << std::setw(2) << std::setfill('0') << static_cast(i) << " "; ss << std::endl; return ss.str(); @@ -213,7 +213,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; hexdump_to_ss(temporary_user_password); - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; return ss.str(); } } __packed; @@ -238,7 +238,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; ss << "\tuse_enter(1):\t" << use_enter << std::endl; ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; @@ -265,10 +265,10 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; hexdump_to_ss(temporary_user_password); - ss << "slot_number:\t" << (int)(slot_number) << std::endl; + ss << "slot_number:\t" << static_cast(slot_number) << std::endl; ss << "challenge:\t" << (challenge) << std::endl; ss << "last_totp_time:\t" << (last_totp_time) << std::endl; - ss << "last_interval:\t" << (int)(last_interval) << std::endl; + ss << "last_interval:\t" << static_cast(last_interval) << std::endl; return ss.str(); } } __packed; @@ -293,7 +293,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; + ss << "slot_config:\t" << std::bitset<8>(static_cast(_slot_config)) << std::endl; ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; ss << "\tuse_enter(1):\t" << use_enter << std::endl; ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; @@ -328,11 +328,11 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; - ss << "numlock:\t" << (int)numlock << std::endl; - ss << "capslock:\t" << (int)capslock << std::endl; - ss << "scrolllock:\t" << (int)scrolllock << std::endl; - ss << "enable_user_password:\t" << (bool) enable_user_password << std::endl; - ss << "delete_user_password:\t" << (bool) delete_user_password << std::endl; + ss << "numlock:\t" << static_cast(numlock) << std::endl; + ss << "capslock:\t" << static_cast(capslock) << std::endl; + ss << "scrolllock:\t" << static_cast(scrolllock) << std::endl; + ss << "enable_user_password:\t" << static_cast(enable_user_password) << std::endl; + ss << "delete_user_password:\t" << static_cast(delete_user_password) << std::endl; return ss.str(); } } __packed; diff --git a/libnitrokey/stick20_commands.h b/libnitrokey/stick20_commands.h index 7efa1b6..62ff6d5 100644 --- a/libnitrokey/stick20_commands.h +++ b/libnitrokey/stick20_commands.h @@ -106,13 +106,13 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; - print_to_ss( (int) volume_flag ); + print_to_ss( static_cast(volume_flag) ); print_to_ss( kind ); print_to_ss_volatile(admin_pin); return ss.str(); } void set_kind_user() { - kind = (uint8_t) 'P'; + kind = 'P'; } void set_defaults(){ set_kind_user(); @@ -141,12 +141,12 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; ss << "_padding:" << std::endl - << ::nitrokey::misc::hexdump((const uint8_t *) (_padding), + << ::nitrokey::misc::hexdump(reinterpret_cast(_padding), sizeof _padding); - print_to_ss((int) SendCounter_u8); - print_to_ss((int) SendDataType_u8); - print_to_ss((int) FollowBytesFlag_u8); - print_to_ss((int) SendSize_u8); + print_to_ss(static_cast(SendCounter_u8)); + print_to_ss(static_cast(SendDataType_u8)); + print_to_ss(static_cast(FollowBytesFlag_u8)); + print_to_ss(static_cast(SendSize_u8)); return ss.str(); } @@ -212,27 +212,27 @@ namespace nitrokey { print_to_ss(transmission_data.dissect()); print_to_ss( MagicNumber_StickConfig_u16 ); - print_to_ss((int) ReadWriteFlagUncryptedVolume_u8 ); - print_to_ss((int) ReadWriteFlagCryptedVolume_u8 ); - print_to_ss((int) ReadWriteFlagHiddenVolume_u8 ); - print_to_ss((int) versionInfo.major ); - print_to_ss((int) versionInfo.minor ); - print_to_ss((int) versionInfo.build_iteration ); - print_to_ss((int) FirmwareLocked_u8 ); - print_to_ss((int) NewSDCardFound_u8 ); - print_to_ss((int) NewSDCardFound_st.NewCard ); - print_to_ss((int) NewSDCardFound_st.Counter ); - print_to_ss((int) SDFillWithRandomChars_u8 ); + print_to_ss(static_cast(ReadWriteFlagUncryptedVolume_u8) ); + print_to_ss(static_cast(ReadWriteFlagCryptedVolume_u8) ); + print_to_ss(static_cast(ReadWriteFlagHiddenVolume_u8) ); + print_to_ss(static_cast(versionInfo.major) ); + print_to_ss(static_cast(versionInfo.minor) ); + print_to_ss(static_cast(versionInfo.build_iteration) ); + print_to_ss(static_cast(FirmwareLocked_u8) ); + print_to_ss(static_cast(NewSDCardFound_u8) ); + print_to_ss(static_cast(NewSDCardFound_st.NewCard) ); + print_to_ss(static_cast(NewSDCardFound_st.Counter) ); + print_to_ss(static_cast(SDFillWithRandomChars_u8) ); print_to_ss( ActiveSD_CardID_u32 ); - print_to_ss((int) VolumeActiceFlag_u8 ); - print_to_ss((int) VolumeActiceFlag_st.unencrypted ); - print_to_ss((int) VolumeActiceFlag_st.encrypted ); - print_to_ss((int) VolumeActiceFlag_st.hidden); - print_to_ss((int) NewSmartCardFound_u8 ); - print_to_ss((int) UserPwRetryCount ); - print_to_ss((int) AdminPwRetryCount ); + print_to_ss(static_cast(VolumeActiceFlag_u8) ); + print_to_ss(static_cast(VolumeActiceFlag_st.unencrypted) ); + print_to_ss(static_cast(VolumeActiceFlag_st.encrypted) ); + print_to_ss(static_cast(VolumeActiceFlag_st.hidden) ); + print_to_ss(static_cast(NewSmartCardFound_u8) ); + print_to_ss(static_cast(UserPwRetryCount) ); + print_to_ss(static_cast(AdminPwRetryCount) ); print_to_ss( ActiveSmartCardID_u32 ); - print_to_ss((int) StickKeysNotInitiated ); + print_to_ss(static_cast(StickKeysNotInitiated) ); return ss.str(); } @@ -296,10 +296,10 @@ namespace nitrokey { uint8_t ReadLevelMax; std::string dissect() const { std::stringstream ss; - print_to_ss((int) WriteLevelMin); - print_to_ss((int) WriteLevelMax); - print_to_ss((int) ReadLevelMin); - print_to_ss((int) ReadLevelMax); + print_to_ss(static_cast(WriteLevelMin)); + print_to_ss(static_cast(WriteLevelMax)); + print_to_ss(static_cast(ReadLevelMin)); + print_to_ss(static_cast(ReadLevelMax)); return ss.str(); } } __packed; @@ -319,9 +319,9 @@ namespace nitrokey { uint8_t HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSWORD_SIZE]; std::string dissect() const { std::stringstream ss; - print_to_ss((int) SlotNr_u8); - print_to_ss((int) StartBlockPercent_u8); - print_to_ss((int) EndBlockPercent_u8); + print_to_ss(static_cast(SlotNr_u8)); + print_to_ss(static_cast(StartBlockPercent_u8)); + print_to_ss(static_cast(EndBlockPercent_u8)); print_to_ss_volatile(HiddenVolumePassword_au8); return ss.str(); } @@ -361,20 +361,20 @@ namespace nitrokey { std::stringstream ss; print_to_ss(transmission_data.dissect()); - print_to_ss((int) FirmwareVersion_au8[0]); - print_to_ss((int) FirmwareVersion_au8[1]); - print_to_ss((int) FirmwareVersionInternal_u8); - print_to_ss((int) SD_Card_Size_u8); + print_to_ss(static_cast(FirmwareVersion_au8[0])); + print_to_ss(static_cast(FirmwareVersion_au8[1])); + print_to_ss(static_cast(FirmwareVersionInternal_u8)); + print_to_ss(static_cast(SD_Card_Size_u8)); print_to_ss( CPU_CardID_u32); print_to_ss( SmartCardID_u32); print_to_ss( SD_CardID_u32); - print_to_ss((int) SC_UserPwRetryCount); - print_to_ss((int) SC_AdminPwRetryCount); - print_to_ss((int) SD_Card_ManufacturingYear_u8); - print_to_ss((int) SD_Card_ManufacturingMonth_u8); + print_to_ss(static_cast(SC_UserPwRetryCount)); + print_to_ss(static_cast(SC_AdminPwRetryCount)); + print_to_ss(static_cast(SD_Card_ManufacturingYear_u8)); + print_to_ss(static_cast(SD_Card_ManufacturingMonth_u8)); print_to_ss( SD_Card_OEM_u16); print_to_ss( SD_WriteSpeed_u16); - print_to_ss((int) SD_Card_Manufacturer_u8); + print_to_ss(static_cast(SD_Card_Manufacturer_u8)); return ss.str(); } diff --git a/log.cc b/log.cc index 049095f..a3c79b2 100644 --- a/log.cc +++ b/log.cc @@ -56,7 +56,7 @@ namespace nitrokey { void Log::operator()(const std::string &logstr, Loglevel lvl) { if (mp_loghandler != nullptr){ // FIXME crashes on exit because static object under mp_loghandler is not valid anymore, see NitrokeyManager::set_log_function - if ((int) lvl <= (int) m_loglevel) mp_loghandler->print(prefix+logstr, lvl); + if (static_cast(lvl) <= static_cast(m_loglevel)) mp_loghandler->print(prefix+logstr, lvl); } } diff --git a/misc.cc b/misc.cc index 59185f3..3cdeb8f 100644 --- a/misc.cc +++ b/misc.cc @@ -114,8 +114,8 @@ static uint32_t _crc32(uint32_t crc, uint32_t data) { uint32_t stm_crc32(const uint8_t *data, size_t size) { uint32_t crc = 0xffffffff; - const uint32_t *pend = (const uint32_t *)(data + size); - for (const uint32_t *p = (const uint32_t *)(data); p < pend; p++) + const uint32_t *pend = reinterpret_cast(data + size); + for (const uint32_t *p = reinterpret_cast(data); p < pend; p++) crc = _crc32(crc, *p); return crc; } From a9a8fd61e9ad175ba4add7709817c1e3d6db2c17 Mon Sep 17 00:00:00 2001 From: David Seifert Date: Sun, 7 Aug 2022 14:20:58 +0200 Subject: [PATCH 3/6] Fix `-Wdeprecated-dynamic-exception-spec` --- NitrokeyManager.cc | 2 +- libnitrokey/CommandFailedException.h | 14 +++++++------- libnitrokey/DeviceCommunicationExceptions.h | 2 +- libnitrokey/LibraryException.h | 8 ++++---- libnitrokey/LongOperationInProgressException.h | 2 +- libnitrokey/NitrokeyManager.h | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 5c99997..5a35575 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -357,7 +357,7 @@ using nitrokey::misc::strcpyT; return res; } - bool NitrokeyManager::is_connected() throw(){ + bool NitrokeyManager::is_connected() noexcept { std::lock_guard lock(mex_dev_com_manager); if(device != nullptr){ auto connected = device->could_be_enumerated(); diff --git a/libnitrokey/CommandFailedException.h b/libnitrokey/CommandFailedException.h index 32bd6b7..8b765f7 100644 --- a/libnitrokey/CommandFailedException.h +++ b/libnitrokey/CommandFailedException.h @@ -41,32 +41,32 @@ class CommandFailedException : public std::exception { LOG(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); } - virtual const char *what() const throw() { + virtual const char *what() const noexcept { return "Command execution has failed on device"; } - bool reason_timestamp_warning() const throw(){ + bool reason_timestamp_warning() const noexcept { return last_command_status == static_cast(cs::timestamp_warning); } - bool reason_AES_not_initialized() const throw(){ + bool reason_AES_not_initialized() const noexcept { return last_command_status == static_cast(cs::AES_dec_failed); } - bool reason_not_authorized() const throw(){ + bool reason_not_authorized() const noexcept { return last_command_status == static_cast(cs::not_authorized); } - bool reason_slot_not_programmed() const throw(){ + bool reason_slot_not_programmed() const noexcept { return last_command_status == static_cast(cs::slot_not_programmed); } - bool reason_wrong_password() const throw(){ + bool reason_wrong_password() const noexcept { return last_command_status == static_cast(cs::wrong_password); } - bool reason_smartcard_busy() const throw(){ + bool reason_smartcard_busy() const noexcept { return last_command_status == static_cast(cs2::smartcard_error); } diff --git a/libnitrokey/DeviceCommunicationExceptions.h b/libnitrokey/DeviceCommunicationExceptions.h index 26fb89a..1b6969d 100644 --- a/libnitrokey/DeviceCommunicationExceptions.h +++ b/libnitrokey/DeviceCommunicationExceptions.h @@ -38,7 +38,7 @@ class DeviceCommunicationException: public std::runtime_error ++occurred; } uint8_t getType() const {return 1;} -// virtual const char* what() const throw() override { +// virtual const char* what() const noexcept override { // return message.c_str(); // } static bool has_occurred(){ return occurred > 0; } diff --git a/libnitrokey/LibraryException.h b/libnitrokey/LibraryException.h index 3b9d177..97f2974 100644 --- a/libnitrokey/LibraryException.h +++ b/libnitrokey/LibraryException.h @@ -46,7 +46,7 @@ class TargetBufferSmallerThanSource: public LibraryException { size_t source_size, size_t target_size ) : source_size(source_size), target_size(target_size) {} - virtual const char *what() const throw() override { + virtual const char *what() const noexcept override { std::string s = " "; auto ts = [](size_t x){ return std::to_string(x); }; std::string msg = std::string("Target buffer size is smaller than source: [source size, buffer size]") @@ -67,7 +67,7 @@ class InvalidHexString : public LibraryException { InvalidHexString (uint8_t invalid_char) : invalid_char( invalid_char) {} - virtual const char *what() const throw() override { + virtual const char *what() const noexcept override { return "Invalid character in hex string"; } @@ -84,7 +84,7 @@ class InvalidSlotException : public LibraryException { InvalidSlotException(uint8_t slot_selected) : slot_selected(slot_selected) {} - virtual const char *what() const throw() override { + virtual const char *what() const noexcept override { return "Wrong slot selected"; } @@ -108,7 +108,7 @@ class TooLongStringException : public LibraryException { } - virtual const char *what() const throw() override { + virtual const char *what() const noexcept override { //TODO add sizes and message data to final message return "Too long string has been supplied as an argument"; } diff --git a/libnitrokey/LongOperationInProgressException.h b/libnitrokey/LongOperationInProgressException.h index 865d6b5..392b214 100644 --- a/libnitrokey/LongOperationInProgressException.h +++ b/libnitrokey/LongOperationInProgressException.h @@ -36,7 +36,7 @@ class LongOperationInProgressException : public CommandFailedException { std::string("LongOperationInProgressException, progress bar status: ")+ std::to_string(progress_bar_value), nitrokey::log::Loglevel::DEBUG); } - virtual const char *what() const throw() { + virtual const char *what() const noexcept { return "Device returned busy status with long operation in progress"; } }; diff --git a/libnitrokey/NitrokeyManager.h b/libnitrokey/NitrokeyManager.h index 34a4fca..b1a7373 100644 --- a/libnitrokey/NitrokeyManager.h +++ b/libnitrokey/NitrokeyManager.h @@ -95,7 +95,7 @@ char * strndup(const char* str, size_t maxlen); bool connect(device::DeviceModel device_model); bool connect(); bool disconnect(); - bool is_connected() throw() ; + bool is_connected() noexcept ; bool could_current_device_be_enumerated(); bool set_default_commands_delay(int delay); From c8f3e0db615a6135178474a9ac5ee411a61750f0 Mon Sep 17 00:00:00 2001 From: David Seifert Date: Sun, 7 Aug 2022 14:20:59 +0200 Subject: [PATCH 4/6] Fix `-Wsuggest-override` --- libnitrokey/CommandFailedException.h | 2 +- libnitrokey/LongOperationInProgressException.h | 2 +- libnitrokey/log.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libnitrokey/CommandFailedException.h b/libnitrokey/CommandFailedException.h index 8b765f7..19712ef 100644 --- a/libnitrokey/CommandFailedException.h +++ b/libnitrokey/CommandFailedException.h @@ -41,7 +41,7 @@ class CommandFailedException : public std::exception { LOG(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); } - virtual const char *what() const noexcept { + virtual const char *what() const noexcept override { return "Command execution has failed on device"; } diff --git a/libnitrokey/LongOperationInProgressException.h b/libnitrokey/LongOperationInProgressException.h index 392b214..81f6d0a 100644 --- a/libnitrokey/LongOperationInProgressException.h +++ b/libnitrokey/LongOperationInProgressException.h @@ -36,7 +36,7 @@ class LongOperationInProgressException : public CommandFailedException { std::string("LongOperationInProgressException, progress bar status: ")+ std::to_string(progress_bar_value), nitrokey::log::Loglevel::DEBUG); } - virtual const char *what() const noexcept { + virtual const char *what() const noexcept override { return "Device returned busy status with long operation in progress"; } }; diff --git a/libnitrokey/log.h b/libnitrokey/log.h index e296909..f7a4c8f 100644 --- a/libnitrokey/log.h +++ b/libnitrokey/log.h @@ -55,7 +55,7 @@ namespace nitrokey { class StdlogHandler : public LogHandler { public: - virtual void print(const std::string &, Loglevel lvl); + virtual void print(const std::string &, Loglevel lvl) override; }; class FunctionalLogHandler : public LogHandler { @@ -63,7 +63,7 @@ namespace nitrokey { log_function_type log_function; public: FunctionalLogHandler(log_function_type _log_function); - virtual void print(const std::string &, Loglevel lvl); + virtual void print(const std::string &, Loglevel lvl) override; }; @@ -72,7 +72,7 @@ namespace nitrokey { log_function_type log_function; public: RawFunctionalLogHandler(log_function_type _log_function); - virtual void print(const std::string &, Loglevel lvl); + virtual void print(const std::string &, Loglevel lvl) override; }; From 9ed297be77f49dc8f8fb211275bba9e1c90cfc69 Mon Sep 17 00:00:00 2001 From: David Seifert Date: Sun, 7 Aug 2022 14:21:00 +0200 Subject: [PATCH 5/6] Fix `-Wshadow` --- NitrokeyManager.cc | 4 ++-- libnitrokey/CommandFailedException.h | 6 +++--- libnitrokey/LibraryException.h | 12 ++++++------ libnitrokey/LongOperationInProgressException.h | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 5a35575..753339c 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -65,14 +65,14 @@ using nitrokey::misc::strcpyT; // package type to auth, auth type [Authorize,UserAuthorize] template - void NitrokeyManager::authorize_packet(T &package, const char *admin_temporary_password, shared_ptr device){ + void NitrokeyManager::authorize_packet(T &package, const char *admin_temporary_password, shared_ptr device_){ if (!is_authorization_command_supported()){ LOG("Authorization command not supported, skipping", Loglevel::WARNING); } auto auth = get_payload(); strcpyT(auth.temporary_password, admin_temporary_password); auth.crc_to_authorize = S::CommandTransaction::getCRC(package); - A::CommandTransaction::run(device, auth); + A::CommandTransaction::run(device_, auth); } shared_ptr NitrokeyManager::_instance = nullptr; diff --git a/libnitrokey/CommandFailedException.h b/libnitrokey/CommandFailedException.h index 19712ef..36e6933 100644 --- a/libnitrokey/CommandFailedException.h +++ b/libnitrokey/CommandFailedException.h @@ -35,9 +35,9 @@ class CommandFailedException : public std::exception { const uint8_t last_command_id; const uint8_t last_command_status; - CommandFailedException(uint8_t last_command_id, uint8_t last_command_status) : - last_command_id(last_command_id), - last_command_status(last_command_status){ + CommandFailedException(uint8_t last_command_id_, uint8_t last_command_status_) : + last_command_id(last_command_id_), + last_command_status(last_command_status_) { LOG(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); } diff --git a/libnitrokey/LibraryException.h b/libnitrokey/LibraryException.h index 97f2974..f85bc2a 100644 --- a/libnitrokey/LibraryException.h +++ b/libnitrokey/LibraryException.h @@ -43,8 +43,8 @@ class TargetBufferSmallerThanSource: public LibraryException { size_t target_size; TargetBufferSmallerThanSource( - size_t source_size, size_t target_size - ) : source_size(source_size), target_size(target_size) {} + size_t source_size_, size_t target_size_ + ) : source_size(source_size_), target_size(target_size_) {} virtual const char *what() const noexcept override { std::string s = " "; @@ -65,7 +65,7 @@ class InvalidHexString : public LibraryException { public: uint8_t invalid_char; - InvalidHexString (uint8_t invalid_char) : invalid_char( invalid_char) {} + InvalidHexString (uint8_t invalid_char_) : invalid_char(invalid_char_) {} virtual const char *what() const noexcept override { return "Invalid character in hex string"; @@ -82,7 +82,7 @@ class InvalidSlotException : public LibraryException { public: uint8_t slot_selected; - InvalidSlotException(uint8_t slot_selected) : slot_selected(slot_selected) {} + InvalidSlotException(uint8_t slot_selected_) : slot_selected(slot_selected_) {} virtual const char *what() const noexcept override { return "Wrong slot selected"; @@ -102,8 +102,8 @@ class TooLongStringException : public LibraryException { 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) { + TooLongStringException(size_t size_source_, size_t size_destination_, const std::string &message_ = "") : size_source( + size_source_), size_destination(size_destination_), message(message_) { LOG(std::string("TooLongStringException, size diff: ")+ std::to_string(size_source-size_destination), nitrokey::log::Loglevel::DEBUG); } diff --git a/libnitrokey/LongOperationInProgressException.h b/libnitrokey/LongOperationInProgressException.h index 81f6d0a..12ccc21 100644 --- a/libnitrokey/LongOperationInProgressException.h +++ b/libnitrokey/LongOperationInProgressException.h @@ -30,8 +30,8 @@ class LongOperationInProgressException : public CommandFailedException { unsigned char progress_bar_value; LongOperationInProgressException( - unsigned char _command_id, uint8_t last_command_status, unsigned char _progress_bar_value) - : CommandFailedException(_command_id, last_command_status), progress_bar_value(_progress_bar_value){ + unsigned char command_id_, uint8_t last_command_status_, unsigned char progress_bar_value_) + : CommandFailedException(command_id_, last_command_status_), progress_bar_value(progress_bar_value_){ LOG( std::string("LongOperationInProgressException, progress bar status: ")+ std::to_string(progress_bar_value), nitrokey::log::Loglevel::DEBUG); From d56ab10a81310a5b1b92299106e5c5e4c9b3ba97 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 29 Aug 2022 17:18:08 +0200 Subject: [PATCH 6/6] Update Catch to the latest v2.x -> v2.13.9 --- unittest/Catch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/Catch b/unittest/Catch index 15cf3ca..62fd660 160000 --- a/unittest/Catch +++ b/unittest/Catch @@ -1 +1 @@ -Subproject commit 15cf3caaceb21172ea42a24e595a2eb58c3ec960 +Subproject commit 62fd660583d3ae7a7886930b413c3c570e89786c