• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 43482519769

13 Nov 2026 06:25PM UTC coverage: 68.466% (+0.05%) from 68.419%
43482519769

push

github

web-flow
coverage: let lcov ignore inconsistent data on system headers (#2138)

lcov 2.x on the CI runner (gcc 15 headers) fails the coverage job with
"lcov: ERROR: (inconsistent) ...: function ... is not hit but line ... has
a non-zero hit count" on files outside the project (e.g. /usr/include/c++/15
and Qt headers), aborting lcov_prepare before coverage of src/ is produced.

The captures already pass "--ignore-errors unused"; add "inconsistent" the
same way. Only the consistency check on data filtered out anyway (-e src/*)
is bypassed; src/ coverage is unchanged. Backport of #2136.

Signed-off-by: Anne Jan Brouwer <brouwer@annejan.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

5276 of 7706 relevant lines covered (68.47%)

72.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.37
/src/pass.cpp
1
// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "pass.h"
4
#include "gpgkeystate.h"
5
#include "util.h"
6
#include <QCoreApplication>
7
#include <QDebug>
8
#include <QDir>
9
#include <QFile>
10
#include <QFileInfo>
11
#include <QProcess>
12
#include <QRandomGenerator>
13
#include <QRegularExpression>
14
#include <QSaveFile>
15
#include <QTextStream>
16
#include <utility>
17

18
#ifdef QT_DEBUG
19
#include "debughelper.h"
20
#endif
21

22
using Enums::GIT_INIT;
23
using Enums::GIT_PULL;
24
using Enums::GIT_PUSH;
25
using Enums::GPG_GENKEYS;
26
using Enums::PASS_COPY;
27
using Enums::PASS_GREP;
28
using Enums::PASS_INIT;
29
using Enums::PASS_INSERT;
30
using Enums::PASS_MOVE;
31
using Enums::PASS_OTP_GENERATE;
32
using Enums::PASS_REMOVE;
33
using Enums::PASS_SHOW;
34

35
namespace {
36
/**
37
 * @brief Returns a non-empty charset value, using a fallback when needed.
38
 * @param input Preferred charset value.
39
 * @param fallback Charset to use when @p input is empty.
40
 * @return @p input if it is not empty; otherwise @p fallback.
41
 */
42
auto fallbackCharset(const QString &input, const QString &fallback) -> QString {
43
  return input.isEmpty() ? fallback : input;
1,275 ✔
44
}
45

46
/**
47
 * @brief Resolve the effective password character set from configuration.
48
 *
49
 * Uses the selected charset index from @p passConfig when it is within range;
50
 * otherwise falls back to the ALLCHARS entry. If the resolved charset string
51
 * is empty, falls back again to the ALLCHARS value.
52
 *
53
 * @param passConfig Password generation configuration.
54
 * @return Non-empty charset string to use for password generation.
55
 */
56
auto effectiveCharset(const PasswordConfiguration &passConfig) -> QString {
71 ✔
57
  int sel = passConfig.selected;
71 ✔
58
  if (sel < 0 || sel >= PasswordConfiguration::CHARSETS_COUNT)
71 ✔
59
    sel = PasswordConfiguration::ALLCHARS;
60
  return fallbackCharset(
61
      passConfig.Characters[sel],
71 ✔
62
      passConfig.Characters[PasswordConfiguration::ALLCHARS]);
71 ✔
63
}
64
} // namespace
65

66
/**
67
 * @brief Pass::Pass wrapper for using either pass or the pass imitation
68
 */
69
Pass::Pass() : env(QProcessEnvironment::systemEnvironment()) {
79 ✔
70
  connect(&exec,
79 ✔
71
          static_cast<void (Executor::*)(int, int, const QString &,
72
                                         const QString &)>(&Executor::finished),
73
          this, &Pass::finished);
79 ✔
74
  connect(&exec, &Executor::error, this, &Pass::finished);
79 ✔
75

76
  connect(&exec, &Executor::starting, this, &Pass::startingExecuteWrapper);
79 ✔
77
  // Merge our vars into WSLENV rather than blindly appending a duplicate
78
  // entry. WSLENV flags: /p translates the path, /u forwards from Windows
79
  // into WSL only; /w would be the other direction, from WSL out, and leaves
80
  // pass inside WSL without the value. Everything updateEnv() sets for pass
81
  // has to cross, the signing key above all: without it pass does not check
82
  // the .gpg-id signature.
83
  const QStringList wslenvVars = {
84
      QStringLiteral("PASSWORD_STORE_DIR/p"),
158 ✔
85
      QStringLiteral("PASSWORD_STORE_SIGNING_KEY/u"),
79 ✔
86
      QStringLiteral("PASSWORD_STORE_GENERATED_LENGTH/u"),
79 ✔
87
      QStringLiteral("PASSWORD_STORE_CHARACTER_SET/u"),
79 ✔
88
      QStringLiteral("PASSWORD_STORE_GPG_OPTS/u")};
474 ✔
89
  const QString existing = env.value(QStringLiteral("WSLENV"));
158 ✔
90
  if (existing.isEmpty()) {
79 ✔
91
    env.insert(QStringLiteral("WSLENV"), wslenvVars.join(':'));
158 ✔
92
  } else {
93
    QStringList parts = existing.split(':', Qt::SkipEmptyParts);
×
94
    for (const QString &v : wslenvVars) {
×
95
      if (!parts.contains(v))
×
96
        parts.append(v);
97
    }
98
    env.insert(QStringLiteral("WSLENV"), parts.join(':'));
×
99
  }
100
}
79 ✔
101

102
/**
103
 * @brief Executes a wrapper command.
104
 * @param id Process ID
105
 * @param app Application to execute
106
 * @param args Arguments
107
 * @param readStdout Whether to read stdout
108
 * @param readStderr Whether to read stderr
109
 */
110
void Pass::executeWrapper(PROCESS id, const QString &app,
×
111
                          const QStringList &args, bool readStdout,
112
                          bool readStderr) {
113
  executeWrapper(id, app, args, QString(), readStdout, readStderr);
×
114
}
×
115

116
void Pass::executeWrapper(PROCESS id, const QString &app,
64 ✔
117
                          const QStringList &args, QString input,
118
                          bool readStdout, bool readStderr) {
119
  beforeExecute(id);
64 ✔
120
#ifdef QT_DEBUG
121
  dbg() << app << args;
122
#endif
123
  exec.execute(id, m_settings.passStore, app, args, std::move(input),
64 ✔
124
               readStdout, readStderr);
125
}
64 ✔
126

127
void Pass::beforeExecute(PROCESS /*id*/) {}
×
128

129
/**
130
 * @brief Initializes the pass wrapper with a settings snapshot.
131
 * @param settings Application settings to use for this backend lifetime.
132
 */
133
void Pass::init(const AppSettings &settings) {
101 ✔
134
  m_settings = settings;
101 ✔
135
#ifdef __APPLE__
136
  // If it exists, prepend gpgtools to PATH
137
  if (QFile(QStringLiteral("/usr/local/MacGPG2/bin")).exists())
138
    env.insert(QStringLiteral("PATH"),
139
               QStringLiteral("/usr/local/MacGPG2/bin:") +
140
                   env.value(QStringLiteral("PATH")));
141
  // Add missing /usr/local/bin (exact component match, no leading colon)
142
  const QString currentPath = env.value(QStringLiteral("PATH"));
143
  if (!currentPath.split(':', Qt::SkipEmptyParts)
144
           .contains(QStringLiteral("/usr/local/bin"))) {
145
    env.insert(QStringLiteral("PATH"),
146
               currentPath.isEmpty()
147
                   ? QStringLiteral("/usr/local/bin")
148
                   : QStringLiteral("/usr/local/bin:") + currentPath);
149
  }
150
#endif
151

152
  // GNUPGHOME: the configured gpgHome wins over the inherited environment,
153
  // but only when it exists. A gpgHome that is gone (the 1.7.0 test suite
154
  // left its temporary keyring path in the live QtPass.conf, #1711) would
155
  // make every gpg call fail with "No secret key"; fall back to whatever the
156
  // environment says and tell the user. Clearing the setting at runtime
157
  // restores the inherited value as well instead of keeping the old path.
158
  const QString inheritedHome = QProcessEnvironment::systemEnvironment().value(
202 ✔
159
      QStringLiteral("GNUPGHOME"));
202 ✔
160
  const auto useInheritedHome = [this, &inheritedHome]() {
64 ✔
161
    if (inheritedHome.isEmpty()) {
64 ✔
162
      env.remove(QStringLiteral("GNUPGHOME"));
128 ✔
163
    } else {
164
      env.insert(QStringLiteral("GNUPGHOME"), inheritedHome);
×
165
    }
166
  };
165 ✔
167
  if (m_settings.gpgHome.isEmpty()) {
101 ✔
168
    useInheritedHome();
63 ✔
169
  } else {
170
    QDir absHome(m_settings.gpgHome);
38 ✔
171
    absHome.makeAbsolute();
38 ✔
172
    if (absHome.exists()) {
38 ✔
173
      env.insert(QStringLiteral("GNUPGHOME"), absHome.path());
74 ✔
174
    } else {
175
      if (inheritedHome.isEmpty()) {
1 ✔
176
        qWarning() << "gpgHome" << absHome.path()
2 ✔
177
                   << "does not exist; using the default GnuPG home";
1 ✔
178
        emit statusMsg(tr("Configured GPG home %1 does not exist, using the "
1 ✔
179
                          "default keyring")
180
                           .arg(absHome.path()),
2 ✔
181
                       5000);
182
      } else {
183
        qWarning() << "gpgHome" << absHome.path()
×
184
                   << "does not exist; using GNUPGHOME" << inheritedHome
×
185
                   << "from the environment";
×
186
        emit statusMsg(tr("Configured GPG home %1 does not exist, using "
×
187
                          "GNUPGHOME %2 from the environment")
188
                           .arg(absHome.path(), inheritedHome),
×
189
                       5000);
190
      }
191
      useInheritedHome();
1 ✔
192
    }
193
  }
38 ✔
194
}
101 ✔
195

196
/**
197
 * @brief Pass::Generate use either pwgen or internal password
198
 * generator
199
 * @param length of the desired password
200
 * @param charset to use for generation
201
 * @return the password
202
 */
203
auto Pass::generatePassword(unsigned int length, const QString &charset)
1,205 ✔
204
    -> QString {
205
  if (length == 0) {
1,205 ✔
206
    emit critical(tr("Invalid password length"),
2 ✔
207
                  tr("Can't generate password with zero length."));
1 ✔
208
    return {};
1 ✔
209
  }
210
  QString passwd;
1,204 ✔
211
  if (m_settings.usePwgen) {
1,204 ✔
212
    // --secure goes first as it overrides --no-* otherwise
213
    QStringList args;
×
214
    args.append("-1");
×
215
    if (!m_settings.lessRandom) {
×
216
      args.append("--secure");
×
217
    }
218
    args.append(m_settings.avoidCapitals ? "--no-capitalize" : "--capitalize");
×
219
    args.append(m_settings.avoidNumbers ? "--no-numerals" : "--numerals");
×
220
    if (m_settings.useSymbols) {
×
221
      args.append("--symbols");
×
222
    }
223
    args.append(QString::number(length));
×
224
    // executeBlocking returns 0 on success, non-zero on failure
225
    if (Executor::executeBlocking(m_settings.pwgenExecutable, args, &passwd) ==
×
226
        0) {
227
      static const QRegularExpression literalNewLines{"[\\n\\r]"};
1 ✔
228
      passwd.remove(literalNewLines);
×
229
    } else {
230
      passwd.clear();
×
231
#ifdef QT_DEBUG
232
      qDebug() << __FILE__ << ":" << __LINE__ << "\t"
233
               << "pwgen fail";
234
#endif
235
      // Error is already handled by clearing passwd; no need for critical
236
      // signal here
237
    }
238
  } else {
239
    // Validate charset - if CUSTOM is selected but chars are empty,
240
    // fall back to ALLCHARS to prevent weak passwords (issue #780)
241
    const QString cs = fallbackCharset(
242
        charset, m_settings.passwordConfiguration
243
                     .Characters[PasswordConfiguration::ALLCHARS]);
1,204 ✔
244
    if (cs.length() > 0) {
1,204 ✔
245
      passwd = generateRandomPassword(cs, length);
2,408 ✔
246
    } else {
247
      emit critical(
×
248
          tr("No characters chosen"),
×
249
          tr("Can't generate password, there are no characters to choose from "
×
250
             "set in the configuration!"));
251
    }
252
  }
253
  return passwd;
254
}
255

256
/**
257
 * @brief Pass::gpgSupportsEd25519 check if GPG supports ed25519 (ECC)
258
 * GPG 2.1+ supports ed25519 which is much faster for key generation
259
 * @return true if ed25519 is supported
260
 */
261
bool Pass::gpgSupportsEd25519(const QString &gpgExecutable) {
18 ✔
262
  const QString exe =
263
      gpgExecutable.isEmpty() ? QStringLiteral("gpg") : gpgExecutable;
18 ✔
264
  QString out, err;
18 ✔
265
  if (Executor::executeBlocking(exe, {"--version"}, &out, &err) != 0) {
72 ✔
266
    return false;
267
  }
268
  QRegularExpression versionRegex(R"(gpg \(GnuPG\) (\d+)\.(\d+))");
18 ✔
269
  QRegularExpressionMatch match = versionRegex.match(out);
18 ✔
270
  if (!match.hasMatch()) {
18 ✔
271
    return false;
272
  }
273
  int major = match.captured(1).toInt();
18 ✔
274
  int minor = match.captured(2).toInt();
18 ✔
275
  return major > 2 || (major == 2 && minor >= 1);
18 ✔
276
}
18 ✔
277

278
/**
279
 * @brief Pass::getDefaultKeyTemplate return default key generation template
280
 * Uses ed25519 if supported, otherwise falls back to RSA
281
 * @return GPG batch template string
282
 */
283
QString Pass::getDefaultKeyTemplate(const QString &gpgExecutable) {
17 ✔
284
  if (gpgSupportsEd25519(gpgExecutable)) {
17 ✔
285
    return QStringLiteral("%echo Generating a default key\n"
17 ✔
286
                          "Key-Type: EdDSA\n"
287
                          "Key-Curve: Ed25519\n"
288
                          "Subkey-Type: ECDH\n"
289
                          "Subkey-Curve: Curve25519\n"
290
                          "Name-Real: \n"
291
                          "Name-Comment: QtPass\n"
292
                          "Name-Email: \n"
293
                          "Expire-Date: 0\n"
294
                          "%no-protection\n"
295
                          "%commit\n"
296
                          "%echo done");
297
  }
298
  return QStringLiteral("%echo Generating a default key\n"
×
299
                        "Key-Type: RSA\n"
300
                        "Subkey-Type: RSA\n"
301
                        "Name-Real: \n"
302
                        "Name-Comment: QtPass\n"
303
                        "Name-Email: \n"
304
                        "Expire-Date: 0\n"
305
                        "%no-protection\n"
306
                        "%commit\n"
307
                        "%echo done");
308
}
309

310
namespace {
311
/**
312
 * @brief Resolve a candidate gpgconf path from the trailing WSL path segment.
313
 *
314
 * Takes the directory portion of @p lastPart (separated by '/' or '\\') and
315
 * appends "gpgconf"; if no separator is present, returns the bare executable
316
 * name "gpgconf".
317
 *
318
 * @param lastPart Path fragment that may contain a directory and executable.
319
 * @return Full path ending in "gpgconf", or "gpgconf" as a fallback.
320
 */
321
auto resolveWslGpgconfPath(const QString &lastPart) -> QString {
5 ✔
322
  qsizetype lastSep = lastPart.lastIndexOf('/');
5 ✔
323
  if (lastSep < 0) {
5 ✔
324
    lastSep = lastPart.lastIndexOf('\\');
4 ✔
325
  }
326
  if (lastSep >= 0) {
4 ✔
327
    return lastPart.left(lastSep + 1) + "gpgconf";
2 ✔
328
  }
329
  return QStringLiteral("gpgconf");
4 ✔
330
}
331

332
/**
333
 * @brief Finds the path to the gpgconf executable in the same directory as the
334
 * given GPG path.
335
 * @example
336
 * QString result = findGpgconfInGpgDir(gpgPath);
337
 * std::cout << result.toStdString() << std::endl; // Expected output: path to
338
 * gpgconf or empty string
339
 *
340
 * @param gpgPath - Absolute path to a GPG executable or related file used to
341
 * locate gpgconf.
342
 * @return QString - The full path to gpgconf if found and executable; otherwise
343
 * an empty QString.
344
 */
345
QString findGpgconfInGpgDir(const QString &gpgPath) {
1 ✔
346
  QFileInfo gpgInfo(gpgPath);
1 ✔
347
  if (!gpgInfo.isAbsolute()) {
1 ✔
348
    return {};
×
349
  }
350

351
  QDir dir(gpgInfo.absolutePath());
1 ✔
352

353
#ifdef Q_OS_WIN
354
  QFileInfo candidateExe(dir.filePath("gpgconf.exe"));
355
  if (candidateExe.isExecutable()) {
356
    return candidateExe.filePath();
357
  }
358
#endif
359

360
  QFileInfo candidate(dir.filePath("gpgconf"));
1 ✔
361
  if (candidate.isExecutable()) {
1 ✔
362
    return candidate.filePath();
×
363
  }
364
  return {};
1 ✔
365
}
1 ✔
366

367
// Compatibility shim for Qt < 5.15 where QProcess::splitCommand is not
368
// available. Keep this fallback while supporting pre-5.15 builds; remove once
369
// the project's minimum supported Qt version is raised to 5.15 or newer.
370
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
371
/**
372
 * @brief Splits a command string into arguments while respecting quotes and
373
 * escape characters.
374
 * @example
375
 * QStringList result = splitCommandCompat("cmd \"arg one\" 'arg two'
376
 * escaped\\ space");
377
 * // Expected output: ["cmd", "arg one", "arg two", "escaped space"]
378
 *
379
 * @param command - The input command string to split into individual arguments.
380
 * @return QStringList - A list of parsed command arguments.
381
 */
382
QStringList splitCommandCompat(const QString &command) {
383
  QStringList result;
384
  QString current;
385
  bool inSingleQuote = false;
386
  bool inDoubleQuote = false;
387
  bool escaping = false;
388
  for (QChar ch : command) {
389
    if (escaping) {
390
      current.append(ch);
391
      escaping = false;
392
      continue;
393
    }
394
    if (ch == '\\') {
395
      escaping = true;
396
      continue;
397
    }
398
    if (ch == '\'' && !inDoubleQuote) {
399
      inSingleQuote = !inSingleQuote;
400
      continue;
401
    }
402
    if (ch == '"' && !inSingleQuote) {
403
      inDoubleQuote = !inDoubleQuote;
404
      continue;
405
    }
406
    if (ch.isSpace() && !inSingleQuote && !inDoubleQuote) {
407
      if (!current.isEmpty()) {
408
        result.append(current);
409
        current.clear();
410
      }
411
      continue;
412
    }
413
    current.append(ch);
414
  }
415
  if (escaping) {
416
    current.append('\\');
417
  }
418
  if (!current.isEmpty()) {
419
    result.append(current);
420
  }
421
  return result;
422
}
423
#endif
424

425
} // namespace
426

427
/**
428
 * @brief Resolves the appropriate gpgconf command from a given GPG executable
429
 * path or command string.
430
 * @example
431
 * ResolvedGpgconfCommand result = Pass::resolveGpgconfCommand("wsl.exe
432
 * /usr/bin/gpg"); std::cout << result.first.toStdString() << std::endl; //
433
 * Expected output sample
434
 *
435
 * @param const QString &gpgPath - Path or command string pointing to the GPG
436
 * executable.
437
 * @return ResolvedGpgconfCommand - A pair containing the resolved gpgconf
438
 * command and its arguments.
439
 */
440
auto Pass::resolveGpgconfCommand(const QString &gpgPath)
10 ✔
441
    -> ResolvedGpgconfCommand {
442
  if (gpgPath.trimmed().isEmpty()) {
10 ✔
443
    return {"gpgconf", {}};
444
  }
445

446
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
447
  QStringList parts = QProcess::splitCommand(gpgPath);
9 ✔
448
#else
449
  QStringList parts = splitCommandCompat(gpgPath);
450
#endif
451

452
  if (parts.isEmpty()) {
9 ✔
453
    return {"gpgconf", {}};
454
  }
455

456
  const QString first = parts.first();
457
  if (first.compare("wsl", Qt::CaseInsensitive) == 0 ||
20 ✔
458
      first.compare("wsl.exe", Qt::CaseInsensitive) == 0) {
11 ✔
459
    if (parts.size() >= 2 && parts.at(1).startsWith("sh")) {
13 ✔
460
      return {"gpgconf", {}};
461
    }
462
    if (parts.size() >= 2 &&
6 ✔
463
        QFileInfo(parts.last()).fileName().startsWith("gpg")) {
16 ✔
464
      QString wslGpgconf = resolveWslGpgconfPath(parts.last());
5 ✔
465
      parts.removeLast();
5 ✔
466
      // Run gpgconf directly rather than through the distribution's default
467
      // shell, which would word-split and expand the arguments. Keep any
468
      // --exec/-e the user already put in the command.
469
      if (!parts.contains("--exec") && !parts.contains("-e")) {
9 ✔
470
        parts.append("--exec");
6 ✔
471
      }
472
      parts.append(wslGpgconf);
473
      return {parts.first(), parts.mid(1)};
474
    }
475
    return {"gpgconf", {}};
476
  }
477

478
  if (!first.contains('/') && !first.contains('\\')) {
2 ✔
479
    return {"gpgconf", {}};
480
  }
481

482
  QString gpgconfPath = findGpgconfInGpgDir(first);
1 ✔
483
  if (!gpgconfPath.isEmpty()) {
1 ✔
484
    return {gpgconfPath, {}};
×
485
  }
486

487
  return {"gpgconf", {}};
488
}
10 ✔
489

490
/**
491
 * @brief Pass::GenerateGPGKeys internal gpg keypair generator . .
492
 * @param batch GnuPG style configuration string
493
 */
494
void Pass::GenerateGPGKeys(QString batch) {
1 ✔
495
  const QString gpgPath = m_settings.gpgExecutable;
496
  if (gpgPath.isEmpty()) {
1 ✔
497
    // No gpg configured: executeWrapper would hand an empty executable to the
498
    // Executor, which silently drops it (see Executor::execute), leaving the
499
    // keygen dialog spinning with no feedback. Surface the misconfiguration
500
    // instead. Deferred via a queued call so we do not re-enter
501
    // KeygenDialog::done(), which drives key generation synchronously.
502
    QMetaObject::invokeMethod(
1 ✔
503
        this,
504
        [this]() {
1 ✔
505
          emit processErrorExit(1, tr("No GPG executable configured"));
1 ✔
506
        },
1 ✔
507
        Qt::QueuedConnection);
508
    return;
509
  }
510

511
  // Kill any stale GPG agents that might be holding locks on the key database.
512
  // This helps avoid "database locked" timeouts during key generation.
513
  ResolvedGpgconfCommand resolvedGpgconf = resolveGpgconfCommand(gpgPath);
×
514
  QStringList killArgs = resolvedGpgconf.arguments;
515
  killArgs << "--kill";
×
516
  killArgs << "gpg-agent";
×
517
  // Use same environment as key generation to target correct gpg-agent
518
  if (Executor::executeBlocking(env, resolvedGpgconf.program, killArgs) != 0) {
×
519
    qWarning() << "Failed to kill gpg-agent";
×
520
  }
521

522
  executeWrapper(GPG_GENKEYS, gpgPath, {"--gen-key", "--no-tty", "--batch"},
×
523
                 std::move(batch), true, true);
524
}
525

526
/**
527
 * @brief Pass::listKeys list users
528
 * @param keystrings
529
 * @param secret list private keys
530
 * @return QList<UserInfo> users
531
 */
532
auto Pass::listKeys(QStringList keystrings, bool secret) -> QList<UserInfo> {
7 ✔
533
  QStringList args = {"--no-tty", "--with-colons", "--with-fingerprint"};
49 ✔
534
  args.append(secret ? "--list-secret-keys" : "--list-keys");
16 ✔
535

536
  for (const QString &keystring : std::as_const(keystrings)) {
14 ✔
537
    if (!keystring.isEmpty()) {
7 ✔
538
      args.append(keystring);
539
    }
540
  }
541
  QString p_out;
7 ✔
542
  if (Executor::executeBlocking(m_settings.gpgExecutable, args, &p_out) != 0) {
7 ✔
543
    return {};
×
544
  }
545
  return parseGpgColonOutput(p_out, secret);
7 ✔
546
}
547

548
/**
549
 * @brief Pass::listKeys list users
550
 * @param keystring
551
 * @param secret list private keys
552
 * @return QList<UserInfo> users
553
 */
554
auto Pass::listKeys(const QString &keystring, bool secret) -> QList<UserInfo> {
6 ✔
555
  return listKeys(QStringList(keystring), secret);
12 ✔
556
}
557

558
/**
559
 * @brief Maps GPG stderr (which may include --status-fd 2 tokens) to a
560
 * user-friendly encryption error string.
561
 *
562
 * Checked in order: machine-readable [GNUPG:] status tokens first (locale-
563
 * independent), then case-insensitive substring fallbacks for GPG builds that
564
 * don't emit status tokens.
565
 *
566
 * @param err Raw stderr from GPG
567
 * @return Translated human-readable error, or empty string if not recognised
568
 */
569
namespace {
570

571
/**
572
 * @brief Checks if @p str contains any of the @p patterns (case-sensitive).
573
 * @param str String to search in.
574
 * @param patterns Patterns to search for.
575
 * @return true if any pattern is found, false otherwise.
576
 */
577
auto containsAny(const QString &str, const QStringList &patterns) -> bool {
34 ✔
578
  for (const QString &p : patterns) {
91 ✔
579
    if (str.contains(p)) {
64 ✔
580
      return true;
581
    }
582
  }
583
  return false;
584
}
585

586
/**
587
 * @brief Checks if str contains any of the patterns (case-insensitive).
588
 * @param str String to search in (will be lowercased once).
589
 * @param patterns List of patterns to search for (must be lowercase; caller
590
 * should convert patterns to lowercase before calling).
591
 * @return true if any pattern is found.
592
 */
593
auto containsAnyCaseInsensitive(const QString &str, const QStringList &patterns)
17 ✔
594
    -> bool {
595
  const QString lower = str.toLower();
596
  for (const QString &p : patterns) {
44 ✔
597
    if (lower.contains(p)) {
31 ✔
598
      return true;
599
    }
600
  }
601
  return false;
602
}
603

604
} // namespace
605

606
auto gpgErrorMessage(const QString &err) -> QString {
14 ✔
607
  // Machine-readable status tokens added by --status-fd 2
608
  if (containsAny(err, {QStringLiteral("[GNUPG:] KEYEXPIRED"),
70 ✔
609
                        QStringLiteral("[GNUPG:] INV_RECP 5 ")}))
14 ✔
610
    return QCoreApplication::translate(
611
        "Pass", "Encryption failed: GPG key has expired. Please renew or "
612
                "replace it.");
3 ✔
613
  if (containsAny(err, {QStringLiteral("[GNUPG:] KEYREVOKED"),
55 ✔
614
                        QStringLiteral("[GNUPG:] INV_RECP 4 ")}))
11 ✔
615
    return QCoreApplication::translate(
616
        "Pass", "Encryption failed: GPG key has been revoked.");
2 ✔
617
  if (containsAny(err, {QStringLiteral("[GNUPG:] NO_PUBKEY"),
45 ✔
618
                        QStringLiteral("[GNUPG:] INV_RECP")}))
9 ✔
619
    return QCoreApplication::translate(
620
        "Pass", "Encryption failed: recipient GPG key not found or invalid. "
621
                "Check that the key ID in .gpg-id is correct and imported.");
2 ✔
622
  if (err.contains(QStringLiteral("[GNUPG:] FAILURE")))
7 ✔
623
    return QCoreApplication::translate(
624
        "Pass", "Encryption failed. Check that your GPG key is valid.");
1 ✔
625

626
  // Locale-dependent fallbacks
627
  if (containsAnyCaseInsensitive(err, {QLatin1String("key has expired"),
24 ✔
628
                                       QLatin1String("key expired")}))
629
    return QCoreApplication::translate(
630
        "Pass", "Encryption failed: GPG key has expired. Please renew or "
631
                "replace it.");
1 ✔
632
  if (containsAnyCaseInsensitive(err, {QLatin1String("key has been revoked"),
20 ✔
633
                                       QLatin1String("revoked")}))
634
    return QCoreApplication::translate(
635
        "Pass", "Encryption failed: GPG key has been revoked.");
1 ✔
636
  if (containsAnyCaseInsensitive(err, {QLatin1String("no public key"),
20 ✔
637
                                       QLatin1String("unusable public key"),
638
                                       QLatin1String("no secret key")}))
639
    return QCoreApplication::translate(
640
        "Pass", "Encryption failed: recipient GPG key not found or invalid. "
641
                "Check that the key ID in .gpg-id is correct and imported.");
2 ✔
642
  if (containsAnyCaseInsensitive(err, {QLatin1String("encryption failed")}))
6 ✔
643
    return QCoreApplication::translate(
644
        "Pass", "Encryption failed. Check that your GPG key is valid.");
×
645

646
  return {};
2 ✔
647
}
×
648

649
namespace {
650
/**
651
 * @brief Determine whether a line from `pass grep` output is an entry header.
652
 *
653
 * Detects the ANSI blue escape (\x1B[94m) emitted by `pass grep`; as a
654
 * plain-text fallback, treats a non-indented line ending in ':' as a header.
655
 *
656
 * @param rawLine Original unmodified output line (with any ANSI codes).
657
 * @param trimmedLine The line after surrounding whitespace has been stripped.
658
 * @return true if the line is an entry header; otherwise false.
659
 */
660
auto isGrepHeaderLine(const QString &rawLine, const QString &trimmedLine)
45 ✔
661
    -> bool {
662
  return rawLine.startsWith(QStringLiteral("\x1B[94m")) ||
123 ✔
663
         (!rawLine.startsWith(' ') && !rawLine.startsWith('\t') &&
91 ✔
664
          trimmedLine.endsWith(':'));
119 ✔
665
}
666
} // namespace
667

668
/**
669
 * @brief Parses 'pass grep' raw output into (entry, matches) pairs.
670
 *
671
 * pass grep emits ANSI blue color (\x1B[94m) at the start of each entry
672
 * header line. This is checked before stripping ANSI so headers are detected
673
 * reliably regardless of locale.
674
 */
675
auto parseGrepOutput(const QString &rawOut)
12 ✔
676
    -> QList<QPair<QString, QStringList>> {
677
  static const QRegularExpression ansi(
678
      QStringLiteral(R"(\x1B\[[0-9;]*[a-zA-Z])"));
14 ✔
679
  QList<QPair<QString, QStringList>> results;
12 ✔
680
  QString currentEntry;
12 ✔
681
  QStringList currentMatches;
12 ✔
682
  for (const QString &rawLine : rawOut.split('\n')) {
69 ✔
683
    QString line = rawLine;
684
    line.remove('\r');
45 ✔
685
    line.remove(ansi);
45 ✔
686
    line = line.trimmed();
45 ✔
687
    const bool isHeader = isGrepHeaderLine(rawLine, line);
45 ✔
688
    if (isHeader) {
45 ✔
689
      if (!currentEntry.isEmpty() && !currentMatches.isEmpty())
14 ✔
690
        results.append({currentEntry, currentMatches});
3 ✔
691
      currentEntry = line.endsWith(':') ? line.chopped(1) : line;
14 ✔
692
      currentMatches.clear();
14 ✔
693
    } else if (!currentEntry.isEmpty()) {
31 ✔
694
      if (!line.isEmpty())
29 ✔
695
        currentMatches << line;
696
    }
697
  }
698
  if (!currentEntry.isEmpty() && !currentMatches.isEmpty())
12 ✔
699
    results.append({currentEntry, currentMatches});
11 ✔
700
  return results;
12 ✔
701
}
702

703
/**
704
 * @brief Pass::processFinished reemits specific signal based on what process
705
 * has finished
706
 * @param id    id of Pass process that was scheduled and finished
707
 * @param exitCode  return code of a process
708
 * @param out   output generated by process(if capturing was requested, empty
709
 *              otherwise)
710
 * @param err   error output generated by process(if capturing was requested,
711
 *              or error occurred)
712
 */
713
void Pass::finished(int id, int exitCode, const QString &out,
65 ✔
714
                    const QString &err) {
715
  auto pid = static_cast<PROCESS>(id);
65 ✔
716

717
  if (exitCode != 0) {
65 ✔
718
    handleProcessError(pid, exitCode, out, err);
5 ✔
719
    return;
5 ✔
720
  }
721

722
  emitProcessFinishedSignal(pid, out, err);
60 ✔
723
}
724

725
void Pass::handleProcessError(PROCESS pid, int exitCode, const QString &out,
5 ✔
726
                              const QString &err) {
727
  Q_UNUSED(out);
728

729
  if (pid == PASS_GREP) {
5 ✔
730
    handleGrepError(exitCode, err);
2 ✔
731
    return;
2 ✔
732
  }
733

734
  if (pid == PASS_INSERT) {
3 ✔
735
    const QString friendly = gpgErrorMessage(err);
1 ✔
736
    const QString why =
737
        friendly.isEmpty() ? err : formatInsertError(friendly, err);
1 ✔
738
    emit insertFailed(why, insertWritten());
1 ✔
739
    emit processErrorExit(exitCode, why);
1 ✔
740
    return;
741
  }
742

743
  emit processErrorExit(exitCode, err);
2 ✔
744
}
745

746
void Pass::handleGrepError(int exitCode, const QString &err) {
2 ✔
747
  if (exitCode == 1) {
2 ✔
748
    emit finishedGrep({});
2 ✔
749
  } else {
750
    emit processErrorExit(exitCode, err);
1 ✔
751
    emit finishedGrep({});
2 ✔
752
  }
753
}
2 ✔
754

755
auto Pass::formatInsertError(const QString &friendly, const QString &err)
×
756
    -> QString {
757
  QStringList humanLines;
×
758
  for (const QString &line : err.split('\n')) {
×
759
    QString cleanedLine = line;
760
    cleanedLine.remove('\r');
×
761
    if (!cleanedLine.startsWith(QLatin1String("[GNUPG:]")))
×
762
      humanLines.append(cleanedLine);
763
  }
764
  const QString humanErr = humanLines.join('\n').trimmed();
×
765
  return humanErr.isEmpty() ? friendly : friendly + "\n\n" + humanErr;
×
766
}
767

768
/**
769
 * @brief Emit the appropriate finished signal for a completed subprocess.
770
 *
771
 * Emits a specific Qt signal corresponding to the given process identifier; for
772
 * grep results the stdout is parsed into a list of matches before emitting.
773
 *
774
 * @param pid The process identifier indicating which finished signal to emit.
775
 * @param out Standard output produced by the process.
776
 * @param err Standard error produced by the process.
777
 */
778
void Pass::emitProcessFinishedSignal(PROCESS pid, const QString &out,
60 ✔
779
                                     const QString &err) {
780
  /**
781
   * @brief Filter sensitive commands to prevent password leakage.
782
   *
783
   * Sensitive commands (PASS_SHOW, etc.) output plaintext passwords or
784
   * searchable content that should not be exposed to any UI listener.
785
   *
786
   * Using a default branch: if new PASS_* values are added, they
787
   * default to NOT leaking (safe by default). Making this
788
   * exhaustive would require updating here for every new
789
   * command and risk silent password leakage if forgotten.
790
   */
791
  switch (pid) {
60 ✔
792
  case PASS_SHOW:
793
  case PASS_OTP_GENERATE:
794
  case PASS_GREP:
795
  case PASS_INSERT:
796
    break;
797
  default:
1 ✔
798
    emit finishedAny(out, err);
1 ✔
799
    emit finishedAnyWithPid(out, err, pid);
1 ✔
800
    break;
1 ✔
801
  }
802

803
  switch (pid) {
60 ✔
804
  case GIT_INIT:
×
805
    emit finishedGitInit(out, err);
×
806
    break;
×
807
  case GIT_PULL:
×
808
    emit finishedGitPull(out, err);
×
809
    break;
×
810
  case GIT_PUSH:
×
811
    emit finishedGitPush(out, err);
×
812
    break;
×
813
  case PASS_SHOW:
20 ✔
814
    emit finishedShow(out);
20 ✔
815
    break;
20 ✔
816
  case PASS_OTP_GENERATE:
×
817
    emit finishedOtpGenerate(out);
×
818
    break;
×
819
  case PASS_INSERT:
38 ✔
820
    emit finishedInsert(out, err);
38 ✔
821
    break;
38 ✔
822
  case PASS_REMOVE:
×
823
    emit finishedRemove(out, err);
×
824
    break;
×
825
  case PASS_INIT:
1 ✔
826
    emit finishedInit(out, err);
1 ✔
827
    break;
1 ✔
828
  case PASS_MOVE:
×
829
    emit finishedMove(out, err);
×
830
    break;
×
831
  case PASS_COPY:
×
832
    emit finishedCopy(out, err);
×
833
    break;
×
834
  case GPG_GENKEYS:
×
835
    emit finishedGenerateGPGKeys(out, err);
×
836
    break;
×
837
  case PASS_GREP:
1 ✔
838
    emit finishedGrep(parseGrepOutput(out));
1 ✔
839
    break;
1 ✔
840
  default:
841
#ifdef QT_DEBUG
842
    dbg() << "Unhandled process type" << pid;
843
#endif
844
    break;
845
  }
846
}
60 ✔
847

848
/**
849
 * @brief Set or remove a single environment variable in the local env list.
850
 *
851
 * The provided key must include a trailing '=' (e.g. "FOO="). Existing entries
852
 * whose text begins with the given key are removed before the new value is
853
 * applied. If value is non-empty the pair "key+value" is appended; if value is
854
 * empty the variable is removed.
855
 *
856
 * The function asserts if key does not end with '='; if the assertion is not
857
 * active it will emit a warning and return without modifying env.
858
 *
859
 * @param key Environment variable name with trailing '=' (anchors the lookup).
860
 * @param value Value to set for the variable; an empty string unsets the
861
 * variable.
862
 */
863
void Pass::setEnvVar(const QString &key, const QString &value) {
361 ✔
864
  const bool hasEq = key.endsWith('=');
361 ✔
865
  Q_ASSERT_X(hasEq, "Pass::setEnvVar",
866
             "called with malformed key (missing '=')");
867
  if (!hasEq) {
361 ✔
868
    qWarning() << "Pass::setEnvVar called with malformed key (missing '='):"
×
869
               << key;
×
870
    return;
×
871
  }
872
  const QString varName = key.chopped(1);
873
  if (value.isEmpty())
361 ✔
874
    env.remove(varName);
82 ✔
875
  else
876
    env.insert(varName, value);
279 ✔
877
}
878

879
/**
880
 * @brief Update the process environment used for executing external commands.
881
 *
882
 * Updates environment entries for PASSWORD_STORE_SIGNING_KEY,
883
 * PASSWORD_STORE_DIR, PASSWORD_STORE_GENERATED_LENGTH, and
884
 * PASSWORD_STORE_CHARACTER_SET based on current settings, then applies the
885
 * environment to the internal executor.
886
 */
887
void Pass::updateEnv() {
71 ✔
888
  setEnvVar(QStringLiteral("PASSWORD_STORE_SIGNING_KEY="),
142 ✔
889
            m_settings.passSigningKey);
71 ✔
890
  setEnvVar(QStringLiteral("PASSWORD_STORE_DIR="), m_settings.passStore);
142 ✔
891

892
  const PasswordConfiguration &passConfig = m_settings.passwordConfiguration;
71 ✔
893
  setEnvVar(QStringLiteral("PASSWORD_STORE_GENERATED_LENGTH="),
142 ✔
894
            QString::number(passConfig.length));
71 ✔
895

896
  setEnvVar(QStringLiteral("PASSWORD_STORE_CHARACTER_SET="),
142 ✔
897
            effectiveCharset(passConfig));
71 ✔
898

899
  // pass hands PASSWORD_STORE_GPG_OPTS to every gpg it runs: the user's own
900
  // options (split as pass's shell splits them: spaces, tabs, newlines),
901
  // then the output limit ImitatePass passes directly.
902
  QStringList gpgOpts = QProcessEnvironment::systemEnvironment()
71 ✔
903
                            .value(QStringLiteral("PASSWORD_STORE_GPG_OPTS"))
142 ✔
904
                            .split(QRegularExpression(QStringLiteral("\\s+")),
142 ✔
905
                                   Qt::SkipEmptyParts);
142 ✔
906
  gpgOpts << maxOutputArgs();
142 ✔
907
  setEnvVar(QStringLiteral("PASSWORD_STORE_GPG_OPTS="),
142 ✔
908
            gpgOpts.join(QLatin1Char(' ')));
71 ✔
909

910
  exec.setEnvironment(env);
71 ✔
911
}
71 ✔
912

913
auto Pass::maxOutputArgs() -> QStringList {
131 ✔
914
  return {QStringLiteral("--max-output"), QString::number(kMaxPlaintextBytes)};
393 ✔
915
}
131 ✔
916

917
/**
918
 * @brief Pass::getGpgIdPath return gpgid file path for some file (folder).
919
 * @param for_file which file (folder) would you like the gpgid file path for.
920
 * @return path to the gpgid file.
921
 */
922
auto Pass::getGpgIdPath(const QString &for_file, const QString &passStore)
118 ✔
923
    -> QString {
924
  QString normalizedStore = QDir::fromNativeSeparators(passStore);
118 ✔
925
  QString normalizedFile = QDir::fromNativeSeparators(for_file);
118 ✔
926
  QString fullPath = normalizedFile.startsWith(normalizedStore)
118 ✔
927
                         ? normalizedFile
118 ✔
928
                         : normalizedStore + "/" + normalizedFile;
75 ✔
929
  QDir gpgIdDir(QFileInfo(fullPath).absoluteDir());
118 ✔
930
  // QDir::cleanPath() always normalises to forward slashes, so use '/'
931
  // here rather than QDir::separator() (which returns '\\' on Windows).
932
  QString cleanPassStore = QDir::cleanPath(normalizedStore);
118 ✔
933
  bool found = false;
934
  while (gpgIdDir.exists()) {
146 ✔
935
    QString currentPath = QDir::cleanPath(gpgIdDir.absolutePath());
145 ✔
936
    const QString prefix =
937
        cleanPassStore.endsWith('/') ? cleanPassStore : cleanPassStore + "/";
145 ✔
938
    if (currentPath != cleanPassStore && !currentPath.startsWith(prefix)) {
145 ✔
939
      break;
940
    }
941
    if (QFile(gpgIdDir.absoluteFilePath(".gpg-id")).exists()) {
268 ✔
942
      found = true;
943
      break;
944
    }
945
    if (!gpgIdDir.cdUp()) {
28 ✔
946
      break;
947
    }
948
  }
949
  return found ? gpgIdDir.absoluteFilePath(".gpg-id")
236 ✔
950
               : QDir(normalizedStore).filePath(".gpg-id");
248 ✔
951
}
118 ✔
952

953
/**
954
 * @brief Pass::getRecipientList return list of gpg-id's to encrypt for
955
 * @param for_file which file (folder) would you like recipients for
956
 * @return recipients gpg-id contents
957
 */
958
auto Pass::getRecipientList(const QString &for_file, const QString &passStore)
65 ✔
959
    -> QStringList {
960
  QFile gpgId(getGpgIdPath(for_file, passStore));
65 ✔
961
  if (!gpgId.open(QIODevice::ReadOnly | QIODevice::Text)) {
65 ✔
962
    return {};
1 ✔
963
  }
964
  QStringList recipients;
64 ✔
965
  while (!gpgId.atEnd()) {
151 ✔
966
    QString recipient(gpgId.readLine());
87 ✔
967
    recipient = recipient.split("#")[0].trimmed();
174 ✔
968
    if (recipient.isEmpty()) {
87 ✔
969
      continue;
7 ✔
970
    }
971
    if (!Util::isValidKeyId(recipient)) {
80 ✔
972
      // Never drop a recipient silently: the list is written back verbatim
973
      // by UsersDialog, so a skipped line disappears from .gpg-id.
974
      qWarning() << "Skipping unusable recipient in" << gpgId.fileName() << ":"
4 ✔
975
                 << recipient;
2 ✔
976
      continue;
2 ✔
977
    }
978
    recipients += recipient;
979
  }
980
  return recipients;
981
}
65 ✔
982

983
/**
984
 * @brief Pass::getRecipientString formatted string for use with GPG
985
 * @param for_file which file (folder) would you like recipients for
986
 * @param separator formatting separator eg: " -r "
987
 * @param count
988
 * @return recipient string
989
 */
990
auto Pass::getRecipientString(const QString &for_file, const QString &passStore,
3 ✔
991
                              const QString &separator, int *count)
992
    -> QStringList {
993
  Q_UNUSED(separator)
994
  QStringList recipients = Pass::getRecipientList(for_file, passStore);
3 ✔
995
  if (count) {
3 ✔
996
    *count = static_cast<int>(recipients.size());
2 ✔
997
  }
998
  return recipients;
3 ✔
999
}
1000

1001
/**
1002
 * @brief Pass::seedGpgIdFile write the inherited recipients into a new
1003
 * folder's .gpg-id
1004
 * @param newDir absolute path of the freshly created folder
1005
 * @param passStore root directory of the password store
1006
 * @return true when newDir/.gpg-id was written
1007
 */
1008
auto Pass::seedGpgIdFile(const QString &newDir, const QString &passStore)
5 ✔
1009
    -> bool {
1010
  const QString gpgIdFile = QDir(newDir).absoluteFilePath(".gpg-id");
10 ✔
1011
  if (QFileInfo::exists(gpgIdFile)) {
5 ✔
1012
    return false;
1013
  }
1014
  // Resolve from the file we are about to create: getGpgIdPath walks up from
1015
  // its directory, so this yields the parent's .gpg-id whether or not newDir
1016
  // carries a trailing separator.
1017
  const QStringList recipients = getRecipientList(gpgIdFile, passStore);
4 ✔
1018
  if (recipients.isEmpty()) {
4 ✔
1019
    return false;
1020
  }
1021
  QSaveFile gpgId(gpgIdFile);
2 ✔
1022
  if (!gpgId.open(QIODevice::WriteOnly)) {
2 ✔
1023
    return false;
1024
  }
1025
  QTextStream out(&gpgId);
2 ✔
1026
  for (const QString &recipient : recipients) {
5 ✔
1027
    out << recipient << '\n';
3 ✔
1028
  }
1029
  out.flush();
2 ✔
1030
  if (out.status() != QTextStream::Ok || !gpgId.commit()) {
2 ✔
1031
    return false;
×
1032
  }
1033
  // Lock to owner-only access; see ImitatePass::writeGpgIdFile for the
1034
  // rationale (NFS / USB / unusual umask). Best-effort where setPermissions
1035
  // is a no-op.
1036
  QFile::setPermissions(gpgIdFile, QFile::ReadOwner | QFile::WriteOwner);
2 ✔
1037
  return true;
1038
}
2 ✔
1039

1040
/* Copyright (C) 2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
1041
 */
1042

1043
/**
1044
 * @brief Generates a random number bounded by the given value.
1045
 * @param bound Upper bound (exclusive)
1046
 * @return Random number in range [0, bound)
1047
 */
1048
auto Pass::boundedRandom(quint32 bound) -> quint32 {
7,592 ✔
1049
  if (bound < 2) {
7,592 ✔
1050
    return 0;
1051
  }
1052

1053
  quint32 randval;
1054
  // Rejection-sampling threshold to avoid modulo bias.
1055
  // This follows the well-known "arc4random_uniform"-style approach:
1056
  // reject values in the low range [0, min), where
1057
  //   min = 2^32 % bound
1058
  // so that the remaining range size is an exact multiple of `bound`.
1059
  //
1060
  // In quint32 arithmetic, (1 + ~bound) wraps to (2^32 - bound), therefore
1061
  //   (1 + ~bound) % bound == 2^32 % bound.
1062
  const quint32 rejectionThreshold = (1 + ~bound) % bound;
7,592 ✔
1063

1064
  do {
1065
    randval = QRandomGenerator::system()->generate();
1066
  } while (randval < rejectionThreshold);
7,592 ✔
1067

1068
  return randval % bound;
7,592 ✔
1069
}
1070

1071
/**
1072
 * @brief Generates a random password from the given charset.
1073
 * @param charset Characters to use in the password
1074
 * @param length Desired password length
1075
 * @return Generated password string
1076
 */
1077
auto Pass::generateRandomPassword(const QString &charset, unsigned int length)
1,204 ✔
1078
    -> QString {
1079
  if (charset.isEmpty() || length == 0U) {
1,204 ✔
1080
    return {};
×
1081
  }
1082
  QString out;
1,204 ✔
1083
  for (unsigned int i = 0; i < length; ++i) {
8,796 ✔
1084
    out.append(charset.at(static_cast<int>(
7,592 ✔
1085
        boundedRandom(static_cast<quint32>(charset.length())))));
7,592 ✔
1086
  }
1087
  return out;
1088
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc