diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-29 16:37:22 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-29 16:37:22 +0100 |
commit | 1bf90425d2006558ce4f4aac0ed5680d31b77918 (patch) | |
tree | c6789df5d10d1b5f6b83c5d1c7c2889e5ad2a6d9 /NK_C_API.cc | |
parent | b0d1d6a1a44210a25b3d0e6950ec08f551714ccf (diff) | |
parent | dc9dd81105634aeb100c47637fedef425f0ac6f9 (diff) | |
download | libnitrokey-1bf90425d2006558ce4f4aac0ed5680d31b77918.tar.gz libnitrokey-1bf90425d2006558ce4f4aac0ed5680d31b77918.tar.bz2 |
Merge branch 'pr_155'
Add Status structure, and a general command for using it as a result.
Usable to limit calls to the device, when multiple status fields are
required at given time.
Tested on Nitrokey Pro v0.7 and v0.10.
Run offline tests as well (C++ and Python).
Fixes #155
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r-- | NK_C_API.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index eae35d5..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(); @@ -261,6 +265,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([&]() { |