summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-25 18:41:59 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-11-26 18:56:24 +0100
commitb0412c73b8ff129183f570a4eed72bdafd9f55d3 (patch)
tree6cee009f149f6532042e46b4e08738864f31ae3e
parent385d33bb4c8bb7fe604f5e0acc8aeca5f2146fae (diff)
downloadlibnitrokey-b0412c73b8ff129183f570a4eed72bdafd9f55d3.tar.gz
libnitrokey-b0412c73b8ff129183f570a4eed72bdafd9f55d3.tar.bz2
Handle FillSDCardWithRandomChars command and test it
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--include/stick20_commands.h38
-rw-r--r--unittest/test2.cc34
2 files changed, 71 insertions, 1 deletions
diff --git a/include/stick20_commands.h b/include/stick20_commands.h
index 5679681..a335809 100644
--- a/include/stick20_commands.h
+++ b/include/stick20_commands.h
@@ -139,7 +139,43 @@ namespace nitrokey {
CommandTransaction;
};
- class FillSDCardWithRandomChars : public PasswordCommand<CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS> {};
+// class FillSDCardWithRandomChars : public PasswordCommand<CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS> {};
+
+
+ class FillSDCardWithRandomChars : Command<CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS> {
+ public:
+ enum class ChosenVolumes : uint8_t {
+ all_volumes = 0,
+ encrypted_volume = 1
+ };
+
+ struct CommandPayload {
+ uint8_t volume_flag;
+ uint8_t kind;
+ uint8_t password[20];
+
+ std::string dissect() const {
+ std::stringstream ss;
+ print_to_ss( (int) volume_flag );
+ print_to_ss( kind );
+ print_to_ss(password);
+ return ss.str();
+ }
+ void set_kind_user() {
+ kind = (uint8_t) 'P';
+ }
+ void set_defaults(){
+ set_kind_user();
+ volume_flag = static_cast<uint8_t>(ChosenVolumes::encrypted_volume);
+ }
+
+ } __packed;
+
+ typedef Transaction<Command<CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS>::command_id(),
+ struct CommandPayload, struct EmptyPayload>
+ CommandTransaction;
+ };
+
class SetupHiddenVolume : Command<CommandID::SEND_HIDDEN_VOLUME_SETUP> {
public:
diff --git a/unittest/test2.cc b/unittest/test2.cc
index 9739217..3cfc5c1 100644
--- a/unittest/test2.cc
+++ b/unittest/test2.cc
@@ -31,6 +31,40 @@ void execute_password_command(Device &stick, const char *password, const char ki
}
+TEST_CASE("long operation test", "[test_long]") {
+ Stick20 stick;
+ bool connected = stick.connect();
+ REQUIRE(connected == true);
+ Log::instance().set_loglevel(Loglevel::DEBUG_L2);
+ try{
+// execute_password_command<FillSDCardWithRandomChars>(stick, "12345678", 'P');
+ auto p = get_payload<FillSDCardWithRandomChars>();
+ p.set_defaults();
+ strcpyT(p.password, "12345678");
+ FillSDCardWithRandomChars::CommandTransaction::run(stick, p);
+ this_thread::sleep_for(1000ms);
+
+ CHECK(false);
+ }
+ catch (LongOperationInProgressException &progressException){
+ CHECK(true);
+ }
+
+
+ for (int i = 0; i < 30; ++i) {
+ try {
+ stick10::GetStatus::CommandTransaction::run(stick);
+ }
+ catch (LongOperationInProgressException &progressException){
+ CHECK((int)progressException.progress_bar_value>=0);
+ CAPTURE((int)progressException.progress_bar_value);
+ this_thread::sleep_for(2000ms);
+ }
+
+ }
+
+}
+
TEST_CASE("test", "[test]") {
Stick20 stick;
bool connected = stick.connect();