aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-03-31 13:42:29 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2017-03-31 14:20:57 +0200
commit9892ae74c8e828d163e797b9a309972bbe8ef367 (patch)
tree23c5010cfa0b305699a60a1274db6c673540147a /NitrokeyManager.cc
parent55af5c07a45a0b51c2f7bbe487862f8781ab9c56 (diff)
downloadlibnitrokey-9892ae74c8e828d163e797b9a309972bbe8ef367.tar.gz
libnitrokey-9892ae74c8e828d163e797b9a309972bbe8ef367.tar.bz2
Do not allow to set delays lower than 20 ms
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc18
1 files 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<std::mutex> lock(mex_dev_com);
- if(device != nullptr){
- device->set_receiving_delay(std::chrono::duration<int, std::milli>(send_receive_delay));
- device->set_retry_delay(std::chrono::duration<int, std::milli>(retry_delay));
+ if(device == nullptr) {
+ return false;
}
+ device->set_receiving_delay(std::chrono::duration<int, std::milli>(send_receive_delay));
+ device->set_retry_delay(std::chrono::duration<int, std::milli>(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) {