diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-31 18:15:37 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-04-03 13:20:36 +0200 |
commit | 9782076fd0c80385f48e2a3c4c61c9dda06841b3 (patch) | |
tree | ad94f5c728d20f265dd8d5b24476f23a0b97cb0b /NK_C_API.cc | |
parent | 71fd63402dcbbc37d6c8b3818de35f7142b850b0 (diff) | |
download | libnitrokey-9782076fd0c80385f48e2a3c4c61c9dda06841b3.tar.gz libnitrokey-9782076fd0c80385f48e2a3c4c61c9dda06841b3.tar.bz2 |
Return OTP codes as strings to make sure they are zero-filled properly
Adjust Python tests for new OTP codes return value
Also remove manual 0-filling
Fixes #57
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r-- | NK_C_API.cc | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index 262a0a4..16099db 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -187,27 +187,33 @@ NK_C_API const char * NK_device_serial_number(){ }); } -NK_C_API uint32_t NK_get_hotp_code(uint8_t slot_number) { +NK_C_API const char * NK_get_hotp_code(uint8_t slot_number) { return NK_get_hotp_code_PIN(slot_number, ""); } -NK_C_API uint32_t NK_get_hotp_code_PIN(uint8_t slot_number, const char* user_temporary_password){ +NK_C_API const char * NK_get_hotp_code_PIN(uint8_t slot_number, const char *user_temporary_password){ auto m = NitrokeyManager::instance(); - return get_with_result([&](){ - return m->get_HOTP_code(slot_number, user_temporary_password); + return get_with_string_result([&](){ + string && s = m->get_HOTP_code(slot_number, user_temporary_password); + char * rs = strdup(s.c_str()); + clear_string(s); + return rs; }); } -NK_C_API uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, - uint8_t last_interval){ +NK_C_API const char * NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, + uint8_t last_interval){ return NK_get_totp_code_PIN(slot_number, challenge, last_totp_time, last_interval, ""); } -NK_C_API uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, - uint8_t last_interval, const char* user_temporary_password){ +NK_C_API const char * NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, + uint8_t last_interval, const char *user_temporary_password){ auto m = NitrokeyManager::instance(); - return get_with_result([&](){ - return m->get_TOTP_code(slot_number, challenge, last_totp_time, last_interval, user_temporary_password); + return get_with_string_result([&](){ + string && s = m->get_TOTP_code(slot_number, challenge, last_totp_time, last_interval, user_temporary_password); + char * rs = strdup(s.c_str()); + clear_string(s); + return rs; }); } |