diff --git a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp --- a/services/tunnelbroker/src/Database/DeviceSessionItem.cpp +++ b/services/tunnelbroker/src/Database/DeviceSessionItem.cpp @@ -1,5 +1,6 @@ #include "DeviceSessionItem.h" #include "ConfigManager.h" +#include "Tools.h" namespace comm { namespace network { @@ -38,8 +39,11 @@ } void DeviceSessionItem::validate() const { - if (!this->sessionID.size()) { - throw std::runtime_error("Error: SessionID is empty."); + if (!validateSessionID(this->sessionID)) { + throw std::runtime_error("Error: SessionID format is wrong."); + } + if (!validateDeviceID(this->deviceID)) { + throw std::runtime_error("Error: DeviceID format is wrong."); } } diff --git a/services/tunnelbroker/src/Database/MessageItem.cpp b/services/tunnelbroker/src/Database/MessageItem.cpp --- a/services/tunnelbroker/src/Database/MessageItem.cpp +++ b/services/tunnelbroker/src/Database/MessageItem.cpp @@ -1,5 +1,6 @@ #include "MessageItem.h" #include "ConfigManager.h" +#include "Tools.h" namespace comm { namespace network { @@ -33,17 +34,11 @@ } void MessageItem::validate() const { - if (!this->messageID.size()) { - throw std::runtime_error("Error: messageID is empty"); + if (!validateDeviceID(this->fromDeviceID)) { + throw std::runtime_error("Error: fromDeviceID format is wrong"); } - if (!this->fromDeviceID.size()) { - throw std::runtime_error("Error: fromDeviceID is empty"); - } - if (!this->toDeviceID.size()) { - throw std::runtime_error("Error: toDeviceID is empty"); - } - if (!this->expire == 0) { - throw std::runtime_error("Error: expire field not provided"); + if (!validateDeviceID(this->toDeviceID)) { + throw std::runtime_error("Error: toDeviceID format is wrong"); } } diff --git a/services/tunnelbroker/src/Database/PublicKeyItem.cpp b/services/tunnelbroker/src/Database/PublicKeyItem.cpp --- a/services/tunnelbroker/src/Database/PublicKeyItem.cpp +++ b/services/tunnelbroker/src/Database/PublicKeyItem.cpp @@ -1,5 +1,6 @@ #include "PublicKeyItem.h" #include "ConfigManager.h" +#include "Tools.h" namespace comm { namespace network { @@ -20,8 +21,8 @@ } void PublicKeyItem::validate() const { - if (!this->deviceID.size()) { - throw std::runtime_error("Error: DeviceID is empty"); + if (!validateDeviceID(this->deviceID)) { + throw std::runtime_error("Error: DeviceID format is wrong"); } if (!this->publicKey.size()) { throw std::runtime_error("Error: PublicKey is empty"); diff --git a/services/tunnelbroker/src/Database/SessionSignItem.cpp b/services/tunnelbroker/src/Database/SessionSignItem.cpp --- a/services/tunnelbroker/src/Database/SessionSignItem.cpp +++ b/services/tunnelbroker/src/Database/SessionSignItem.cpp @@ -1,5 +1,6 @@ #include "SessionSignItem.h" #include "ConfigManager.h" +#include "Tools.h" namespace comm { namespace network { @@ -22,8 +23,8 @@ } void SessionSignItem::validate() const { - if (!this->deviceID.size()) { - throw std::runtime_error("Error: DeviceID is empty"); + if (!validateDeviceID(this->deviceID)) { + throw std::runtime_error("Error: DeviceID format is wrong"); } if (!this->sign.size()) { throw std::runtime_error("Error: Sign is empty");