From f5c0d61ae6cda2106c9d88ef7050b4003e725489 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Tue, 31 Jan 2017 09:14:30 +0300 Subject: [PATCH] feat(toxpk): Add 'ToxPk::getPkSize()' method --- src/core/toxpk.cpp | 13 +++++++++++-- src/core/toxpk.h | 1 + test/core/toxpk_test.cpp | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/toxpk.cpp b/src/core/toxpk.cpp index ccfb53f8c..c368ce384 100644 --- a/src/core/toxpk.cpp +++ b/src/core/toxpk.cpp @@ -83,8 +83,8 @@ QString ToxPk::toString() const /** * @brief Returns a pointer to the raw key data. - * @return Pointer to the raw key data, which is exactly TOX_PUBLIC_KEY_SIZE bytes - * long. Returns a nullptr if the ToxPk is empty. + * @return Pointer to the raw key data, which is exactly `ToxPk::getPkSize()` + * bytes long. Returns a nullptr if the ToxPk is empty. */ const uint8_t* ToxPk::getBytes() const { @@ -113,3 +113,12 @@ bool ToxPk::isEmpty() const { 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; +} diff --git a/src/core/toxpk.h b/src/core/toxpk.h index 67c63e498..b2265eda0 100644 --- a/src/core/toxpk.h +++ b/src/core/toxpk.h @@ -20,6 +20,7 @@ public: const uint8_t* getBytes() const; bool isEmpty() const; + static int getPkSize(); private: QByteArray key; }; diff --git a/test/core/toxpk_test.cpp b/test/core/toxpk_test.cpp index 415e09d19..1f9747dc4 100644 --- a/test/core/toxpk_test.cpp +++ b/test/core/toxpk_test.cpp @@ -58,7 +58,7 @@ START_TEST(publicKeyTest) { ToxPk pk(testPk); 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]); } }