Skip to content

Commit

Permalink
code review #1
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored and louib committed Aug 23, 2019
1 parent 682e384 commit d8a0b85
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 18 deletions.
9 changes: 2 additions & 7 deletions src/cli/Utils.cpp
Expand Up @@ -141,17 +141,13 @@ namespace Utils
if (!yubiKeySlot.isEmpty()) {
bool ok = false;
int slot = yubiKeySlot.toInt(&ok, 10);
if (!ok) {
err << QString("Invalid YubiKey slot %1").arg(yubiKeySlot) << endl;
return {};
}
if (slot != 1 && slot != 2) {
if (!ok || (slot != 1 && slot != 2)) {
err << QString("Invalid YubiKey slot %1").arg(yubiKeySlot) << endl;
return {};
}

QString errorMessage;
bool blocking = YubiKey::instance()->isBlocking(slot, errorMessage);
bool blocking = YubiKey::instance()->checkSlotIsBlocking(slot, errorMessage);
if (!errorMessage.isEmpty()) {
err << errorMessage << endl;
return {};
Expand All @@ -161,7 +157,6 @@ namespace Utils
slot,
blocking,
QString("Please touch the button on your YubiKey to unlock " + databaseFilename),
QString("Challenge-response with YubiKey " + QString::number(slot) + " succeeded!!!"),
QString("Failed to unlock " + databaseFilename + " with YubiKey " + QString::number(slot)),
outputDescriptor,
errorDescriptor));
Expand Down
5 changes: 0 additions & 5 deletions src/keys/YkChallengeResponseKeyCLI.cpp
Expand Up @@ -31,15 +31,13 @@ QUuid YkChallengeResponseKeyCLI::UUID("e2be77c0-c810-417a-8437-32f41d00bd1d");
YkChallengeResponseKeyCLI::YkChallengeResponseKeyCLI(int slot,
bool blocking,
QString messageInteraction,
QString messageSuccess,
QString messageFailure,
FILE* outputDescriptor,
FILE* errorDescriptor)
: ChallengeResponseKey(UUID)
, m_slot(slot)
, m_blocking(blocking)
, m_messageInteraction(messageInteraction)
, m_messageSuccess(messageSuccess)
, m_messageFailure(messageFailure)
, m_out(outputDescriptor)
, m_err(errorDescriptor)
Expand Down Expand Up @@ -71,9 +69,6 @@ bool YkChallengeResponseKeyCLI::challenge(const QByteArray& challenge, unsigned
}
YubiKey::ChallengeResult result = YubiKey::instance()->challenge(m_slot, m_blocking, challenge, m_key);
if (result == YubiKey::SUCCESS) {
if (m_blocking) {
out << m_messageSuccess << endl;
}
return true;
}
} while (retries > 0);
Expand Down
2 changes: 0 additions & 2 deletions src/keys/YkChallengeResponseKeyCLI.h
Expand Up @@ -35,7 +35,6 @@ class YkChallengeResponseKeyCLI : public QObject, public ChallengeResponseKey
explicit YkChallengeResponseKeyCLI(int slot,
bool blocking,
QString messageInteraction,
QString messageSuccess,
QString messageFailure,
FILE* outputDescriptor,
FILE* errorDescriptor);
Expand All @@ -49,7 +48,6 @@ class YkChallengeResponseKeyCLI : public QObject, public ChallengeResponseKey
int m_slot;
bool m_blocking;
QString m_messageInteraction;
QString m_messageSuccess;
QString m_messageFailure;
FILE* m_out;
FILE* m_err;
Expand Down
4 changes: 2 additions & 2 deletions src/keys/drivers/YubiKey.cpp
Expand Up @@ -135,7 +135,7 @@ void YubiKey::detect()
// Check slot 1 and 2 for Challenge-Response HMAC capability
for (int i = 1; i <= 2; ++i) {
QString errorMsg;
bool isBlocking = this->isBlocking(i, errorMsg);
bool isBlocking = checkSlotIsBlocking(i, errorMsg);
if (errorMsg.isEmpty()) {
found = true;
emit detected(i, isBlocking);
Expand All @@ -152,7 +152,7 @@ void YubiKey::detect()
}
}

bool YubiKey::isBlocking(int slot, QString& errorMessage)
bool YubiKey::checkSlotIsBlocking(int slot, QString& errorMessage)
{
if (!init()) {
errorMessage = QString("Could not initialize YubiKey.");
Expand Down
2 changes: 1 addition & 1 deletion src/keys/drivers/YubiKey.h
Expand Up @@ -96,7 +96,7 @@ class YubiKey : public QObject
*
* @return whether the key is blocking or not.
*/
bool isBlocking(int slot, QString& errorMessage);
bool checkSlotIsBlocking(int slot, QString& errorMessage);
signals:
/** Emitted in response to detect() when a device is found
*
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCli.cpp
Expand Up @@ -1348,7 +1348,7 @@ void TestCli::testYubiKeyOption()
}

QString errorMessage;
bool isBlocking = YubiKey::instance()->isBlocking(2, errorMessage);
bool isBlocking = YubiKey::instance()->checkSlotIsBlocking(2, errorMessage);
if (isBlocking && errorMessage.isEmpty()) {
QSKIP("Skipping YubiKey in press mode.");
}
Expand Down

0 comments on commit d8a0b85

Please sign in to comment.