diff options
-rw-r--r-- | NitrokeyManager.cc | 19 | ||||
-rw-r--r-- | libnitrokey/NitrokeyManager.h | 1 | ||||
-rw-r--r-- | unittest/test_offline.cc | 4 |
3 files changed, 24 insertions, 0 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 6c26a43..496496e 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -398,6 +398,25 @@ using nitrokey::misc::strcpyT; return "NA"; } + uint32_t NitrokeyManager::get_serial_number_as_u32() { + if (device == nullptr) { throw DeviceNotConnected("device not connected"); } + switch (device->get_device_model()) { + case DeviceModel::PRO: { + auto response = GetStatus::CommandTransaction::run(device); + return response.data().card_serial_u32; + } + break; + + case DeviceModel::STORAGE: + { + auto response = stick20::GetDeviceStatus::CommandTransaction::run(device); + return response.data().ActiveSmartCardID_u32; + } + break; + } + return 0; + } + stick10::GetStatus::ResponsePayload NitrokeyManager::get_status(){ try{ auto response = GetStatus::CommandTransaction::run(device); diff --git a/libnitrokey/NitrokeyManager.h b/libnitrokey/NitrokeyManager.h index 33ede1b..163a799 100644 --- a/libnitrokey/NitrokeyManager.h +++ b/libnitrokey/NitrokeyManager.h @@ -104,6 +104,7 @@ char * strndup(const char* str, size_t maxlen); stick10::GetStatus::ResponsePayload get_status(); string get_status_as_string(); string get_serial_number(); + uint32_t get_serial_number_as_u32(); char * get_totp_slot_name(uint8_t slot_number); char * get_hotp_slot_name(uint8_t slot_number); diff --git a/unittest/test_offline.cc b/unittest/test_offline.cc index 320ad48..3ca3905 100644 --- a/unittest/test_offline.cc +++ b/unittest/test_offline.cc @@ -67,6 +67,10 @@ TEST_CASE("Test C++ side behaviour in offline", "[fast]") { REQUIRE(serial_number.empty()); REQUIRE_THROWS_AS( + i->get_serial_number_as_u32(), DeviceNotConnected + ); + + REQUIRE_THROWS_AS( i->get_status(), DeviceNotConnected ); |