diff options
author | Szczepan Zalega <szczepan.zalega@gmail.com> | 2016-03-20 17:50:27 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan.zalega@gmail.com> | 2016-03-20 17:50:27 +0100 |
commit | 9f4fff341b1ca691c4b1de135dcae392e1ff5602 (patch) | |
tree | 4c98a829052f92a1074a8abaa5ffa08af8b9f884 /unittest/test_HOTP.cc | |
parent | 657792b9542bf66536aaea3e2385da2b0880bcf6 (diff) | |
download | libnitrokey-9f4fff341b1ca691c4b1de135dcae392e1ff5602.tar.gz libnitrokey-9f4fff341b1ca691c4b1de135dcae392e1ff5602.tar.bz2 |
adding hextobyte implementation
Diffstat (limited to 'unittest/test_HOTP.cc')
-rw-r--r-- | unittest/test_HOTP.cc | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc index dec299c..c1147d3 100644 --- a/unittest/test_HOTP.cc +++ b/unittest/test_HOTP.cc @@ -2,10 +2,11 @@ #include "catch.hpp" #include <iostream> -#include <string.h> +//#include <string.h> #include "device_proto.h" #include "log.h" #include "stick10_commands.h" +#include <cstdlib> using namespace std; using namespace nitrokey::device; @@ -20,7 +21,25 @@ std::string getSlotName(Stick10 &stick, int slotNo) { return sName; } -void setSecret (uint8_t slot_secret[]){}; +void setSecret (uint8_t slot_secret[], const char* secretHex){ + assert(strlen(secretHex)%2==0); + char buf[2]; + for(int i=0; i<strlen(secretHex); i++){ + buf[i%2] = secretHex[i]; + if (i%2==1){ + slot_secret[i/2] = strtoul(buf, NULL, 16) & 0xFF; + } + } +}; + +TEST_CASE("test secret", "[functions]") { + uint8_t slot_secret[21]; + slot_secret[20] = 0; + const char* secretHex = "3132333435363738393031323334353637383930"; + setSecret(slot_secret, secretHex); + WARN(slot_secret); + REQUIRE(strcmp("12345678901234567890",reinterpret_cast<char *>(slot_secret) ) == 0 ); +} TEST_CASE("Slot names are correct", "[slotNames]") { Stick10 stick; @@ -40,11 +59,13 @@ TEST_CASE("Slot names are correct", "[slotNames]") { { WriteToHOTPSlot::CommandTransaction::CommandPayload hwrite; hwrite.slot_number = 0; - strcpy(hwrite.slot_name, "rfc_test"); - strcpy(hwrite.slot_secret, ""); - hwrite.slot_config; - strcpy(hwrite.slot_token_id, ""); - strcpy(hwrite.slot_counter, ""); + strcpy(reinterpret_cast<char *>(hwrite.slot_name), "rfc_test"); + //strcpy(reinterpret_cast<char *>(hwrite.slot_secret), ""); + const char* secretHex = "3132333435363738393031323334353637383930"; + setSecret(hwrite.slot_secret, secretHex); + //hwrite.slot_config; + strcpy(reinterpret_cast<char *>(hwrite.slot_token_id), ""); + strcpy(reinterpret_cast<char *>(hwrite.slot_counter), ""); } |