From 9892ae74c8e828d163e797b9a309972bbe8ef367 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 31 Mar 2017 13:42:29 +0200 Subject: Do not allow to set delays lower than 20 ms Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index eeda537..40e166e 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -70,11 +70,18 @@ namespace nitrokey{ } bool NitrokeyManager::set_current_device_speed(int retry_delay, int send_receive_delay){ + if (retry_delay < 20 || send_receive_delay < 20){ + LOG("Delay set too low: " + to_string(retry_delay) +" "+ to_string(send_receive_delay), Loglevel::WARNING); + return false; + } + std::lock_guard lock(mex_dev_com); - if(device != nullptr){ - device->set_receiving_delay(std::chrono::duration(send_receive_delay)); - device->set_retry_delay(std::chrono::duration(retry_delay)); + if(device == nullptr) { + return false; } + device->set_receiving_delay(std::chrono::duration(send_receive_delay)); + device->set_retry_delay(std::chrono::duration(retry_delay)); + return true; } bool NitrokeyManager::connect() { @@ -89,7 +96,12 @@ namespace nitrokey{ } bool NitrokeyManager::set_default_commands_delay(int delay){ + if (delay < 20){ + LOG("Delay set too low: " + to_string(delay), Loglevel::WARNING); + return false; + } Device::set_default_device_speed(delay); + return true; } bool NitrokeyManager::connect(const char *device_model) { -- cgit v1.2.3