From 44ac7d152b4024c2355cb83c09ce3bf41491f0bf Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Fri, 24 Feb 2017 01:06:09 +0100 Subject: [PATCH] Use better variable names --- src/keys/drivers/YubiKey.cpp | 24 ++++++++++++------------ src/keys/drivers/YubiKey.h | 8 +++----- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/keys/drivers/YubiKey.cpp b/src/keys/drivers/YubiKey.cpp index 1d4445cd6..e68949394 100644 --- a/src/keys/drivers/YubiKey.cpp +++ b/src/keys/drivers/YubiKey.cpp @@ -111,7 +111,7 @@ void YubiKey::detect() emit alreadyRunning(); return; } else if (result != YubiKey::ERROR) { - emit detected(i, result == YubiKey::WOULDBLOCK ? true : false); + emit detected(i, result == YubiKey::WOULDBLOCK); return; } } @@ -143,14 +143,14 @@ static inline QString printByteArray(const QByteArray& a) } #endif -YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByteArray& chal, QByteArray& resp) +YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByteArray& challenge, QByteArray& response) { if (!m_mutex.tryLock()) { return ALREADY_RUNNING; } int yk_cmd = (slot == 1) ? SLOT_CHAL_HMAC1 : SLOT_CHAL_HMAC2; - QByteArray paddedChal = chal; + QByteArray paddedChallenge = challenge; // ensure that YubiKey::init() succeeded if (m_yk == NULL) { @@ -159,7 +159,7 @@ YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByte } // yk_challenge_response() insists on 64 byte response buffer */ - resp.resize(64); + response.resize(64); /* The challenge sent to the yubikey should always be 64 bytes for * compatibility with all configurations. Follow PKCS7 padding. @@ -167,21 +167,21 @@ YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByte * There is some question whether or not 64 byte fixed length * configurations even work, some docs say avoid it. */ - const int padLen = 64 - paddedChal.size(); + const int padLen = 64 - paddedChallenge.size(); if (padLen > 0) { - paddedChal.append(QByteArray(padLen, padLen)); + paddedChallenge.append(QByteArray(padLen, padLen)); } const unsigned char *c; unsigned char *r; - c = reinterpret_cast(paddedChal.constData()); - r = reinterpret_cast(resp.data()); + c = reinterpret_cast(paddedChallenge.constData()); + r = reinterpret_cast(response.data()); #ifdef QT_DEBUG - qDebug().nospace() << __func__ << "(" << slot << ") c = " << printByteArray(paddedChal); + qDebug().nospace() << __func__ << "(" << slot << ") c = " << printByteArray(paddedChallenge); #endif - int ret = yk_challenge_response(m_yk, yk_cmd, mayBlock, paddedChal.size(), c, resp.size(), r); + int ret = yk_challenge_response(m_yk, yk_cmd, mayBlock, paddedChallenge.size(), c, response.size(), r); m_mutex.unlock(); @@ -209,10 +209,10 @@ YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByte } // actual HMAC-SHA1 response is only 20 bytes - resp.resize(20); + response.resize(20); #ifdef QT_DEBUG - qDebug().nospace() << __func__ << "(" << slot << ") r = " << printByteArray(resp) << ", ret = " << ret; + qDebug().nospace() << __func__ << "(" << slot << ") r = " << printByteArray(response) << ", ret = " << ret; #endif return SUCCESS; diff --git a/src/keys/drivers/YubiKey.h b/src/keys/drivers/YubiKey.h index 6c3504ed1..2382b69cf 100644 --- a/src/keys/drivers/YubiKey.h +++ b/src/keys/drivers/YubiKey.h @@ -59,13 +59,11 @@ public: * * @param slot YubiKey configuration slot * @param mayBlock operation is allowed to block - * @param chal challenge input to YubiKey - * @param resp response output from YubiKey + * @param challenge challenge input to YubiKey + * @param response response output from YubiKey * @return true on success */ - ChallengeResult challenge(int slot, bool mayBlock, - const QByteArray& chal, - QByteArray& resp); + ChallengeResult challenge(int slot, bool mayBlock, const QByteArray& challenge, QByteArray& response); /** * @brief YubiKey::getSerial - serial number of YubiKey