// SPDX-FileCopyrightText: 2022 Linus Jahn // // SPDX-License-Identifier: LGPL-2.1-or-later #ifndef QXMPPFILEENCRYPTION_H #define QXMPPFILEENCRYPTION_H #include "QXmppGlobal.h" #include #include namespace QCA { class Cipher; class Initializer; } // namespace QCA namespace QXmpp::Private::Encryption { enum Direction { Encode, Decode, }; QXMPP_EXPORT QByteArray process(const QByteArray &data, Cipher cipherConfig, Direction direction, const QByteArray &key, const QByteArray &iv); QXMPP_EXPORT QByteArray generateKey(Cipher cipher); QXMPP_EXPORT QByteArray generateInitializationVector(Cipher); // export for tests class QXMPP_EXPORT EncryptionDevice : public QIODevice { public: EncryptionDevice(std::unique_ptr input, Cipher config, const QByteArray &key, const QByteArray &iv); ~EncryptionDevice() override; bool open(QIODevice::OpenMode mode) override; void close() override; bool isSequential() const override; qint64 size() const override; qint64 readData(char *data, qint64 maxlen) override; qint64 writeData(const char *data, qint64 len) override; bool atEnd() const override; private: Cipher m_cipherConfig; bool m_finalized = false; std::vector m_outputBuffer; std::unique_ptr m_input; std::unique_ptr m_cipher; }; class QXMPP_EXPORT DecryptionDevice : public QIODevice { public: DecryptionDevice(std::unique_ptr output, Cipher config, const QByteArray &key, const QByteArray &iv); ~DecryptionDevice() override; bool open(QIODevice::OpenMode mode) override; void close() override; bool isSequential() const override; qint64 size() const override; qint64 readData(char *data, qint64 maxlen) override; qint64 writeData(const char *data, qint64 len) override; private: Cipher m_cipherConfig; std::vector m_outputBuffer; std::unique_ptr m_output; std::unique_ptr m_cipher; }; } // namespace QXmpp::Private::Encryption #endif // QXMPPFILEENCRYPTION_H