Skip to content

Commit 3e0b949

Browse files
committed
Extract OTP constants into defines
This patch extracts the HOTP and TOTP slot count as well as the maximum length for the OTP slot name and secret into defines in device_proto.h, similar to the PWS constants.
1 parent 6401ca4 commit 3e0b949

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

NitrokeyManager.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ using nitrokey::misc::strcpyT;
470470
}
471471

472472
bool NitrokeyManager::is_internal_hotp_slot_number(uint8_t slot_number) const { return slot_number < 0x20; }
473-
bool NitrokeyManager::is_valid_hotp_slot_number(uint8_t slot_number) const { return slot_number < 3; }
474-
bool NitrokeyManager::is_valid_totp_slot_number(uint8_t slot_number) const { return slot_number < 0x10-1; } //15
473+
bool NitrokeyManager::is_valid_hotp_slot_number(uint8_t slot_number) const { return slot_number < HOTP_SLOT_COUNT; }
474+
bool NitrokeyManager::is_valid_totp_slot_number(uint8_t slot_number) const { return slot_number < TOTP_SLOT_COUNT; }
475475
uint8_t NitrokeyManager::get_internal_slot_number_for_totp(uint8_t slot_number) const { return (uint8_t) (0x20 + slot_number); }
476476
uint8_t NitrokeyManager::get_internal_slot_number_for_hotp(uint8_t slot_number) const { return (uint8_t) (0x10 + slot_number); }
477477

@@ -636,9 +636,8 @@ using nitrokey::misc::strcpyT;
636636
payload2.id = 0;
637637
auto secret_bin = misc::hex_string_to_byte(secret);
638638
auto remaining_secret_length = secret_bin.size();
639-
const auto maximum_OTP_secret_size = 40;
640-
if(remaining_secret_length > maximum_OTP_secret_size){
641-
throw TargetBufferSmallerThanSource(remaining_secret_length, maximum_OTP_secret_size);
639+
if(remaining_secret_length > OTP_SECRET_LENGTH){
640+
throw TargetBufferSmallerThanSource(remaining_secret_length, OTP_SECRET_LENGTH);
642641
}
643642

644643
while (remaining_secret_length>0){

libnitrokey/device_proto.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
#define PWS_SEND_TAB 2
5353
#define PWS_SEND_CR 3
5454

55+
#define HOTP_SLOT_COUNT 3
56+
#define TOTP_SLOT_COUNT 15
57+
#define OTP_SLOTNAME_LENGTH 15
58+
#define OTP_SECRET_LENGTH 40
59+
5560
#include <mutex>
5661
#include "DeviceCommunicationExceptions.h"
5762
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)

0 commit comments

Comments
 (0)