aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-26 21:17:34 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:57 +0200
commit7d71398f4043c10c3870cb9deb2eae7bf1c5f0ee (patch)
treed279064b370c5ec757dccb218b55d8fa65d2c93b
parentba29c8cebf36d8e7b7b18a74df752b1b220ce473 (diff)
downloadlibnitrokey-7d71398f4043c10c3870cb9deb2eae7bf1c5f0ee.tar.gz
libnitrokey-7d71398f4043c10c3870cb9deb2eae7bf1c5f0ee.tar.bz2
Assertions on password safe slot number
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NitrokeyManager.cc10
-rw-r--r--include/NitrokeyManager.h1
-rw-r--r--unittest/test_bindings.py2
3 files changed, 11 insertions, 2 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 018557c..e541b47 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -220,7 +220,8 @@ namespace nitrokey{
}
void NitrokeyManager::get_password_safe_slot_status() {
- GetPasswordSafeSlotStatus::CommandTransaction::run(*device); //TODO FIXME
+ auto responsePayload = GetPasswordSafeSlotStatus::CommandTransaction::run(*device); //TODO FIXME
+ responsePayload.password_safe_status;
}
uint8_t NitrokeyManager::get_user_retry_count() {
@@ -237,6 +238,7 @@ namespace nitrokey{
}
const char *NitrokeyManager::get_password_safe_slot_name(uint8_t slot_number, const char *temporary_password) {
+ assert (is_valid_password_safe_slot_number(slot_number));
auto p = get_payload<GetPasswordSafeSlotName>();
p.slot_number = slot_number;
@@ -249,7 +251,10 @@ namespace nitrokey{
return strdup((const char *) response.slot_name);
}
+ bool NitrokeyManager::is_valid_password_safe_slot_number(uint8_t slot_number) const { return slot_number < 16; }
+
const char *NitrokeyManager::get_password_safe_slot_login(uint8_t slot_number, const char *temporary_password) {
+ assert (is_valid_password_safe_slot_number(slot_number));
auto p = get_payload<GetPasswordSafeSlotLogin>();
p.slot_number = slot_number;
auto response = GetPasswordSafeSlotLogin::CommandTransaction::run(*device, p);
@@ -257,6 +262,7 @@ namespace nitrokey{
}
const char *NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number, const char *temporary_password) {
+ assert (is_valid_password_safe_slot_number(slot_number));
auto p = get_payload<GetPasswordSafeSlotPassword>();
p.slot_number = slot_number;
auto response = GetPasswordSafeSlotPassword::CommandTransaction::run(*device, p);
@@ -265,6 +271,7 @@ namespace nitrokey{
void NitrokeyManager::write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login,
const char *slot_password) {
+ assert (is_valid_password_safe_slot_number(slot_number));
auto p = get_payload<SetPasswordSafeSlotData>();
p.slot_number = slot_number;
strcpyT(p.slot_name, slot_name);
@@ -278,6 +285,7 @@ namespace nitrokey{
}
void NitrokeyManager::erase_password_safe_slot(uint8_t slot_number) {
+ assert (is_valid_password_safe_slot_number(slot_number));
auto p = get_payload<ErasePasswordSafeSlot>();
p.slot_number = slot_number;
ErasePasswordSafeSlot::CommandTransaction::run(*device, p);
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index 629744a..63332aa 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -69,6 +69,7 @@ namespace nitrokey {
bool is_valid_hotp_slot_number(uint8_t slot_number) const;
bool is_valid_totp_slot_number(uint8_t slot_number) const;
+ bool is_valid_password_safe_slot_number(uint8_t slot_number) const;
uint8_t get_internal_slot_number_for_hotp(uint8_t slot_number) const;
uint8_t get_internal_slot_number_for_totp(uint8_t slot_number) const;
bool erase_slot(uint8_t slot_number);
diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py
index c7e64b9..4d749bd 100644
--- a/unittest/test_bindings.py
+++ b/unittest/test_bindings.py
@@ -90,7 +90,7 @@ def test_erase_password_safe_slot(C):
assert C.NK_enable_password_safe(DefaultPasswords.USER) == DeviceErrorCode.STATUS_OK
assert C.NK_erase_password_safe_slot(0) == DeviceErrorCode.STATUS_OK
assert gs(C.NK_get_password_safe_slot_name(0, DefaultPasswords.ADMIN_TEMP)) == ''
- assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK # TODO should be DeviceErrorCode.NOT_PROGRAMMED ?
+ assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK # TODO shouldn't be DeviceErrorCode.NOT_PROGRAMMED ?
def test_password_safe_slot_status(C):