summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-04-02 15:14:11 +0200
committerRobin Krahl <robin.krahl@ireas.org>2020-04-02 15:20:38 +0200
commit02f19713c155457e8cc7d80d581bdac35cb1716d (patch)
treea749bf7e45f9c71a1006eef6f0e5ae491ccdc1dc
parent67b14773cf4ab1812af85d3aaf99bdc6119c5a8a (diff)
downloadlibnitrokey-02f19713c155457e8cc7d80d581bdac35cb1716d.tar.gz
libnitrokey-02f19713c155457e8cc7d80d581bdac35cb1716d.tar.bz2
NitrokeyManager: Refactor get_serial_number
To avoid duplicate code, this patch refactors the get_serial_number method to use get_serial_number_as_u32 internally. It does not change get_serial_number’s behavior.
-rw-r--r--NitrokeyManager.cc22
1 files changed, 8 insertions, 14 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 496496e..b6a076a 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -380,22 +380,16 @@ using nitrokey::misc::strcpyT;
string NitrokeyManager::get_serial_number() {
- if (device == nullptr) { return ""; };
- switch (device->get_device_model()) {
- case DeviceModel::PRO: {
- auto response = GetStatus::CommandTransaction::run(device);
- return nitrokey::misc::toHex(response.data().card_serial_u32);
- }
- break;
-
- case DeviceModel::STORAGE:
- {
- auto response = stick20::GetDeviceStatus::CommandTransaction::run(device);
- return nitrokey::misc::toHex(response.data().ActiveSmartCardID_u32);
+ try {
+ auto serial_number = this->get_serial_number_as_u32();
+ if (serial_number == 0) {
+ return "NA";
+ } else {
+ return nitrokey::misc::toHex(serial_number);
}
- break;
+ } catch (DeviceNotConnected& e) {
+ return "";
}
- return "NA";
}
uint32_t NitrokeyManager::get_serial_number_as_u32() {