Skip to content

Commit

Permalink
Fix Picture loading under windows (open-eid#1121)
Browse files Browse the repository at this point in the history
IB-7524

Signed-off-by: Raul Metsma <[email protected]>

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Sep 19, 2022
1 parent c9c9017 commit 7c16ebd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
16 changes: 8 additions & 8 deletions client/DigiDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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 ); }
Expand All @@ -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);
Expand Down
15 changes: 6 additions & 9 deletions client/QSigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenData> cache;

Expand All @@ -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);
Expand Down Expand Up @@ -199,9 +199,7 @@ QByteArray QSigner::decrypt(std::function<QByteArray (QCryptoBackend *)> &&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.
Expand Down Expand Up @@ -397,9 +395,8 @@ std::vector<unsigned char> 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();
Expand Down
5 changes: 2 additions & 3 deletions client/QSmartCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
6 changes: 4 additions & 2 deletions client/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@

namespace {
template <typename F>
inline void waitFor(F&& function) {
inline auto waitFor(F&& function) {
std::exception_ptr exception;
typename std::invoke_result<F>::type result{};
QEventLoop l;
std::thread([&]{
try {
function();
result = function();
} catch(...) {
exception = std::current_exception();
}
Expand All @@ -39,6 +40,7 @@ namespace {
l.exec();
if(exception)
std::rethrow_exception(exception);
return result;
}

inline QString escapeUnicode(const QString &str) {
Expand Down

0 comments on commit 7c16ebd

Please sign in to comment.