aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-26 21:09:16 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:57 +0200
commit7f2bea1869529fb3fa53d809260e2713b43a1fd8 (patch)
tree9ca77a4f70fc7a27304c56399169e137157aeebc
parentf6bd34b262b66fde862aa3d95c339f5c587156eb (diff)
downloadlibnitrokey-7f2bea1869529fb3fa53d809260e2713b43a1fd8.tar.gz
libnitrokey-7f2bea1869529fb3fa53d809260e2713b43a1fd8.tar.bz2
Erase password safe slot
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NK_C_API.cc7
-rw-r--r--NK_C_API.h1
-rw-r--r--NitrokeyManager.cc6
-rw-r--r--include/NitrokeyManager.h2
-rw-r--r--unittest/test_bindings.py8
5 files changed, 24 insertions, 0 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 542c6ad..4f7195e 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -301,6 +301,13 @@ extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_nam
});
}
+extern int NK_erase_password_safe_slot(uint8_t slot_number) {
+ auto m = NitrokeyManager::instance();
+ return get_without_result([&](){
+ m->erase_password_safe_slot(slot_number);
+ });
+}
+
}
diff --git a/NK_C_API.h b/NK_C_API.h
index addafc3..54be406 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -37,6 +37,7 @@ extern const char *NK_get_password_safe_slot_name(uint8_t slot_number, const cha
extern const char *NK_get_password_safe_slot_login(uint8_t slot_number, const char *temporary_password);
extern const char *NK_get_password_safe_slot_password(uint8_t slot_number, const char *temporary_password);
extern int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, const char *slot_password);
+extern int NK_erase_password_safe_slot(uint8_t slot_number);
}
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 7ffee51..018557c 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -277,4 +277,10 @@ namespace nitrokey{
SetPasswordSafeSlotData2::CommandTransaction::run(*device, p2);
}
+ void NitrokeyManager::erase_password_safe_slot(uint8_t slot_number) {
+ auto p = get_payload<ErasePasswordSafeSlot>();
+ p.slot_number = slot_number;
+ ErasePasswordSafeSlot::CommandTransaction::run(*device, p);
+ }
+
} \ No newline at end of file
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index 541945b..629744a 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -57,6 +57,8 @@ namespace nitrokey {
write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login,
const char *slot_password);
+ void erase_password_safe_slot(uint8_t slot_number);
+
private:
NitrokeyManager();
~NitrokeyManager();
diff --git a/unittest/test_bindings.py b/unittest/test_bindings.py
index 4ac3844..2d56865 100644
--- a/unittest/test_bindings.py
+++ b/unittest/test_bindings.py
@@ -11,6 +11,7 @@ RFC_SECRET = '12345678901234567890'
class DefaultPasswords(Enum):
ADMIN = '12345678'
USER = '123456'
+ ADMIN_TEMP = '123123123'
class DeviceErrorCode(Enum):
@@ -85,6 +86,13 @@ def test_get_password_safe_slot_login_password(C):
assert slot_password == 'pass1'
+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 ?
+
+
def test_password_safe_slot_status(C):
C.NK_set_debug(True)
assert C.NK_get_password_safe_slot_status() == DeviceErrorCode.STATUS_OK