Use better variable names

This commit is contained in:
Janek Bevendorff 2017-02-24 01:06:09 +01:00
parent 70816f90b2
commit 44ac7d152b
No known key found for this signature in database
GPG key ID: CFEC2F6850BFFA53
2 changed files with 15 additions and 17 deletions

View file

@ -111,7 +111,7 @@ void YubiKey::detect()
emit alreadyRunning(); emit alreadyRunning();
return; return;
} else if (result != YubiKey::ERROR) { } else if (result != YubiKey::ERROR) {
emit detected(i, result == YubiKey::WOULDBLOCK ? true : false); emit detected(i, result == YubiKey::WOULDBLOCK);
return; return;
} }
} }
@ -143,14 +143,14 @@ static inline QString printByteArray(const QByteArray& a)
} }
#endif #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()) { if (!m_mutex.tryLock()) {
return ALREADY_RUNNING; return ALREADY_RUNNING;
} }
int yk_cmd = (slot == 1) ? SLOT_CHAL_HMAC1 : SLOT_CHAL_HMAC2; int yk_cmd = (slot == 1) ? SLOT_CHAL_HMAC1 : SLOT_CHAL_HMAC2;
QByteArray paddedChal = chal; QByteArray paddedChallenge = challenge;
// ensure that YubiKey::init() succeeded // ensure that YubiKey::init() succeeded
if (m_yk == NULL) { 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 */ // 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 /* The challenge sent to the yubikey should always be 64 bytes for
* compatibility with all configurations. Follow PKCS7 padding. * 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 * There is some question whether or not 64 byte fixed length
* configurations even work, some docs say avoid it. * configurations even work, some docs say avoid it.
*/ */
const int padLen = 64 - paddedChal.size(); const int padLen = 64 - paddedChallenge.size();
if (padLen > 0) { if (padLen > 0) {
paddedChal.append(QByteArray(padLen, padLen)); paddedChallenge.append(QByteArray(padLen, padLen));
} }
const unsigned char *c; const unsigned char *c;
unsigned char *r; unsigned char *r;
c = reinterpret_cast<const unsigned char*>(paddedChal.constData()); c = reinterpret_cast<const unsigned char*>(paddedChallenge.constData());
r = reinterpret_cast<unsigned char*>(resp.data()); r = reinterpret_cast<unsigned char*>(response.data());
#ifdef QT_DEBUG #ifdef QT_DEBUG
qDebug().nospace() << __func__ << "(" << slot << ") c = " << printByteArray(paddedChal); qDebug().nospace() << __func__ << "(" << slot << ") c = " << printByteArray(paddedChallenge);
#endif #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(); 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 // actual HMAC-SHA1 response is only 20 bytes
resp.resize(20); response.resize(20);
#ifdef QT_DEBUG #ifdef QT_DEBUG
qDebug().nospace() << __func__ << "(" << slot << ") r = " << printByteArray(resp) << ", ret = " << ret; qDebug().nospace() << __func__ << "(" << slot << ") r = " << printByteArray(response) << ", ret = " << ret;
#endif #endif
return SUCCESS; return SUCCESS;

View file

@ -59,13 +59,11 @@ public:
* *
* @param slot YubiKey configuration slot * @param slot YubiKey configuration slot
* @param mayBlock operation is allowed to block * @param mayBlock operation is allowed to block
* @param chal challenge input to YubiKey * @param challenge challenge input to YubiKey
* @param resp response output from YubiKey * @param response response output from YubiKey
* @return true on success * @return true on success
*/ */
ChallengeResult challenge(int slot, bool mayBlock, ChallengeResult challenge(int slot, bool mayBlock, const QByteArray& challenge, QByteArray& response);
const QByteArray& chal,
QByteArray& resp);
/** /**
* @brief YubiKey::getSerial - serial number of YubiKey * @brief YubiKey::getSerial - serial number of YubiKey