aboutsummaryrefslogtreecommitdiff
path: root/unittest/test_HOTP.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 22:11:07 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 22:11:07 +0200
commit4ac5f8bbbd6e007ecd02be46bfbc0c11de010722 (patch)
tree5baef202153147b396ba5b377da2e88cb62ae19a /unittest/test_HOTP.cc
parent137a28c05ceacd0427fe1fb25b5a184d6b96985c (diff)
downloadlibnitrokey-4ac5f8bbbd6e007ecd02be46bfbc0c11de010722.tar.gz
libnitrokey-4ac5f8bbbd6e007ecd02be46bfbc0c11de010722.tar.bz2
C++ tests: use get_payload() function to clear packet before using
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest/test_HOTP.cc')
-rw-r--r--unittest/test_HOTP.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc
index a961b24..f25bad4 100644
--- a/unittest/test_HOTP.cc
+++ b/unittest/test_HOTP.cc
@@ -5,11 +5,13 @@
#include "log.h"
#include "stick10_commands.h"
#include <cstdlib>
+#include "misc.h"
using namespace std;
using namespace nitrokey::device;
using namespace nitrokey::proto::stick10;
using namespace nitrokey::log;
+using namespace nitrokey::misc;
void hexStringToByte(uint8_t data[], const char* hexString){
assert(strlen(hexString)%2==0);
@@ -43,7 +45,7 @@ TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") {
const char * temporary_password = "123456789012345678901234";
{
- FirstAuthenticate::CommandTransaction::CommandPayload authreq;
+ auto authreq = get_payload<FirstAuthenticate>();
strcpy((char *)(authreq.card_password), "12345678");
strcpy((char *)(authreq.temporary_password), temporary_password);
FirstAuthenticate::CommandTransaction::run(stick, authreq);
@@ -51,21 +53,20 @@ TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") {
//test according to https://tools.ietf.org/html/rfc4226#page-32
{
- WriteToHOTPSlot::CommandTransaction::CommandPayload hwrite;
+ auto hwrite = get_payload<WriteToHOTPSlot>();
hwrite.slot_number = 0x10;
strcpy(reinterpret_cast<char *>(hwrite.slot_name), "rfc4226_lib");
//strcpy(reinterpret_cast<char *>(hwrite.slot_secret), "");
const char* secretHex = "3132333435363738393031323334353637383930";
hexStringToByte(hwrite.slot_secret, secretHex);
- // reset the HOTP counter
-// memset(hwrite.slot_counter, 0, 8);
+
//hwrite.slot_config; //TODO check various configs in separate test cases
//strcpy(reinterpret_cast<char *>(hwrite.slot_token_id), "");
//strcpy(reinterpret_cast<char *>(hwrite.slot_counter), "");
//authorize writehotp first
{
- Authorize::CommandTransaction::CommandPayload auth;
+ auto auth = get_payload<Authorize>();
strcpy((char *)(auth.temporary_password), temporary_password);
auth.crc_to_authorize = WriteToHOTPSlot::CommandTransaction::getCRC(hwrite);
Authorize::CommandTransaction::run(stick, auth);
@@ -80,7 +81,7 @@ TEST_CASE("Test HOTP codes according to RFC", "[HOTP]") {
};
for( auto code: codes){
- GetHOTP::CommandTransaction::CommandPayload gh;
+ auto gh = get_payload<GetHOTP>();
gh.slot_number = 0x10;
auto resp = GetHOTP::CommandTransaction::run(stick, gh);
REQUIRE( resp.code == code);