From 2ff57c2eb75f64db39111c6a5a02cf7c1cad87e5 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Fri, 10 Mar 2017 20:42:59 +0100 Subject: [PATCH] Coding style fixes --- src/gui/ChangeMasterKeyWidget.cpp | 13 ++++++++----- src/gui/DatabaseOpenWidget.cpp | 16 +++++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/gui/ChangeMasterKeyWidget.cpp b/src/gui/ChangeMasterKeyWidget.cpp index bb963d3cd..616b0ee01 100644 --- a/src/gui/ChangeMasterKeyWidget.cpp +++ b/src/gui/ChangeMasterKeyWidget.cpp @@ -166,16 +166,18 @@ void ChangeMasterKeyWidget::generateKey() #ifdef WITH_XC_YUBIKEY if (m_ui->challengeResponseGroup->isChecked()) { - int i = m_ui->comboChallengeResponse->currentIndex(); - i = m_ui->comboChallengeResponse->itemData(i).toInt(); + int selectionIndex = m_ui->comboChallengeResponse->currentIndex(); + int comboPayload = m_ui->comboChallengeResponse->itemData(selectionIndex).toInt(); - if (0 == i) { + if (0 == comboPayload) { m_ui->messageWidget->showMessage(tr("Changing master key failed: no YubiKey inserted."), MessageWidget::Error); return; } - bool blocking = i & true; - int slot = i >> 1; + + // read blocking mode from LSB and slot index number from second LSB + bool blocking = comboPayload & 1; + int slot = comboPayload >> 1; auto key = QSharedPointer(new YkChallengeResponseKey(slot, blocking)); m_key.addChallengeResponseKey(key); } @@ -212,6 +214,7 @@ void ChangeMasterKeyWidget::pollYubikey() void ChangeMasterKeyWidget::yubikeyDetected(int slot, bool blocking) { YkChallengeResponseKey yk(slot, blocking); + // add detected YubiKey to combo box and encode blocking mode in LSB, slot number in second LSB m_ui->comboChallengeResponse->addItem(yk.getName(), QVariant((slot << 1) | blocking)); m_ui->comboChallengeResponse->setEnabled(m_ui->challengeResponseGroup->isChecked()); m_ui->buttonRedetectYubikey->setEnabled(m_ui->challengeResponseGroup->isChecked()); diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index 2eebcae3c..f7d432479 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -37,9 +37,9 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent) - : DialogyWidget(parent), - m_ui(new Ui::DatabaseOpenWidget()), - m_db(nullptr) + : DialogyWidget(parent) + , m_ui(new Ui::DatabaseOpenWidget()) + , m_db(nullptr) { m_ui->setupUi(this); @@ -208,11 +208,12 @@ CompositeKey DatabaseOpenWidget::databaseKey() } if (m_ui->checkChallengeResponse->isChecked()) { - int i = m_ui->comboChallengeResponse->currentIndex(); - i = m_ui->comboChallengeResponse->itemData(i).toInt(); + int selectionIndex = m_ui->comboChallengeResponse->currentIndex(); + int comboPayload = m_ui->comboChallengeResponse->itemData(selectionIndex).toInt(); - bool blocking = i & true; - int slot = i >> 1; + // read blocking mode from LSB and slot index number from second LSB + bool blocking = comboPayload & 1; + int slot = comboPayload >> 1; auto key = QSharedPointer(new YkChallengeResponseKey(slot, blocking)); masterKey.addChallengeResponseKey(key); } @@ -267,6 +268,7 @@ void DatabaseOpenWidget::pollYubikey() void DatabaseOpenWidget::yubikeyDetected(int slot, bool blocking) { YkChallengeResponseKey yk(slot, blocking); + // add detected YubiKey to combo box and encode blocking mode in LSB, slot number in second LSB m_ui->comboChallengeResponse->addItem(yk.getName(), QVariant((slot << 1) | blocking)); m_ui->comboChallengeResponse->setEnabled(true); m_ui->checkChallengeResponse->setEnabled(true);