aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NK_C_API.cc7
-rw-r--r--NK_C_API.h8
-rw-r--r--unittest/test_pro.py9
3 files changed, 23 insertions, 1 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 1d3fa3a..c44e36f 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -299,6 +299,13 @@ extern "C" {
});
}
+ NK_C_API uint32_t NK_device_serial_number_as_u32() {
+ auto m = NitrokeyManager::instance();
+ return get_with_result([&]() {
+ return m->get_serial_number_as_u32();
+ });
+ }
+
NK_C_API char * NK_get_hotp_code(uint8_t slot_number) {
return NK_get_hotp_code_PIN(slot_number, "");
}
diff --git a/NK_C_API.h b/NK_C_API.h
index d5c54a3..df3e992 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -386,6 +386,14 @@ extern "C" {
NK_C_API char * NK_device_serial_number();
/**
+ * Return the device's serial number string as an integer. Use
+ * NK_last_command_status to check for an error if this function
+ * returns zero.
+ * @return device's serial number as an integer
+ */
+ NK_C_API uint32_t NK_device_serial_number_as_u32();
+
+ /**
* Get last command processing status. Useful for commands which returns the results of their own and could not return
* an error code.
* @return previous command processing error code
diff --git a/unittest/test_pro.py b/unittest/test_pro.py
index 99d7b1f..d25a50e 100644
--- a/unittest/test_pro.py
+++ b/unittest/test_pro.py
@@ -704,6 +704,13 @@ def test_get_serial_number(C):
print(('Serial number of the device: ', sn))
+@pytest.mark.status
+def test_get_serial_number_as_u32(C):
+ sn = C.NK_device_serial_number_as_u32()
+ assert sn > 0
+ print(('Serial number of the device (u32): ', sn))
+
+
@pytest.mark.otp
@pytest.mark.parametrize("secret", ['000001', '00'*10+'ff', '00'*19+'ff', '000102',
'00'*29+'ff', '00'*39+'ff', '002EF43F51AFA97BA2B46418768123C9E1809A5B' ])
@@ -1038,4 +1045,4 @@ def test_OTP_all_rw(C):
this_loop_codes.append(('H', i, code))
all_codes.append(this_loop_codes)
from pprint import pprint
- pprint(all_codes) \ No newline at end of file
+ pprint(all_codes)