/*! \file piethutilbase.h * \ingroup IO-Utils * \~\brief * \~english Base helper for optional crypt layer in IO-Utils transports * \~russian Базовый помощник для необязательного слоя шифрования в транспортах IO-Utils */ /* PIP - Platform Independent Primitives Base class for ethernet utils Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef PIETHUTILBASE_H #define PIETHUTILBASE_H #include "pibytearray.h" #include "pip_io_utils_export.h" //! \ingroup IO-Utils //! \~\brief //! \~english Base helper that adds optional packet encryption to transport utilities. //! \~russian Базовый помощник, добавляющий необязательное шифрование пакетов в транспортные утилиты. class PIP_IO_UTILS_EXPORT PIEthUtilBase { public: //! \~english Constructs helper with crypt layer disabled. //! \~russian Создает помощник с выключенным слоем шифрования. PIEthUtilBase(); //! \~english Destroys the crypt helper. //! \~russian Уничтожает помощник шифрования. ~PIEthUtilBase(); //! \~english Enables or disables the crypt layer. //! \~russian Включает или выключает слой шифрования. void setCryptEnabled(bool on); //! \~english Enables the crypt layer. //! \~russian Включает слой шифрования. void cryptEnable(); //! \~english Disables the crypt layer. //! \~russian Выключает слой шифрования. void cryptDisable(); //! \~english Returns whether the crypt layer is enabled. //! \~russian Возвращает, включен ли слой шифрования. bool isCryptEnabled() const; //! \~english Sets crypt key "k" and enables the crypt layer. //! \~russian Устанавливает ключ шифрования "k" и включает слой шифрования. void setCryptKey(const PIByteArray & k); //! \~english Generates crypt key from passphrase "k" and enables the crypt layer. //! \~russian Генерирует ключ шифрования из парольной фразы "k" и включает слой шифрования. void createCryptKey(const PIString & k); //! \~english Returns current crypt key. //! \~russian Возвращает текущий ключ шифрования. PIByteArray cryptKey() const; //! \~english Returns extra size added by encryption. //! \~russian Возвращает дополнительный размер, добавляемый шифрованием. static size_t cryptSizeAddition(); protected: //! \~english Encrypts "data" when the crypt layer is enabled. //! \~russian Шифрует "data", если слой шифрования включен. PIByteArray cryptData(const PIByteArray & data); //! \~english Decrypts "data" when the crypt layer is enabled. //! \~russian Дешифрует "data", если слой шифрования включен. //! \~\details //! \~english Returns empty %PIByteArray when decryption fails. //! \~russian Возвращает пустой %PIByteArray, если дешифрование не удалось. PIByteArray decryptData(const PIByteArray & data); private: PIByteArray _key; bool _crypt; }; #endif // PIETHUTILBASE_H