diff --git a/client/DigiDoc.cpp b/client/DigiDoc.cpp index c510ad092..092686105 100644 --- a/client/DigiDoc.cpp +++ b/client/DigiDoc.cpp @@ -519,7 +519,7 @@ bool DigiDoc::open( const QString &file ) try { WaitDialogHolder waitDialog(parent, tr("Opening"), false); - waitFor([&] { + return waitFor([&] { b = Container::openPtr(to(file)); if(b && b->mediaType() == "application/vnd.etsi.asic-s+zip" && b->dataFiles().size() == 1) { @@ -548,10 +548,10 @@ bool DigiDoc::open( const QString &file ) isTimeStamped = parentContainer->signatures()[0]->trustedSigningTime().compare("2018-07-01T00:00:00Z") < 0; for(const Signature *signature: b->signatures()) m_signatures.append(DigiDocSignature(signature, this, isTimeStamped)); + qApp->addRecent( file ); + containerState = signatures().isEmpty() ? ContainerState::UnsignedSavedContainer : ContainerState::SignedContainer; + return true; }); - qApp->addRecent( file ); - containerState = signatures().isEmpty() ? ContainerState::UnsignedSavedContainer : ContainerState::SignedContainer; - return true; } catch(const Exception &e) { switch(e.code()) { @@ -602,9 +602,9 @@ void DigiDoc::removeSignature( unsigned int num ) if( !checkDoc( num >= b->signatures().size(), tr("Missing signature") ) ) return; try { - waitFor([this, num] { + modified = waitFor([this, num] { b->removeSignature(num); - modified = true; + return true; }); } catch( const Exception &e ) { setLastError( tr("Failed remove signature from container"), e ); } @@ -626,13 +626,13 @@ bool DigiDoc::saveAs(const QString &filename) { try { - waitFor([&]{ + return waitFor([&]{ if(parentContainer) parentContainer->save(to(filename)); else b->save(to(filename)); + return true; }); - return true; } catch( const Exception &e ) { QFile::remove(filename); diff --git a/client/QSigner.cpp b/client/QSigner.cpp index b48f768be..c220a9ff5 100644 --- a/client/QSigner.cpp +++ b/client/QSigner.cpp @@ -46,8 +46,8 @@ Q_LOGGING_CATEGORY(SLog, "qdigidoc4.QSigner") class QSigner::Private final { public: - QCryptoBackend *backend = nullptr; - QSmartCard *smartcard = nullptr; + QCryptoBackend *backend {}; + QSmartCard *smartcard {}; TokenData auth, sign; QList cache; @@ -61,7 +61,7 @@ ECDSA_SIG* QSigner::Private::ecdsa_do_sign(const unsigned char *dgst, int dgst_l const BIGNUM * /*inv*/, const BIGNUM * /*rp*/, EC_KEY *eckey) { QCryptoBackend *backend = (QCryptoBackend*)EC_KEY_get_ex_data(eckey, 0); - QByteArray result = backend->sign(0, QByteArray::fromRawData((const char*)dgst, dgst_len)); + QByteArray result = backend->sign(NID_sha256, QByteArray::fromRawData((const char*)dgst, dgst_len)); if(result.isEmpty()) return nullptr; QByteArray r = result.left(result.size()/2); @@ -199,9 +199,7 @@ QByteArray QSigner::decrypt(std::function &&func) } } while(status != QCryptoBackend::PinOK); QByteArray result; - waitFor([&]{ - result = func(d->backend); - }); + result = waitFor([&]{ return func(d->backend); }); QCardLock::instance().exclusiveUnlock(); d->backend->logout(); d->smartcard->reload(); // QSmartCard should also know that PIN1 is blocked. @@ -397,9 +395,8 @@ std::vector QSigner::sign(const std::string &method, const std::v throwException((tr("Failed to login token") + " " + QCryptoBackend::errorString(status)), Exception::PINFailed) } } while(status != QCryptoBackend::PinOK); - QByteArray sig; - waitFor([&]{ - sig = d->backend->sign(type, QByteArray::fromRawData((const char*)digest.data(), int(digest.size()))); + QByteArray sig = waitFor([&]{ + return d->backend->sign(type, QByteArray::fromRawData((const char*)digest.data(), int(digest.size()))); }); QCardLock::instance().exclusiveUnlock(); d->backend->logout(); diff --git a/client/QSmartCard.cpp b/client/QSmartCard.cpp index 28be742bd..d9de65978 100644 --- a/client/QSmartCard.cpp +++ b/client/QSmartCard.cpp @@ -113,10 +113,9 @@ QPCSCReader::Result Card::transfer(QPCSCReader *reader, bool verify, const QByte else if(Common::language() == QLatin1String("et")) language = 0x0425; else if(Common::language() == QLatin1String("ru")) language = 0x0419; QPCSCReader::Result result; - waitFor([&]{ - result = reader->transferCTL(apdu, verify, language, QSmartCardData::minPinLen(type), newPINOffset, requestCurrentPIN); + return waitFor([&]{ + return reader->transferCTL(apdu, verify, language, QSmartCardData::minPinLen(type), newPINOffset, requestCurrentPIN); }); - return result; } diff --git a/client/Utils.h b/client/Utils.h index 76f80eb32..671b7fe06 100644 --- a/client/Utils.h +++ b/client/Utils.h @@ -25,12 +25,13 @@ namespace { template - inline void waitFor(F&& function) { + inline auto waitFor(F&& function) { std::exception_ptr exception; + typename std::invoke_result::type result{}; QEventLoop l; std::thread([&]{ try { - function(); + result = function(); } catch(...) { exception = std::current_exception(); } @@ -39,6 +40,7 @@ namespace { l.exec(); if(exception) std::rethrow_exception(exception); + return result; } inline QString escapeUnicode(const QString &str) {