1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat(toxpk): Add 'ToxPk::getPkSize()' method

This commit is contained in:
Diadlo 2017-01-31 09:14:30 +03:00
parent d351f9e5ec
commit f5c0d61ae6
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
3 changed files with 13 additions and 3 deletions

View File

@ -83,8 +83,8 @@ QString ToxPk::toString() const
/** /**
* @brief Returns a pointer to the raw key data. * @brief Returns a pointer to the raw key data.
* @return Pointer to the raw key data, which is exactly TOX_PUBLIC_KEY_SIZE bytes * @return Pointer to the raw key data, which is exactly `ToxPk::getPkSize()`
* long. Returns a nullptr if the ToxPk is empty. * bytes long. Returns a nullptr if the ToxPk is empty.
*/ */
const uint8_t* ToxPk::getBytes() const const uint8_t* ToxPk::getBytes() const
{ {
@ -113,3 +113,12 @@ bool ToxPk::isEmpty() const
{ {
return key.isEmpty(); return key.isEmpty();
} }
/**
* @brief Get size of public key in bytes.
* @return Size of public key in bytes.
*/
int ToxPk::getPkSize()
{
return TOX_PUBLIC_KEY_SIZE;
}

View File

@ -20,6 +20,7 @@ public:
const uint8_t* getBytes() const; const uint8_t* getBytes() const;
bool isEmpty() const; bool isEmpty() const;
static int getPkSize();
private: private:
QByteArray key; QByteArray key;
}; };

View File

@ -58,7 +58,7 @@ START_TEST(publicKeyTest)
{ {
ToxPk pk(testPk); ToxPk pk(testPk);
ck_assert(testPk == pk.getKey()); ck_assert(testPk == pk.getKey());
for (int i = 0; i < 32; i++) { for (int i = 0; i < ToxPk::getPkSize(); i++) {
ck_assert(testPkArray[i] == pk.getBytes()[i]); ck_assert(testPkArray[i] == pk.getBytes()[i]);
} }
} }