diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-04-02 16:29:27 +0200 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2020-04-02 16:29:27 +0200 |
commit | 0270a9b3de4b45fcfcb83f8e20a78702811d4192 (patch) | |
tree | 4135cf93dd87ca81b2e6f534603dfb6f7ca2b1d4 /NK_C_API.cc | |
parent | 6100df4127eca5f9733cd5fa51acd32c8febd754 (diff) | |
download | libnitrokey-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.cc')
-rw-r--r-- | NK_C_API.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index 1d3fa3a..d993671 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -217,6 +217,12 @@ extern "C" { }); } + NK_C_API int NK_write_config_struct(struct NK_config config, + const char *admin_temporary_password) { + return NK_write_config(config.numlock, config.capslock, config.scrolllock, config.enable_user_password, + config.disable_user_password, admin_temporary_password); + } + NK_C_API uint8_t* NK_read_config() { auto m = NitrokeyManager::instance(); @@ -226,6 +232,21 @@ extern "C" { }); } + NK_C_API int NK_read_config_struct(struct NK_config* out) { + if (out == nullptr) { + return -1; + } + auto m = NitrokeyManager::instance(); + return get_without_result([&]() { + auto v = m->read_config(); + out->numlock = v[0]; + out->capslock = v[1]; + out->scrolllock = v[2]; + out->enable_user_password = v[3]; + out->disable_user_password = v[4]; + }); + } + NK_C_API enum NK_device_model NK_get_device_model() { auto m = NitrokeyManager::instance(); |