From 5a56b83084d797728e5ed557cce2637b3a1e7e56 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 4 Apr 2018 23:54:07 +0200 Subject: Add NK_login_enum to the C API As with the C++ API, identifying the model by the first character of a string is not intuitive. This patch adds the NK_login_enum function to the C API that accepts an enum value instead of a string. It also adds a new enum NK_device_model as device::DeviceModel is an enum class and therefore cannot be used in C. --- NK_C_API.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'NK_C_API.cc') diff --git a/NK_C_API.cc b/NK_C_API.cc index 64355f5..b245940 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -161,6 +161,22 @@ extern "C" { return 0; } + NK_C_API int NK_login_enum(NK_device_model device_model) { + const char *model_string; + switch (device_model) { + case NK_PRO: + model_string = "P"; + break; + case NK_STORAGE: + model_string = "S"; + break; + default: + /* no such enum value -- return error code */ + return 0; + } + return NK_login(model_string); + } + NK_C_API int NK_logout() { auto m = NitrokeyManager::instance(); return get_without_result([&]() { -- cgit v1.2.1