QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
importkeydialog.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_IMPORTKEYDIALOG_H_
9#define SRC_IMPORTKEYDIALOG_H_
10
11#include <QDialog>
12#include <QElapsedTimer>
13#include <QScopedPointer>
14#include <QString>
15#include <QStringList>
16
17namespace Ui {
18class ImportKeyDialog;
19}
20
29class ImportKeyDialog : public QDialog {
30 Q_OBJECT
31
32public:
38 static constexpr int kImportTimeoutMs = 60000;
39
46 explicit ImportKeyDialog(QString gpgExe, QWidget *parent = nullptr,
47 int timeoutMs = kImportTimeoutMs);
49 ~ImportKeyDialog() override;
50
56 auto importedKeyId() const -> QString;
57
68 static auto parseGpgImportOutput(const QString &output) -> QString;
69
73 struct BlockKeys {
75 int publicKeys = 0;
77 int secretKeys = 0;
78 };
79
90 static auto keysInBlock(const QString &listing) -> BlockKeys;
91
93 static constexpr qsizetype kMaxKeyLine = 1024;
96 static constexpr qsizetype kMaxKeyLines = 16 * 1024 * 1024 / 64;
97
113 [[nodiscard]] static auto fitsTheEditor(QStringView text) -> bool;
114
115private slots:
124
131
137
143
144private:
146 QScopedPointer<Ui::ImportKeyDialog> ui;
151 QString m_gpgExe;
154
167 auto importFromString(const QString &input) -> bool;
178 auto runGpg(const QStringList &args, const QString &input, QString *stdOut,
179 QString *stdErr, const QElapsedTimer &timer) -> bool;
185 void showError(const QString &message);
190 void showSuccess(const QString &keyId);
191};
192#endif // SRC_IMPORTKEYDIALOG_H_
static constexpr qsizetype kMaxKeyLines
Most lines fitsTheEditor() lets through: a 16 MiB key file in armor's 64-character lines.
static auto fitsTheEditor(QStringView text) -> bool
Whether text is laid out as armor can be, so the input field can show it at a bounded cost.
~ImportKeyDialog() override
Destroys the dialog and its generated UI.
static auto parseGpgImportOutput(const QString &output) -> QString
Parse GPG import output to extract a key id or fingerprint.
void showError(const QString &message)
Shows message in a plain-text warning box (gpg's stderr quotes user IDs, which must not be read as ma...
auto importedKeyId() const -> QString
Get the imported key id on success.
static auto keysInBlock(const QString &listing) -> BlockKeys
Count the keys in the listing of gpg --with-colons --import-options show-only --import.
int m_timeoutMs
Most milliseconds gpg may take to import (kImportTimeoutMs).
QString m_importedKeyId
Key id or fingerprint of the last successful import; empty until then. Read back through importedKeyI...
ImportKeyDialog(QString gpgExe, QWidget *parent=nullptr, int timeoutMs=kImportTimeoutMs)
Construct an ImportKeyDialog.
void on_fileButton_clicked()
"From file" button: picks a file, reads it as a regular file of at most 16 MiB, requires the -----BEG...
static constexpr int kImportTimeoutMs
How long gpg may take to import before it is stopped: the import runs on the GUI thread,...
auto runGpg(const QStringList &args, const QString &input, QString *stdOut, QString *stdErr, const QElapsedTimer &timer) -> bool
Runs gpg with args on input within what is left of m_timeoutMs since timer started.
QString m_gpgExe
Path of the gpg binary to run; empty means plain gpg on PATH.
void on_pasteButton_clicked()
"From clipboard" button: replaces the input field with the clipboard text, unless the clipboard is em...
void showSuccess(const QString &keyId)
Shows the "imported, now verify the fingerprint" information box.
QScopedPointer< Ui::ImportKeyDialog > ui
Generated form (importkeydialog.ui); owned.
auto importFromString(const QString &input) -> bool
Lists the keys in input first, with nothing written, and refuses a block that holds a private key or ...
void on_importButton_clicked()
"Import" button: runs importFromString() on the trimmed input and closes the dialog with accept() on ...
static constexpr qsizetype kMaxKeyLine
Longest line fitsTheEditor() lets through, in characters.
void on_inputTextEdit_textChanged()
Enables the Import button only while the input field holds non-blank text.
How many keys an armored block holds, by kind.
int publicKeys
Public keys: pub records.
int secretKeys
Keys with their secret part: sec records.