summaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
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 /NitrokeyManager.cc
parentba29c8cebf36d8e7b7b18a74df752b1b220ce473 (diff)
downloadlibnitrokey-7d71398f4043c10c3870cb9deb2eae7bf1c5f0ee.tar.gz
libnitrokey-7d71398f4043c10c3870cb9deb2eae7bf1c5f0ee.tar.bz2
Assertions on password safe slot number
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc10
1 files changed, 9 insertions, 1 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);