From 5a0babcc2ed25df0b3992a0f8a1f737c3d749392 Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 1 Dec 2026 01:05:49 +0100 Subject: [PATCH] Split ImitatePass::reencryptFiles Fourth batch for #2157: the largest function left (lizard CCN 55, 306 lines). The code and its comments move into helpers; the run does the same steps in the same order. - startReencryptRun(): the checks after the run's own pull (unfinished Git operation, a link, the list Init() wrote changed by the pull), the leftovers of an interrupted run and the backup commit. - reencryptEntry(): one entry, returning false when the run was cancelled meanwhile (the caller then stops, as the old break did). - listKeysFor(): a list's keys now and before Init(), once per run. - readerChangeOf(): who would gain the entry and who was taken off and still reads it. - holdForAgreement(): the question after the run, or the failure when the entry's bytes cannot be read to hold a yes to. - isTrustedEntry() and namedReaders(): the former lambdas. The run's record of key IDs, names and list keys is one WhoReads struct; ListKeys, WhoReads and ReaderChange are defined next to ReencryptResult. reencryptFiles 55 -> 8; every helper is below 15. No behaviour change. Part of #2157. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Anne Jan Brouwer --- src/imitatepass.cpp | 519 ++++++++++++++++++++++++-------------------- src/imitatepass.h | 81 +++++++ 2 files changed, 370 insertions(+), 230 deletions(-) diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index 6fade9bc0..88f351445 100644 --- a/src/imitatepass.cpp +++ b/src/imitatepass.cpp @@ -1529,6 +1529,32 @@ struct ImitatePass::ReencryptResult { QStringList walked; ///< Entries whose recipients the run judged. }; +/// Per list: the primary keys gpg encrypts to now (none when it cannot), +/// and those it encrypted to before Init() replaced the list (the same when +/// it did not, or when the old list no longer resolves). +struct ImitatePass::ListKeys { + std::optional> now; ///< Encrypted to now, if gpg can. + QSet before; ///< Encrypted to before Init(). + bool beforeUnknown = false; ///< Init() replaced a list gpg cannot + ///< encrypt to: who left it is unknown. +}; + +/// What one run has learnt about who reads what: each key ID's primary +/// key, a name for the question, and each list's keys. +struct ImitatePass::WhoReads { + QHash primaries; ///< Key ID to primary fingerprint. + QHash names; ///< Primary fingerprint to a name. + QHash lists; ///< `.gpg-id` path to its keys. +}; + +/// How re-encrypting one entry changes who can read it. +struct ImitatePass::ReaderChange { + bool gains = false; ///< Someone not added by this change gains it. + QSet gaining; ///< Those, by primary fingerprint. + QSet losing; ///< Removed recipients who still read it. + QSet listNow; ///< The list's keys now. +}; + namespace { /// Poll interval while waiting for queued git commands to drain. constexpr int kReencryptRetryMs = 100; @@ -1760,9 +1786,53 @@ auto ImitatePass::recipientsForDir(const QString &fileName, // cancel flag is set was interrupted: its file is neither checked nor failed. auto ImitatePass::reencryptFiles(const QString &dir) -> ReencryptResult { ReencryptResult result; + if (!startReencryptRun(dir, result)) { + return result; + } + + QStringList files = entriesToReencrypt(dir, &result.failed); + // A run the user agreed to takes the entries they were shown, no more. + if (!m_reencryptAgreed.isEmpty()) { + files.erase(std::remove_if(files.begin(), files.end(), + [this](const QString &file) { + return !m_reencryptAgreed.contains(file); + }), + files.end()); + } + result.total = files.size(); + emit reencryptProgress(0, result.total); + + QString currentDir; + QHash gpgIdFilesVerified; + QStringList gpgId; + WhoReads who; + for (const QString &fileName : std::as_const(files)) { + if (m_reencryptCancel.load()) { + result.cancelled = true; + break; + } + const QString fileDir = QFileInfo(fileName).path(); + if (fileDir != currentDir) { + if (!recipientsForDir(fileName, gpgIdFilesVerified, gpgId, result)) { + return result; + } + currentDir = fileDir; + } + if (!reencryptEntry(fileName, gpgId, who, result)) { + result.cancelled = true; + break; + } + result.checked++; + emit reencryptProgress(result.checked, result.total); + } + return result; +} + +auto ImitatePass::startReencryptRun(const QString &dir, ReencryptResult &result) + -> bool { if (!pullBeforeReencrypt()) { result.aborted = true; - return result; + return false; } // The GUI-thread checks ran before this worker's own pull. // pullBeforeReencrypt refuses an unmerged index, but a pull that stopped in a @@ -1775,7 +1845,7 @@ auto ImitatePass::reencryptFiles(const QString &dir) -> ReencryptResult { emit critical(tr("Unfinished Git operation"), midOp); } result.aborted = true; - return result; + return false; } // reencryptPath() checked the folder before the pull; a pulled commit can // have made it, or a folder above it, a link since. Recovery and the walk @@ -1787,7 +1857,7 @@ auto ImitatePass::reencryptFiles(const QString &dir) -> ReencryptResult { "password store and is left alone.") .arg(QDir::toNativeSeparators(QDir::cleanPath(dir)))); result.aborted = true; - return result; + return false; } // Init() wrote the recipients the user ticked and committed them. A pull @@ -1811,7 +1881,7 @@ auto ImitatePass::reencryptFiles(const QString &dir) -> ReencryptResult { QFileInfo(m_writtenGpgId->file).path()))); } result.aborted = true; - return result; + return false; } } @@ -1819,7 +1889,7 @@ auto ImitatePass::reencryptFiles(const QString &dir) -> ReencryptResult { // the backup commit like everything else, and a stale temporary does not. if (!recoverReencryptLeftovers(dir)) { result.aborted = true; - return result; + return false; } if (!createBackupCommit()) { @@ -1828,241 +1898,230 @@ auto ImitatePass::reencryptFiles(const QString &dir) -> ReencryptResult { } else { result.aborted = true; } - return result; - } - - QStringList files = entriesToReencrypt(dir, &result.failed); - // A run the user agreed to takes the entries they were shown, no more. - if (!m_reencryptAgreed.isEmpty()) { - files.erase(std::remove_if(files.begin(), files.end(), - [this](const QString &file) { - return !m_reencryptAgreed.contains(file); - }), - files.end()); + return false; } - result.total = files.size(); - emit reencryptProgress(0, result.total); + return true; +} - QString currentDir; - QHash gpgIdFilesVerified; - QStringList gpgId; - // Who reads what: each key ID's primary key, and a name for the question. - QHash primaries; - QHash names; - // Per list: the primary keys gpg encrypts to now (none when it cannot), - // and those it encrypted to before Init() replaced the list (the same - // when it did not, or when the old list no longer resolves). - struct ListKeys { - std::optional> now; - QSet before; - bool beforeUnknown = false; ///< Init() replaced a list gpg cannot - ///< encrypt to: who left it is unknown. - }; - QHash listKeys; +auto ImitatePass::isTrustedEntry(const QString &fileName, + const QSet &listNow) const -> bool { // What the user moved or copied in is taken as it is; what they agreed to // in reencryptAlso() only while its bytes are the ones they were shown. - const auto isTrusted = [this](const QString &fileName, - const QSet &listNow) { - if (std::any_of(m_reencryptTrusted.cbegin(), m_reencryptTrusted.cend(), - [&fileName](const QString &trusted) { - return fileName == trusted || - fileName.startsWith(trusted + QLatin1Char('/')); - })) { - return true; + if (std::any_of(m_reencryptTrusted.cbegin(), m_reencryptTrusted.cend(), + [&fileName](const QString &trusted) { + return fileName == trusted || + fileName.startsWith(trusted + QLatin1Char('/')); + })) { + return true; + } + const auto agreed = m_reencryptAgreed.constFind(fileName); + // An entry that cannot be read as a regular file hashes to nothing, + // which matches no agreement. + return agreed != m_reencryptAgreed.constEnd() && !agreed->hash.isEmpty() && + agreed->readers == listNow && entryHash(fileName) == agreed->hash; +} + +auto ImitatePass::listKeysFor(const QString &gpgIdPath, + const QStringList &gpgId, WhoReads &who) + -> const ListKeys & { + if (const auto known = who.lists.constFind(gpgIdPath); + known != who.lists.constEnd()) { + return *known; + } + ListKeys fresh; + fresh.now = keysEncryptedTo(gpgId, who.primaries, who.names); + std::optional> before = fresh.now; + if (m_previousList && m_previousList->gpgIdFile == gpgIdPath) { + before = keysEncryptedTo(m_previousList->recipients, who.primaries, + who.names, false); + } + // A previous list gpg cannot encrypt to, or one whose probe names + // nobody it can tell, exempts no one, and leaves unknown who was + // taken off it. + if (before && before->contains(kUnknownReader)) { + before.reset(); + } + fresh.before = before ? *before : fresh.now.value_or(QSet()); + fresh.beforeUnknown = !before; + return *who.lists.insert(gpgIdPath, fresh); +} + +auto ImitatePass::readerChangeOf(const QString &fileName, + const QStringList &keys, const ListKeys &lk, + WhoReads &who) -> ReaderChange { + ReaderChange change; + if (!lk.now) { + return change; + } + change.listNow = *lk.now; + const QSet readers = primaryKeysOf(keys, who.primaries, who.names); + change.gaining = *lk.now; + change.gaining.subtract(readers); + // Whom this change added gains every entry of the folder, as it + // should. + QSet added = *lk.now; + added.subtract(lk.before); + change.gaining.subtract(added); + change.gains = !change.gaining.isEmpty(); + // Who was taken off the list and still reads it, if it is skipped: + // by this change, or by an earlier one that left it so (and is not + // back on it now). + QSet removed = lk.before; + removed.unite(m_removedReaders.value(fileName)); + removed.subtract(*lk.now); + if (lk.beforeUnknown) { + removed.insert(kUnknownReader); + } + // A recipient ID that names no known key (hidden by throw-keyids, + // or not in the keyring) may be anyone removed. When every ID is + // known, only those removed who are among them still read it. + const bool readersKnown = + std::all_of(keys.cbegin(), keys.cend(), [&who](const QString &id) { + return who.primaries.contains(id.toUpper()); + }); + if (!readersKnown) { + change.losing = removed; + } else { + change.losing = readers; + change.losing.intersect(removed); + // Who was taken off is not known (an old list gpg could not + // encrypt to, or an earlier run that could not tell): any + // reader no longer on the list may be one. + if (removed.contains(kUnknownReader)) { + QSet off = readers; + off.subtract(*lk.now); + change.losing.unite(off); } - const auto agreed = m_reencryptAgreed.constFind(fileName); - // An entry that cannot be read as a regular file hashes to nothing, - // which matches no agreement. - return agreed != m_reencryptAgreed.constEnd() && !agreed->hash.isEmpty() && - agreed->readers == listNow && entryHash(fileName) == agreed->hash; - }; - for (const QString &fileName : std::as_const(files)) { - if (m_reencryptCancel.load()) { - result.cancelled = true; - break; + } + return change; +} + +auto ImitatePass::namedReaders(const QSet &fprs, + const QHash &names) + -> QString { + QStringList who; + for (const QString &fpr : fprs) { + if (fpr == kUnknownReader) { + who << tr("a recipient gpg does not name"); + continue; } - const QString fileDir = QFileInfo(fileName).path(); - if (fileDir != currentDir) { - if (!recipientsForDir(fileName, gpgIdFilesVerified, gpgId, result)) { - return result; - } - currentDir = fileDir; + who << names.value(fpr, fpr.right(16)); + } + who.sort(); + return who.join(QStringLiteral(", ")); +} + +auto ImitatePass::holdForAgreement(const QString &fileName, + const QStringList &keys, + const ReaderChange &change, + const WhoReads &who, ReencryptResult &result) + -> bool { + const QByteArray shownHash = entryHash(fileName); + if (shownHash.isEmpty()) { + // gpg lists its recipients, but its bytes cannot be held to a yes + // (over the read cap, or no longer a regular file): reported as + // left, not asked about, or the question would come back after + // every yes. + result.failed << tr("%1 was not re-encrypted: it would become " + "readable by %2, and it cannot be read to ask " + "about it (too large, or not a regular file).") + .arg(fileName, + namedReaders(change.gaining, who.names)); + if (!change.losing.isEmpty()) { + result.stillReadByRemoved.insert(fileName, change.losing); } - // A pull since the listing may have put a link under the name, or in - // place of a folder on the way to it. gpg given the name reads the - // target, and one already encrypted for these recipients would pass the - // comparison without a word. - bool keepRecord = false; - const QFileInfo entry(fileName); - if (entry.isSymLink() || !entry.isFile() || - Util::isUnderLink(fileName, m_settings.passStore)) { - result.failed << tr("%1 is no longer a regular file, or lies behind a " - "link, and was not re-encrypted.") - .arg(fileName); - } else if (const QStringList keys = getKeysFromFile(fileName); - keys != gpgId) { - // Re-encrypting hands the entry to this folder's recipients. Someone - // on the list who cannot read it yet, and whom this change did not - // add, gains it: an entry copied in from a folder they cannot read - // is left for the user to agree to. Taking readers away (a removed - // recipient, a rotated subkey) needs no question. Who reads it now is - // what its recipient IDs say, which a writer can add to: this stops a - // copy, not a crafted entry (SECURITY.md). - const QString gpgIdPath = - Pass::getGpgIdPath(fileName, m_settings.passStore); - bool gains = false; - QSet gaining; - QSet losing; - QSet listNow; - const bool hidden = - !keys.isEmpty() && - std::all_of(keys.cbegin(), keys.cend(), [](const QString &id) { - return id == QLatin1String("0000000000000000"); - }); - // No recipients gpg can list: not an entry it can decrypt either, so - // the attempt below fails without handing anything over. - if (!keys.isEmpty()) { - if (!listKeys.contains(gpgIdPath)) { - ListKeys fresh; - fresh.now = keysEncryptedTo(gpgId, primaries, names); - std::optional> before = fresh.now; - if (m_previousList && m_previousList->gpgIdFile == gpgIdPath) { - before = keysEncryptedTo(m_previousList->recipients, primaries, - names, false); - } - // A previous list gpg cannot encrypt to, or one whose probe names - // nobody it can tell, exempts no one, and leaves unknown who was - // taken off it. - if (before && before->contains(kUnknownReader)) { - before.reset(); - } - fresh.before = before ? *before : fresh.now.value_or(QSet()); - fresh.beforeUnknown = !before; - listKeys.insert(gpgIdPath, fresh); - } - const ListKeys &lk = listKeys[gpgIdPath]; - if (lk.now) { - listNow = *lk.now; - const QSet readers = primaryKeysOf(keys, primaries, names); - gaining = *lk.now; - gaining.subtract(readers); - // Whom this change added gains every entry of the folder, as it - // should. - QSet added = *lk.now; - added.subtract(lk.before); - gaining.subtract(added); - gains = !gaining.isEmpty(); - // Who was taken off the list and still reads it, if it is skipped: - // by this change, or by an earlier one that left it so (and is not - // back on it now). - QSet removed = lk.before; - removed.unite(m_removedReaders.value(fileName)); - removed.subtract(*lk.now); - if (lk.beforeUnknown) { - removed.insert(kUnknownReader); - } - // A recipient ID that names no known key (hidden by throw-keyids, - // or not in the keyring) may be anyone removed. When every ID is - // known, only those removed who are among them still read it. - const bool readersKnown = std::all_of( - keys.cbegin(), keys.cend(), [&primaries](const QString &id) { - return primaries.contains(id.toUpper()); - }); - if (!readersKnown) { - losing = removed; - } else { - losing = readers; - losing.intersect(removed); - // Who was taken off is not known (an old list gpg could not - // encrypt to, or an earlier run that could not tell): any - // reader no longer on the list may be one. - if (removed.contains(kUnknownReader)) { - QSet off = readers; - off.subtract(*lk.now); - losing.unite(off); - } - } - } - } - if (m_reencryptCancel.load()) { - result.cancelled = true; - break; - } - const auto named = [this, &names](const QSet &fprs) { - QStringList who; - for (const QString &fpr : fprs) { - if (fpr == kUnknownReader) { - who << tr("a recipient gpg does not name"); - continue; - } - who << names.value(fpr, fpr.right(16)); - } - who.sort(); - return who.join(QStringLiteral(", ")); - }; - QString why; - const bool ask = gains && !isTrusted(fileName, listNow); - const QByteArray shownHash = ask ? entryHash(fileName) : QByteArray(); - if (ask && shownHash.isEmpty()) { - // gpg lists its recipients, but its bytes cannot be held to a yes - // (over the read cap, or no longer a regular file): reported as - // left, not asked about, or the question would come back after - // every yes. - result.failed << tr("%1 was not re-encrypted: it would become " - "readable by %2, and it cannot be read to ask " - "about it (too large, or not a regular file).") - .arg(fileName, named(gaining)); - if (!losing.isEmpty()) { - result.stillReadByRemoved.insert(fileName, losing); - } - keepRecord = true; - } else if (ask) { - result.unexpected << fileName; - result.unexpectedHashes << shownHash; - result.unexpectedReaders << listNow; - QString detail = - hidden ? tr("its recipients cannot be told (hidden key IDs); " - "it would become readable by %1") - .arg(named(gaining)) - : tr("would become readable by %1").arg(named(gaining)); - if (!losing.isEmpty()) { - // Named only where the entry's recipients say so; otherwise it - // may be. - detail += - QStringLiteral("; ") + - (losing.contains(kUnknownReader) || - !std::all_of(keys.cbegin(), keys.cend(), - [&primaries](const QString &id) { - return primaries.contains(id.toUpper()); - }) - ? tr("may still be readable by someone taken off " - "the list") - : tr("still readable by %1, who was removed") - .arg(named(losing))); - result.stillReadByRemoved.insert(fileName, losing); - } - result.unexpectedDetails << detail; - } else if (reencryptSingleFile(fileName, gpgId, &why)) { - result.reencrypted++; - result.rewritten << fileName; - } else if (m_reencryptCancel.load()) { - // Interrupted by the cancel: the file is untouched, not failed. - result.cancelled = true; - break; - } else { - // The reason names the entry itself when there is one to give. - result.failed << (why.isEmpty() ? fileName : why); - // Not rewritten: whoever was removed still reads it. - keepRecord = true; - } + return true; + } + const bool hidden = + !keys.isEmpty() && + std::all_of(keys.cbegin(), keys.cend(), [](const QString &id) { + return id == QLatin1String("0000000000000000"); + }); + result.unexpected << fileName; + result.unexpectedHashes << shownHash; + result.unexpectedReaders << change.listNow; + QString detail = hidden + ? tr("its recipients cannot be told (hidden key IDs); " + "it would become readable by %1") + .arg(namedReaders(change.gaining, who.names)) + : tr("would become readable by %1") + .arg(namedReaders(change.gaining, who.names)); + if (!change.losing.isEmpty()) { + // Named only where the entry's recipients say so; otherwise it + // may be. + detail += + QStringLiteral("; ") + + (change.losing.contains(kUnknownReader) || + !std::all_of(keys.cbegin(), keys.cend(), + [&who](const QString &id) { + return who.primaries.contains(id.toUpper()); + }) + ? tr("may still be readable by someone taken off " + "the list") + : tr("still readable by %1, who was removed") + .arg(namedReaders(change.losing, who.names))); + result.stillReadByRemoved.insert(fileName, change.losing); + } + result.unexpectedDetails << detail; + return false; +} + +auto ImitatePass::reencryptEntry(const QString &fileName, + const QStringList &gpgId, WhoReads &who, + ReencryptResult &result) -> bool { + // A pull since the listing may have put a link under the name, or in + // place of a folder on the way to it. gpg given the name reads the + // target, and one already encrypted for these recipients would pass the + // comparison without a word. + bool keepRecord = false; + const QFileInfo entry(fileName); + if (entry.isSymLink() || !entry.isFile() || + Util::isUnderLink(fileName, m_settings.passStore)) { + result.failed << tr("%1 is no longer a regular file, or lies behind a " + "link, and was not re-encrypted.") + .arg(fileName); + } else if (const QStringList keys = getKeysFromFile(fileName); + keys != gpgId) { + // Re-encrypting hands the entry to this folder's recipients. Someone + // on the list who cannot read it yet, and whom this change did not + // add, gains it: an entry copied in from a folder they cannot read + // is left for the user to agree to. Taking readers away (a removed + // recipient, a rotated subkey) needs no question. Who reads it now is + // what its recipient IDs say, which a writer can add to: this stops a + // copy, not a crafted entry (SECURITY.md). + ReaderChange change; + // No recipients gpg can list: not an entry it can decrypt either, so + // the attempt below fails without handing anything over. + if (!keys.isEmpty()) { + change = readerChangeOf( + fileName, keys, + listKeysFor(Pass::getGpgIdPath(fileName, m_settings.passStore), gpgId, + who), + who); } - if (!keepRecord) { - result.walked << fileName; + if (m_reencryptCancel.load()) { + return false; + } + QString why; + if (change.gains && !isTrustedEntry(fileName, change.listNow)) { + keepRecord = holdForAgreement(fileName, keys, change, who, result); + } else if (reencryptSingleFile(fileName, gpgId, &why)) { + result.reencrypted++; + result.rewritten << fileName; + } else if (m_reencryptCancel.load()) { + // Interrupted by the cancel: the file is untouched, not failed. + return false; + } else { + // The reason names the entry itself when there is one to give. + result.failed << (why.isEmpty() ? fileName : why); + // Not rewritten: whoever was removed still reads it. + keepRecord = true; } - result.checked++; - emit reencryptProgress(result.checked, result.total); } - return result; + if (!keepRecord) { + result.walked << fileName; + } + return true; } // No push after a cancel, abort or per-file failure: a partially re-encrypted diff --git a/src/imitatepass.h b/src/imitatepass.h index 6ede23100..a3547de92 100644 --- a/src/imitatepass.h +++ b/src/imitatepass.h @@ -827,6 +827,87 @@ class ImitatePass : public Pass { * @return Counts and the list of files that could not be re-encrypted. */ auto reencryptFiles(const QString &dir) -> ReencryptResult; + /// Per list: the primary keys gpg encrypts to now and before Init(). + struct ListKeys; + /// What one run has learnt about who reads what. + struct WhoReads; + /// How re-encrypting one entry changes who can read it. + struct ReaderChange; + /** + * @brief The checks a run makes after its own pull, before it writes: + * no unfinished Git operation, @p dir not a link or behind one, the list + * Init() wrote unchanged by the pull; then the leftovers of an + * interrupted run, and the backup commit. + * @param dir Directory passed to reencryptPath(). + * @param result Marked aborted or cancelled when the run stops. + * @return Whether the run goes on. + */ + auto startReencryptRun(const QString &dir, ReencryptResult &result) -> bool; + /** + * @brief Whether an entry that would gain readers is taken without a + * question: the user moved or copied it in, or agreed to it in + * reencryptAlso() while its bytes and its list's keys are unchanged. + * @param fileName The entry. + * @param listNow The keys its list encrypts to now. + * @return Whether it is re-encrypted without asking. + */ + [[nodiscard]] auto isTrustedEntry(const QString &fileName, + const QSet &listNow) const -> bool; + /** + * @brief The keys of the list at @p gpgIdPath, worked out once per run. + * @param gpgIdPath The `.gpg-id` the entry falls under. + * @param gpgId The recipients read from it. + * @param who The run's record; the result is kept in it. + * @return Its keys now and before Init() replaced it. + */ + auto listKeysFor(const QString &gpgIdPath, const QStringList &gpgId, + WhoReads &who) -> const ListKeys &; + /** + * @brief Who would gain an entry by re-encrypting it to its list, other + * than those this change added, and who was taken off and still reads + * it. + * @param fileName The entry. + * @param keys The recipient key IDs it is encrypted to. + * @param lk Its list's keys (listKeysFor()). + * @param who The run's record of key IDs and names. + * @return The change; nobody gains when gpg cannot encrypt to the list. + */ + auto readerChangeOf(const QString &fileName, const QStringList &keys, + const ListKeys &lk, WhoReads &who) -> ReaderChange; + /** + * @brief The names of @p fprs for a question or a failure, sorted. + * @param fprs Primary fingerprints, or kUnknownReader. + * @param names Fingerprint to name, as the run learnt them. + * @return The names, comma-separated. + */ + static auto namedReaders(const QSet &fprs, + const QHash &names) -> QString; + /** + * @brief Leave an entry that would gain readers for the user: named in + * the question after the run, with the bytes it is named for, or + * reported as failed when its bytes cannot be read to hold a yes to. + * @param fileName The entry. + * @param keys The recipient key IDs it is encrypted to. + * @param change Who gains it and who still reads it. + * @param who The run's record of key IDs and names. + * @param result Gets the question or the failure. + * @return Whether its removed-reader record is kept (reported as failed). + */ + auto holdForAgreement(const QString &fileName, const QStringList &keys, + const ReaderChange &change, const WhoReads &who, + ReencryptResult &result) -> bool; + /** + * @brief Check one entry and re-encrypt it to @p gpgId when it is not + * encrypted to those keys yet, unless it would gain readers no one + * agreed to. + * @param fileName The entry. + * @param gpgId The recipients of its folder. + * @param who The run's record of who reads what. + * @param result Gets the entry's outcome. + * @return false when the run was cancelled meanwhile. + */ + auto reencryptEntry(const QString &fileName, const QStringList &gpgId, + WhoReads &who, ReencryptResult &result) -> bool; /** * @brief Pull before a run, when the store is a Git repository and * automatic pulling is on.