Skip to content

Commit 3594ec0

Browse files
author
Lauris Kaplinski
committed
Update to new automatic label system
1 parent 6b683b7 commit 3594ec0

3 files changed

Lines changed: 17 additions & 23 deletions

File tree

client/CDocSupport.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ StreamListSource::next(std::string& name, int64_t& size)
451451
}
452452

453453
static void
454-
recode_label(std::string& label, uint64_t& expiry)
454+
recode_label(libcdoc::Recipient& rcpt, std::string& label, uint64_t& expiry)
455455
{
456456
if(!label.starts_with("data:")) return;
457457
auto values = libcdoc::Lock::parseLabel(label);
@@ -463,40 +463,39 @@ recode_label(std::string& label, uint64_t& expiry)
463463
std::string expiry_str = values.at("server_exp");
464464
values.erase("server_exp");
465465
if (!expiry_str.empty()) expiry = std::stoll(expiry_str);
466-
QUrlQuery q;
467-
q.setQueryItems({
468-
{QStringLiteral("v"), QString::number(1)},
469-
{QStringLiteral("type"), QString::fromStdString(type)}
470-
});
471466
for (const auto& [key, value] : values) {
472467
if (!value.empty())
473-
q.addQueryItem(QString::fromStdString(key), QString::fromStdString(value));
468+
rcpt.setLabelValue(key, value);
474469
}
475-
label = "data:" + q.query(QUrl::FullyEncoded).toStdString();
476470
}
477471

478472
libcdoc::Recipient
479473
makeFromLock(const libcdoc::Lock& lock, const std::string& server_id)
480474
{
481475
uint64_t expiry_ts = 0;
482476
std::string label = lock.label;
483-
recode_label(label, expiry_ts);
484477
switch (lock.type) {
485478
case libcdoc::Lock::CDOC1:
486479
if (!server_id.empty()) {
487-
return libcdoc::Recipient::makeServer(label, lock.getBytes(libcdoc::Lock::CERT), server_id);
480+
libcdoc::Recipient rcpt = libcdoc::Recipient::makeServer(label, lock.getBytes(libcdoc::Lock::CERT), server_id);
481+
recode_label(rcpt, label, expiry_ts);
482+
return rcpt;
488483
} else {
489-
return libcdoc::Recipient::makeCertificate(label, lock.getBytes(libcdoc::Lock::CERT));
484+
libcdoc::Recipient rcpt = libcdoc::Recipient::makeCertificate(label, lock.getBytes(libcdoc::Lock::CERT));
485+
recode_label(rcpt, label, expiry_ts);
486+
return rcpt;
490487
}
491488
case libcdoc::Lock::PUBLIC_KEY:
492489
case libcdoc::Lock::SERVER: {
493490
libcdoc::Recipient::PKType rcpt_type = (lock.pk_type == libcdoc::Lock::RSA) ? libcdoc::Recipient::RSA : libcdoc::Recipient::ECC;
494491
if (!server_id.empty()) {
495492
libcdoc::Recipient rcpt = libcdoc::Recipient::makeServer(label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type, server_id);
493+
recode_label(rcpt, label, expiry_ts);
496494
rcpt.expiry_ts = expiry_ts;
497495
return rcpt;
498496
} else {
499497
libcdoc::Recipient rcpt = libcdoc::Recipient::makePublicKey(label, lock.getBytes(libcdoc::Lock::RCPT_KEY), rcpt_type);
498+
recode_label(rcpt, label, expiry_ts);
500499
rcpt.expiry_ts = expiry_ts;
501500
return rcpt;
502501
}

client/CryptoDoc.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,9 @@ bool CryptoDoc::encrypt(const QString &filename, const QString& label, const QBy
478478
libcdoc::result_t result = writer->encrypt(slsrc, enc_keys);
479479
writer_last_error = QString::fromStdString(writer->getLastErrorStr());
480480
qCDebug(CRYPTO) << "Encryption result: " << result << ' ' << writer_last_error;
481-
if (result == libcdoc::OK) // Encryption successful, open new reader
482-
d->createCDocReader(d->fileName);
483-
else if(QFile::exists(d->fileName))
484-
QFile::remove(d->fileName);
481+
if (result != libcdoc::OK)
482+
if(QFile::exists(d->fileName))
483+
QFile::remove(d->fileName);
485484
return result;
486485
});
487486
d->crypto.secret.clear();
@@ -491,14 +490,10 @@ bool CryptoDoc::encrypt(const QString &filename, const QString& label, const QBy
491490
->withText(tr("Please check your internet connection and network settings."))
492491
->withDetails(writer_last_error)
493492
->open();
494-
} else if(!d->reader) {
495-
WarningDialog::create()
496-
->withTitle(CryptoDoc::tr("Failed to open document"))
497-
->withText(CryptoDoc::tr("Unsupported file format"))
498-
->open();
499-
return false;
493+
} else {
494+
this->clear(d->fileName);
495+
this->open(d->fileName);
500496
}
501-
502497
return d->isEncrypted();
503498
}
504499

0 commit comments

Comments
 (0)