aboutsummaryrefslogtreecommitdiff
path: root/NK_C_API.h
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-04-02 16:29:27 +0200
committerRobin Krahl <robin.krahl@ireas.org>2020-04-02 16:29:27 +0200
commit0270a9b3de4b45fcfcb83f8e20a78702811d4192 (patch)
tree4135cf93dd87ca81b2e6f534603dfb6f7ca2b1d4 /NK_C_API.h
parent6100df4127eca5f9733cd5fa51acd32c8febd754 (diff)
downloadlibnitrokey-0270a9b3de4b45fcfcb83f8e20a78702811d4192.tar.gz
libnitrokey-0270a9b3de4b45fcfcb83f8e20a78702811d4192.tar.bz2
Add NK_config struct and read/write functions
This patch adds the NK_config struct to the C API that stores the general configuration of a Nitrokey device. It also adds the NK_read_config_struct and NK_write_config_struct functions to make the API easier to use. While NK_write_config_struct is only a convenience method, NK_read_config_struct makes the API more safe as the user no longer has to read the data from a pointer to an array. This patch also extends the test_read_write_config test case with the two new functions.
Diffstat (limited to 'NK_C_API.h')
-rw-r--r--NK_C_API.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/NK_C_API.h b/NK_C_API.h
index d5c54a3..6aab7ca 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -265,6 +265,32 @@ extern "C" {
uint8_t write_level_max;
};
+ /**
+ * The general configuration of a Nitrokey device.
+ */
+ struct NK_config {
+ /**
+ * value in range [0-1] to send HOTP code from slot 'numlock' after double pressing numlock
+ * or outside the range to disable this function
+ */
+ uint8_t numlock;
+ /**
+ * similar to numlock but with capslock
+ */
+ uint8_t capslock;
+ /**
+ * similar to numlock but with scrolllock
+ */
+ uint8_t scrolllock;
+ /**
+ * True to enable OTP PIN protection (require PIN each OTP code request)
+ */
+ bool enable_user_password;
+ /**
+ * Unused.
+ */
+ bool disable_user_password;
+ };
struct NK_storage_ProductionTest{
uint8_t FirmwareVersion_au8[2];
@@ -450,6 +476,14 @@ extern "C" {
bool enable_user_password, bool delete_user_password, const char *admin_temporary_password);
/**
+ * Write general config to the device
+ * @param config the configuration data
+ * @param admin_temporary_password current admin temporary password
+ * @return command processing error code
+ */
+ NK_C_API int NK_write_config_struct(struct NK_config config, const char *admin_temporary_password);
+
+ /**
* Get currently set config - status of function Numlock/Capslock/Scrollock OTP sending and is enabled PIN protected OTP
* @see NK_write_config
* @return uint8_t general_config[5]:
@@ -462,6 +496,15 @@ extern "C" {
*/
NK_C_API uint8_t* NK_read_config();
+ /**
+ * Get currently set config and write it to the given pointer.
+ * @see NK_read_config
+ * @see NK_write_config_struct
+ * @param out a pointer to the struct that should be written to
+ * @return command processing error code
+ */
+ NK_C_API int NK_read_config_struct(struct NK_config* out);
+
//OTP
/**