From d82829f6fc0f55d3eddcf26d14637883541ce452 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 28 Jan 2019 11:53:58 +0100 Subject: Add NK_get_status function to get status struct Currently, the C API provides access to the device status using the NK_get_{major,minor}_firmware_version, NK_device_serial_number and NK_read_config functions. Each function sends a command to the device, although the data is returned in a single response. This patch adds a NK_status struct and a NK_get_status function that provide access to this data with a single command. --- NK_C_API.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'NK_C_API.cc') diff --git a/NK_C_API.cc b/NK_C_API.cc index eae35d5..6905ef4 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -261,6 +261,30 @@ extern "C" { }); } + NK_C_API int NK_get_status(struct NK_status* out) { + if (out == nullptr) { + return -1; + } + auto m = NitrokeyManager::instance(); + auto result = get_with_status([&]() { + return m->get_status(); + }, proto::stick10::GetStatus::ResponsePayload()); + auto error_code = std::get<0>(result); + if (error_code != 0) { + return error_code; + } + + auto status = std::get<1>(result); + out->firmware_version_major = status.firmware_version_st.major; + out->firmware_version_minor = status.firmware_version_st.minor; + out->serial_number_smart_card = status.card_serial_u32; + out->config_numlock = status.numlock; + out->config_capslock = status.capslock; + out->config_scrolllock = status.scrolllock; + out->otp_user_password = status.enable_user_password != 0; + return 0; + } + NK_C_API char * NK_device_serial_number() { auto m = NitrokeyManager::instance(); return get_with_string_result([&]() { -- cgit v1.2.1 From b2f35949dec2251aeb162324864292cdd7596c9b Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 28 Jan 2019 12:00:51 +0100 Subject: Replace NK_status with NK_get_status_as_string For naming consistency, this patch adds the NK_get_status_as_string function to replace NK_status and marks NK_status as deprecated. --- NK_C_API.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'NK_C_API.cc') diff --git a/NK_C_API.cc b/NK_C_API.cc index 6905ef4..e560c3f 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -252,6 +252,10 @@ extern "C" { NK_C_API char * NK_status() { + return NK_get_status_as_string(); + } + + NK_C_API char * NK_get_status_as_string() { auto m = NitrokeyManager::instance(); return get_with_string_result([&]() { string && s = m->get_status_as_string(); -- cgit v1.2.1