diff --git a/lib/libelectronic-id b/lib/libelectronic-id index 4d935f1e..421ef7e9 160000 --- a/lib/libelectronic-id +++ b/lib/libelectronic-id @@ -1 +1 @@ -Subproject commit 4d935f1ea6bacf2f3a13c3d8eb759be39ca2e4c0 +Subproject commit 421ef7e9329c950f7570d478dd48d1db44417c93 diff --git a/src/controller/command-handlers/certificatereader.cpp b/src/controller/command-handlers/certificatereader.cpp index 3ef1df10..c2f09293 100644 --- a/src/controller/command-handlers/certificatereader.cpp +++ b/src/controller/command-handlers/certificatereader.cpp @@ -25,7 +25,6 @@ #include "application.hpp" #include "signauthutils.hpp" #include "utils/utils.hpp" -#include "magic_enum/magic_enum.hpp" using namespace electronic_id; @@ -37,9 +36,9 @@ CardCertificateAndPinInfo getCertificateWithStatusAndInfo(const CardInfo::ptr& c { const auto certificateBytes = card->eid().getCertificate(certificateType); - auto certificateDer = QByteArray(reinterpret_cast(certificateBytes.data()), - int(certificateBytes.size())); - auto certificate = QSslCertificate(certificateDer, QSsl::Der); + QByteArray certificateDer(reinterpret_cast(certificateBytes.data()), + int(certificateBytes.size())); + QSslCertificate certificate(certificateDer, QSsl::Der); if (certificate.isNull()) { THROW(SmartCardChangeRequiredError, "Invalid certificate returned by electronic ID " + card->eid().name()); @@ -59,24 +58,23 @@ CardCertificateAndPinInfo getCertificateWithStatusAndInfo(const CardInfo::ptr& c subject = QStringLiteral("%1, %2, %3").arg(surName, givenName, serialNumber); } - auto certInfo = CertificateInfo {certificateType, - certificate.expiryDate() < QDateTime::currentDateTimeUtc(), - certificate.effectiveDate() > QDateTime::currentDateTimeUtc(), - subject, - certificate.issuerInfo(QSslCertificate::CommonName).join(' '), - certificate.effectiveDate().date().toString(Qt::ISODate), - certificate.expiryDate().date().toString(Qt::ISODate)}; - auto pinInfo = - PinInfo {certificateType.isAuthentication() ? card->eid().authPinMinMaxLength() - : card->eid().signingPinMinMaxLength(), - certificateType.isAuthentication() ? card->eid().authPinRetriesLeft() - : card->eid().signingPinRetriesLeft(), - card->eid().smartcard().readerHasPinPad()}; + CertificateInfo certInfo {certificateType, + certificate.expiryDate() < QDateTime::currentDateTimeUtc(), + certificate.effectiveDate() > QDateTime::currentDateTimeUtc(), + std::move(subject), + certificate.issuerInfo(QSslCertificate::CommonName).join(' '), + certificate.effectiveDate().date().toString(Qt::ISODate), + certificate.expiryDate().date().toString(Qt::ISODate)}; + PinInfo pinInfo {certificateType.isAuthentication() ? card->eid().authPinMinMaxLength() + : card->eid().signingPinMinMaxLength(), + certificateType.isAuthentication() ? card->eid().authPinRetriesLeft() + : card->eid().signingPinRetriesLeft(), + card->eid().smartcard().readerHasPinPad()}; if (pinInfo.pinRetriesCount.first == 0) { pinInfo.pinIsBlocked = true; } - return {card, certificateDer, certificate, std::move(certInfo), std::move(pinInfo)}; + return {card, std::move(certificateDer), certificate, std::move(certInfo), std::move(pinInfo)}; } } // namespace diff --git a/src/ui/certificatewidget.cpp b/src/ui/certificatewidget.cpp index 0e07066c..9f2169ae 100644 --- a/src/ui/certificatewidget.cpp +++ b/src/ui/certificatewidget.cpp @@ -164,7 +164,7 @@ bool CertificateButton::eventFilter(QObject* object, QEvent* event) void CertificateButton::setCertificateInfo(const CardCertificateAndPinInfo& cardCertPinInfo) { CertificateWidgetInfo::setCertificateInfo(cardCertPinInfo); - const auto certInfo = cardCertPinInfo.certInfo; + const auto &certInfo = cardCertPinInfo.certInfo; setText( tr("%1 Issuer: %2 Valid: %3 to %4") .arg(certInfo.subject, certInfo.issuer, certInfo.effectiveDate, certInfo.expiryDate)); diff --git a/src/ui/webeiddialog.cpp b/src/ui/webeiddialog.cpp index f41f010f..a3924d3a 100644 --- a/src/ui/webeiddialog.cpp +++ b/src/ui/webeiddialog.cpp @@ -85,8 +85,9 @@ WebEidDialog::WebEidDialog(QWidget* parent) : WebEidUI(parent), ui(new Private) setWindowFlag(Qt::CustomizeWindowHint); setWindowFlag(Qt::WindowTitleHint); setWindowTitle(QApplication::applicationDisplayName()); - setTrText(ui->aboutVersion, - [] { return tr("Version: %1").arg(QApplication::applicationVersion()); }); + setTrText(ui->aboutVersion, []() -> QString { + return tr("Version: %1").arg(QApplication::applicationVersion()); + }); ui->langButton = new QToolButton(this); ui->langButton->setObjectName("langButton"); @@ -255,7 +256,7 @@ void WebEidDialog::showAboutPage() void WebEidDialog::showFatalErrorPage() { auto* d = new WebEidDialog(); - d->setTrText(d->ui->messagePageTitleLabel, [] { return tr("Operation failed"); }); + d->setTrText(d->ui->messagePageTitleLabel, []() -> QString { return tr("Operation failed"); }); d->ui->fatalError->show(); d->ui->fatalHelp->show(); d->ui->connectCardLabel->hide(); @@ -289,10 +290,12 @@ void WebEidDialog::onSmartCardStatusUpdate(const RetriableError status) { currentCommand = CommandType::INSERT_CARD; - setTrText(ui->connectCardLabel, - [status] { return std::get<0>(retriableErrorToTextTitleAndIcon(status)); }); - setTrText(ui->messagePageTitleLabel, - [status] { return std::get<1>(retriableErrorToTextTitleAndIcon(status)); }); + setTrText(ui->connectCardLabel, [status]() -> QString { + return std::get<0>(retriableErrorToTextTitleAndIcon(status)); + }); + setTrText(ui->messagePageTitleLabel, [status]() -> QString { + return std::get<1>(retriableErrorToTextTitleAndIcon(status)); + }); ui->cardChipIcon->setPixmap(std::get<2>(retriableErrorToTextTitleAndIcon(status))); // In case the insert card page is not shown, switch back to it. @@ -375,12 +378,12 @@ void WebEidDialog::onSingleCertificateReady(const QUrl& origin, return; case CommandType::AUTHENTICATE: ui->pinInputCertificateInfo->setCertificateInfo(certAndPin); - setTrText(ui->pinInputPageTitleLabel, [] { return tr("Authenticate"); }); - setTrText(ui->pinInputDescriptionLabel, [] { + setTrText(ui->pinInputPageTitleLabel, []() -> QString { return tr("Authenticate"); }); + setTrText(ui->pinInputDescriptionLabel, []() -> QString { return tr("By authenticating, I agree to the transfer of my name and personal " "identification code to the service provider."); }); - setTrText(ui->pinTitleLabel, [useExternalPinDialog] { + setTrText(ui->pinTitleLabel, [useExternalPinDialog]() -> QString { return useExternalPinDialog ? tr("Please enter PIN for authentication in the PIN dialog window that opens.") : tr("Enter PIN1 for authentication"); @@ -388,12 +391,12 @@ void WebEidDialog::onSingleCertificateReady(const QUrl& origin, break; case CommandType::SIGN: ui->pinInputCertificateInfo->setCertificateInfo(certAndPin); - setTrText(ui->pinInputPageTitleLabel, [] { return tr("Signing"); }); - setTrText(ui->pinInputDescriptionLabel, [] { + setTrText(ui->pinInputPageTitleLabel, []() -> QString { return tr("Signing"); }); + setTrText(ui->pinInputDescriptionLabel, []() -> QString { return tr("By signing, I agree to the transfer of my name and personal identification " "code to the service provider."); }); - setTrText(ui->pinTitleLabel, [useExternalPinDialog] { + setTrText(ui->pinTitleLabel, [useExternalPinDialog]() -> QString { return useExternalPinDialog ? tr("Please enter PIN for signing in the PIN dialog window that opens.") : tr("Enter PIN2 for signing"); @@ -443,7 +446,7 @@ void WebEidDialog::onVerifyPinFailed(const VerifyPinFailed::Status status, const // FIXME: don't allow retry in case of UNKNOWN_ERROR switch (status) { case Status::RETRY_ALLOWED: - message = [retriesLeft] { + message = [retriesLeft]() -> QString { return retriesLeft == -1 ? tr("Incorrect PIN.") : tr("Incorrect PIN, %n attempts left.", nullptr, retriesLeft); }; @@ -516,9 +519,9 @@ template void WebEidDialog::onRetryImpl(Text text) { setTrText(ui->connectCardLabel, std::forward(text)); - setTrText(ui->messagePageTitleLabel, [] { return tr("Operation failed"); }); + setTrText(ui->messagePageTitleLabel, []() -> QString { return tr("Operation failed"); }); ui->cardChipIcon->setPixmap(pixmap("no-id-card"_L1)); - setupOK([this] { emit retry(); }, [] { return tr("Try again"); }, true); + setupOK([this] { emit retry(); }, []() -> QString { return tr("Try again"); }, true); ui->pageStack->setCurrentIndex(int(Page::ALERT)); } @@ -534,7 +537,7 @@ void WebEidDialog::setTrText(QWidget* label, Text text) const void WebEidDialog::connectOkToCachePinAndEmitSelectedCertificate( const CardCertificateAndPinInfo& certAndPin) { - setupOK([this, certAndPin] { + setupOK([this, certAndPin = std::forward(certAndPin)] { ui->pinInput->hide(); ui->pinTitleLabel->hide(); ui->pinErrorLabel->hide(); @@ -585,7 +588,7 @@ void WebEidDialog::setupPinPrompt(const PinInfo& pinInfo) ui->pinErrorLabel->setVisible(showPinError); showPinInputWarning(showPinError); if (showPinError) { - setTrText(ui->pinErrorLabel, [pinInfo] { + setTrText(ui->pinErrorLabel, [pinInfo]() -> QString { return tr("The PIN has been entered incorrectly at least once. %n attempts left.", nullptr, int(pinInfo.pinRetriesCount.first)); }); @@ -602,7 +605,7 @@ void WebEidDialog::setupPinPadProgressBarAndEmitWait(const CardCertificateAndPin ui->selectAnotherCertificate->hide(); ui->pinTimeRemaining->setText( tr("Time remaining: %1").arg(ui->pinEntryTimeoutProgressBar->maximum())); - setTrText(ui->pinTitleLabel, [this] { + setTrText(ui->pinTitleLabel, [this]() -> QString { return tr("Please enter %1 in PinPad reader") .arg(currentCommand == CommandType::AUTHENTICATE ? tr("PIN1 for authentication") : tr("PIN2 for signing")); @@ -629,7 +632,7 @@ void WebEidDialog::setupPinInput(const CardCertificateAndPinInfo& certAndPin) // 4. Special characters // (ASCII 0x20...0x2F, space../ + 0x3A...0x40, :..@ + 0x5B...0x60, [..` + 0x7B...0x7F, {..~). // 5. We additionally allow uppercase and lowercase Unicode letters. - const auto regexpWithOrWithoutLetters = + const auto ®expWithOrWithoutLetters = certAndPin.cardInfo->eid().allowsUsingLettersAndSpecialCharactersInPin() ? QStringLiteral("[0-9 -/:-@[-`{-~\\p{L}]{%1,%2}") : QStringLiteral("[0-9]{%1,%2}"); @@ -650,7 +653,7 @@ void WebEidDialog::setupOK(Func&& func, const std::function& text, bo ui->okButton->show(); ui->okButton->setEnabled(enabled); setTrText( - ui->okButton, text ? text : [] { return tr("Confirm"); }); + ui->okButton, text ? text : []() -> QString { return tr("Confirm"); }); ui->cancelButton->show(); ui->cancelButton->setEnabled(true); ui->helpButton->hide(); @@ -663,7 +666,8 @@ void WebEidDialog::displayPinBlockedError() ui->pinTimeoutTimer->stop(); ui->pinTimeRemaining->hide(); ui->pinEntryTimeoutProgressBar->hide(); - setTrText(ui->pinErrorLabel, [] { return tr("PIN is locked. Unblock and try again."); }); + setTrText(ui->pinErrorLabel, + []() -> QString { return tr("PIN is locked. Unblock and try again."); }); ui->pinErrorLabel->show(); ui->okButton->hide(); ui->cancelButton->setEnabled(true);