2019-06-24 22:01:18 +08:00
|
|
|
/*
|
|
|
|
Copyright © 2019 by The qTox Project Contributors
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-30 00:09:20 +08:00
|
|
|
#include "toxpk.h"
|
|
|
|
|
|
|
|
#include <tox/tox.h>
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QString>
|
|
|
|
|
2019-04-12 04:38:37 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
2016-12-30 00:09:20 +08:00
|
|
|
/**
|
|
|
|
* @class ToxPk
|
|
|
|
* @brief This class represents a Tox Public Key, which is a part of Tox ID.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The default constructor. Creates an empty Tox key.
|
|
|
|
*/
|
|
|
|
ToxPk::ToxPk()
|
2019-04-12 04:38:37 +08:00
|
|
|
: ContactId()
|
2017-02-26 19:52:45 +08:00
|
|
|
{
|
|
|
|
}
|
2016-12-30 00:09:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The copy constructor.
|
2016-12-30 06:14:48 +08:00
|
|
|
* @param other ToxPk to copy
|
2016-12-30 00:09:20 +08:00
|
|
|
*/
|
|
|
|
ToxPk::ToxPk(const ToxPk& other)
|
2019-04-12 04:38:37 +08:00
|
|
|
: ContactId(other.id)
|
2017-02-26 19:52:45 +08:00
|
|
|
{
|
|
|
|
}
|
2016-12-30 00:09:20 +08:00
|
|
|
|
|
|
|
/**
|
2016-12-30 06:14:48 +08:00
|
|
|
* @brief Constructs a ToxPk from bytes.
|
|
|
|
* @param rawId The bytes to construct the ToxPk from. The lenght must be exactly
|
|
|
|
* TOX_PUBLIC_KEY_SIZE, else the ToxPk will be empty.
|
2016-12-30 00:09:20 +08:00
|
|
|
*/
|
|
|
|
ToxPk::ToxPk(const QByteArray& rawId)
|
2019-04-12 04:38:37 +08:00
|
|
|
: ContactId([rawId](){
|
|
|
|
assert(rawId.length() == TOX_PUBLIC_KEY_SIZE);
|
|
|
|
return rawId;}())
|
2016-12-30 00:09:20 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-30 06:14:48 +08:00
|
|
|
* @brief Constructs a ToxPk from bytes.
|
|
|
|
* @param rawId The bytes to construct the ToxPk from, will read exactly
|
2016-12-30 00:09:20 +08:00
|
|
|
* TOX_PUBLIC_KEY_SIZE from the specified buffer.
|
|
|
|
*/
|
|
|
|
ToxPk::ToxPk(const uint8_t* rawId)
|
2019-04-12 04:38:37 +08:00
|
|
|
: ContactId(QByteArray(reinterpret_cast<const char*>(rawId), TOX_PUBLIC_KEY_SIZE))
|
2016-12-30 00:09:20 +08:00
|
|
|
{
|
|
|
|
}
|
2017-01-31 14:14:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get size of public key in bytes.
|
|
|
|
* @return Size of public key in bytes.
|
|
|
|
*/
|
2019-04-12 04:38:37 +08:00
|
|
|
int ToxPk::getSize() const
|
2017-01-31 14:14:30 +08:00
|
|
|
{
|
|
|
|
return TOX_PUBLIC_KEY_SIZE;
|
|
|
|
}
|