From 6e44c2b11bd1be9e080f1179283c49f9bb8955a5 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Fri, 25 May 2018 00:15:40 +0200 Subject: Expose device model in C API The C++ API already provides access to the model of the connected device in NitrokeyManager::get_connected_device_model(). This patch also exposes this information in the C API by adding NK_get_device_model. As there might be no device connected, the function returns a boolean indicating the connection status and writes the model of the connected device to a pointer passed as an argument. --- 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 8e005b8..56340ac 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -238,6 +238,30 @@ extern "C" { } + NK_C_API bool NK_get_device_model(enum NK_device_model *out) { + if (out == nullptr) { + return false; + } + auto m = NitrokeyManager::instance(); + try { + auto model = m->get_connected_device_model(); + switch (model) { + case DeviceModel::PRO: + *out = NK_PRO; + return true; + case DeviceModel::STORAGE: + *out = NK_STORAGE; + return true; + default: + /* unknown device -- should not happen */ + return false; + } + } catch (const DeviceNotConnected& e) { + return false; + } + } + + void clear_string(std::string &s) { std::fill(s.begin(), s.end(), ' '); } -- cgit v1.2.1