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.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index 222e5e1..10cc29f 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -89,6 +89,17 @@ extern "C" { */ NK_C_API int NK_logout(); + /** + * Query the model of the connected device. If the out argument is + * NULL or if there is no connected device, this function returns + * false. Otherwise it returns true and sets the target of the out + * pointer to the model of the connected device. + * + * @param out a pointer to write the model to + * @return true if a device is connected and the out argument has been set + */ + NK_C_API bool NK_get_device_model(enum NK_device_model *out); + /** * Return the debug status string. Debug purposes. * @return command processing error code -- cgit v1.2.1 From f0f1691bc741da48bc2e1adfa4535026ae42d6d3 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 20 Jun 2018 12:03:28 +0200 Subject: Replace *out function parameter with return value Using return value instead of memory manipulation seem to be cleaner solution and less error prone due to avoiding pointer usage. Signed-off-by: Szczepan Zalega --- NK_C_API.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index 10cc29f..a739aff 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -41,14 +41,18 @@ extern "C" { * The Nitrokey device models supported by the API. */ enum NK_device_model { + /** + * Use, if no supported device is connected + */ + NK_DISCONNECTED = 0, /** * Nitrokey Pro. */ - NK_PRO, + NK_PRO = 1, /** * Nitrokey Storage. */ - NK_STORAGE + NK_STORAGE = 2 }; /** @@ -90,15 +94,12 @@ extern "C" { NK_C_API int NK_logout(); /** - * Query the model of the connected device. If the out argument is - * NULL or if there is no connected device, this function returns - * false. Otherwise it returns true and sets the target of the out - * pointer to the model of the connected device. + * Query the model of the connected device. + * Returns the model of the connected device or NK_DISCONNECTED. * - * @param out a pointer to write the model to * @return true if a device is connected and the out argument has been set */ - NK_C_API bool NK_get_device_model(enum NK_device_model *out); + NK_C_API enum NK_device_model NK_get_device_model(); /** * Return the debug status string. Debug purposes. -- cgit v1.2.1