qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
toxid.h
Go to the documentation of this file.
1 /*
2  Copyright © 2015-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 
21 #pragma once
22 
23 #include "toxpk.h"
24 
25 #include <QByteArray>
26 #include <QString>
27 #include <cstdint>
28 
29 class ToxId
30 {
31 public:
32  ToxId();
33  ToxId(const ToxId& other);
34  explicit ToxId(const QString& id);
35  explicit ToxId(const QByteArray& rawId);
36  explicit ToxId(const uint8_t* rawId, int len);
37  ToxId& operator=(const ToxId& other) = default;
38  ToxId& operator=(ToxId&& other) = default;
39 
40  bool operator==(const ToxId& other) const;
41  bool operator!=(const ToxId& other) const;
42  QString toString() const;
43  void clear();
44  bool isValid() const;
45 
46  static bool isValidToxId(const QString& id);
47  static bool isToxId(const QString& id);
48  const uint8_t* getBytes() const;
49  QByteArray getToxId() const;
50  ToxPk getPublicKey() const;
51  QString getNoSpamString() const;
52 
53 private:
54  void constructToxId(const QByteArray& rawId);
55 
56 public:
57  static const QRegularExpression ToxIdRegEx;
58 
59 private:
60  QByteArray toxId;
61 };
ToxId::operator!=
bool operator!=(const ToxId &other) const
Compares the inequality of the Public Key.
Definition: toxid.cpp:150
ToxId::toString
QString toString() const
Returns the Tox ID converted to QString. Is equal to getPublicKey() if the Tox ID was constructed fro...
Definition: toxid.cpp:160
ToxId::getToxId
QByteArray getToxId() const
ToxId::getNoSpamString
QString getNoSpamString() const
Returns the NoSpam value converted to QString.
Definition: toxid.cpp:204
ToxId::operator=
ToxId & operator=(const ToxId &other)=default
ToxId::constructToxId
void constructToxId(const QByteArray &rawId)
Definition: toxid.cpp:125
ToxId::clear
void clear()
Clears all elements of the Tox ID.
Definition: toxid.cpp:168
ToxId::ToxIdRegEx
static const QRegularExpression ToxIdRegEx
Definition: toxid.h:57
ToxId::isValid
bool isValid() const
Check it it's a valid Tox ID by verifying the checksum.
Definition: toxid.cpp:239
ToxId::getBytes
const uint8_t * getBytes() const
Gets the ToxID as bytes, convenience function for toxcore interface.
Definition: toxid.cpp:177
ToxId::ToxId
ToxId()
The default constructor. Creates an empty Tox ID.
Definition: toxid.cpp:62
toxpk.h
ToxId::isToxId
static bool isToxId(const QString &id)
Check, that id is probably a valid Tox ID.
Definition: toxid.cpp:230
ToxId::getPublicKey
ToxPk getPublicKey() const
Gets the Public Key part of the ToxID.
Definition: toxid.cpp:190
ToxPk
This class represents a Tox Public Key, which is a part of Tox ID.
Definition: toxpk.h:26
ToxId::toxId
QByteArray toxId
Definition: toxid.h:60
ToxId
This class represents a Tox ID.
Definition: toxid.h:29
ToxId::operator==
bool operator==(const ToxId &other) const
Compares the equality of the Public Key.
Definition: toxid.cpp:140
ToxId::isValidToxId
static bool isValidToxId(const QString &id)
Check, that id is a valid Tox ID.
Definition: toxid.cpp:219