qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
toxencrypt.h
Go to the documentation of this file.
1 /*
2  Copyright © 2017-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <QByteArray>
23 #include <QString>
24 
25 #include <memory>
26 
27 struct Tox_Pass_Key;
28 
30 {
31 public:
32  ~ToxEncrypt();
33  ToxEncrypt() = delete;
34  ToxEncrypt(const ToxEncrypt& other) = delete;
35  ToxEncrypt& operator=(const ToxEncrypt& other) = delete;
36 
37  static int getMinBytes();
38  static bool isEncrypted(const QByteArray& ciphertext);
39  static QByteArray encryptPass(const QString& password, const QByteArray& plaintext);
40  static QByteArray decryptPass(const QString& password, const QByteArray& ciphertext);
41  static std::unique_ptr<ToxEncrypt> makeToxEncrypt(const QString& password);
42  static std::unique_ptr<ToxEncrypt> makeToxEncrypt(const QString& password,
43  const QByteArray& toxSave);
44  QByteArray encrypt(const QByteArray& plaintext) const;
45  QByteArray decrypt(const QByteArray& ciphertext) const;
46 
47 private:
48  explicit ToxEncrypt(Tox_Pass_Key* key);
49 
50 private:
51  Tox_Pass_Key* passKey = nullptr;
52 };
ToxEncrypt::encrypt
QByteArray encrypt(const QByteArray &plaintext) const
Encrypts the plaintext with the stored key.
Definition: toxencrypt.cpp:218
ToxEncrypt::~ToxEncrypt
~ToxEncrypt()
Frees the passKey before destruction.
Definition: toxencrypt.cpp:45
ToxEncrypt::makeToxEncrypt
static std::unique_ptr< ToxEncrypt > makeToxEncrypt(const QString &password)
Factory method for the ToxEncrypt object.
Definition: toxencrypt.cpp:156
ToxEncrypt::decrypt
QByteArray decrypt(const QByteArray &ciphertext) const
Decrypts data encrypted with this module, using the stored key.
Definition: toxencrypt.cpp:245
ToxEncrypt::isEncrypted
static bool isEncrypted(const QByteArray &ciphertext)
Checks if the data was encrypted by this module.
Definition: toxencrypt.cpp:74
ToxEncrypt::getMinBytes
static int getMinBytes()
Gets the minimum number of bytes needed for isEncrypted()
Definition: toxencrypt.cpp:64
ToxEncrypt::decryptPass
static QByteArray decryptPass(const QString &password, const QByteArray &ciphertext)
Decrypts data encrypted with this module.
Definition: toxencrypt.cpp:120
ToxEncrypt
Encapsulates the toxencrypsave API. Since key derivation is work intensive and to avoid storing plain...
Definition: toxencrypt.h:29
ToxEncrypt::encryptPass
static QByteArray encryptPass(const QString &password, const QByteArray &plaintext)
Encrypts the plaintext with the given password.
Definition: toxencrypt.cpp:90
ToxEncrypt::passKey
Tox_Pass_Key * passKey
Definition: toxencrypt.h:51
ToxEncrypt::ToxEncrypt
ToxEncrypt()=delete
ToxEncrypt::operator=
ToxEncrypt & operator=(const ToxEncrypt &other)=delete