Dialog for importing GPG keys from file or clipboard.
More...
#include <importkeydialog.h>
|
| static auto | parseGpgImportOutput (const QString &output) -> QString |
| | Parse GPG import output to extract a key id or fingerprint.
|
| static auto | keysInBlock (const QString &listing) -> BlockKeys |
| | Count the keys in the listing of gpg --with-colons --import-options show-only --import.
|
| 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.
|
|
| static constexpr int | kImportTimeoutMs = 60000 |
| | How long gpg may take to import before it is stopped: the import runs on the GUI thread, and a key crafted with many user IDs kept gpg busy for minutes, the window and its autoclear timers frozen with it.
|
| static constexpr qsizetype | kMaxKeyLine = 1024 |
| | Longest line fitsTheEditor() lets through, in characters.
|
| static constexpr qsizetype | kMaxKeyLines = 16 * 1024 * 1024 / 64 |
| | Most lines fitsTheEditor() lets through: a 16 MiB key file in armor's 64-character lines.
|
|
| void | on_fileButton_clicked () |
| | "From file" button: picks a file, reads it as a regular file of at most 16 MiB, requires the -----BEGIN PGP armor header and loads the text into the input field. Binary keyrings are refused with a hint to gpg --armor --export first, and text that fails fitsTheEditor() with the limits it broke.
|
| void | on_pasteButton_clicked () |
| | "From clipboard" button: replaces the input field with the clipboard text, unless the clipboard is empty or the text fails fitsTheEditor().
|
| void | on_importButton_clicked () |
| | "Import" button: runs importFromString() on the trimmed input and closes the dialog with accept() on success.
|
| void | on_inputTextEdit_textChanged () |
| | Enables the Import button only while the input field holds non-blank text.
|
|
| 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 more than one key. Then feeds it to gpg --no-options --status-fd 1 --import --batch --yes via Executor::executeBlocking() and records the imported key id. Neither run reads gpg.conf, so options there cannot make the listing and the import see different keys.
|
| 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.
|
| 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 markup).
|
| void | showSuccess (const QString &keyId) |
| | Shows the "imported, now verify the fingerprint" information box.
|
|
| QScopedPointer< Ui::ImportKeyDialog > | ui |
| | Generated form (importkeydialog.ui); owned.
|
| QString | m_importedKeyId |
| | Key id or fingerprint of the last successful import; empty until then. Read back through importedKeyId().
|
| QString | m_gpgExe |
| | Path of the gpg binary to run; empty means plain gpg on PATH.
|
| int | m_timeoutMs |
| | Most milliseconds gpg may take to import (kImportTimeoutMs).
|
Dialog for importing GPG keys from file or clipboard.
Allows users to import GPG public keys without leaving QtPass. Offers two import paths: from file or from clipboard text.
Definition at line 29 of file importkeydialog.h.
◆ ImportKeyDialog()
| ImportKeyDialog::ImportKeyDialog |
( |
QString | gpgExe, |
|
|
QWidget * | parent = nullptr, |
|
|
int | timeoutMs = kImportTimeoutMs ) |
|
explicit |
Construct an ImportKeyDialog.
- Parameters
-
| gpgExe | Path to the gpg executable (falls back to "gpg" if empty). |
| parent | Optional parent widget. |
| timeoutMs | Most milliseconds gpg may take to import. |
Definition at line 40 of file importkeydialog.cpp.
◆ ~ImportKeyDialog()
| ImportKeyDialog::~ImportKeyDialog |
( |
| ) |
|
|
overridedefault |
Destroys the dialog and its generated UI.
◆ fitsTheEditor()
| auto ImportKeyDialog::fitsTheEditor |
( |
QStringView | text | ) |
-> bool |
|
staticnodiscard |
Whether text is laid out as armor can be, so the input field can show it at a bounded cost.
Armor lines are 64 characters (76 at most) and a header line not much longer. A line without break opportunity takes Qt time growing with the square of its length to wrap, and each line costs the editor some 440 bytes, so a file of one long line or of line breaks only froze or filled the GUI before gpg ever saw it.
- Parameters
-
| text | The text to show. A line ends where the editor starts a new one: LF, CR (CRLF once), U+2028, U+2029, U+FDD0 and U+FDD1. |
- Returns
- False when a line is longer than kMaxKeyLine or there are more than kMaxKeyLines lines.
Definition at line 57 of file importkeydialog.cpp.
◆ importedKeyId()
| auto ImportKeyDialog::importedKeyId |
( |
| ) |
const -> QString |
Get the imported key id on success.
- Returns
- The imported key id (or fingerprint when GnuPG status output provides one), or empty if import failed.
Definition at line 49 of file importkeydialog.cpp.
◆ importFromString()
| bool ImportKeyDialog::importFromString |
( |
const QString & | input | ) |
-> bool |
|
private |
Lists the keys in input first, with nothing written, and refuses a block that holds a private key or more than one key. Then feeds it to gpg --no-options --status-fd 1 --import --batch --yes via Executor::executeBlocking() and records the imported key id. Neither run reads gpg.conf, so options there cannot make the listing and the import see different keys.
- Parameters
-
| input | Armored key text, trimmed. |
- Returns
- true when the block held one public key, gpg exited with 0 and a key id could be parsed from its output; false after showError() otherwise.
Definition at line 193 of file importkeydialog.cpp.
◆ keysInBlock()
| auto ImportKeyDialog::keysInBlock |
( |
const QString & | listing | ) |
-> BlockKeys |
|
static |
Count the keys in the listing of gpg --with-colons --import-options show-only --import.
Only the primary-key records count (pub and sec); subkeys, user IDs and fingerprints belong to the key before them.
- Parameters
-
| listing | gpg's colon listing of the block. |
- Returns
- The public and the secret keys in it.
Definition at line 281 of file importkeydialog.cpp.
◆ on_fileButton_clicked
| void ImportKeyDialog::on_fileButton_clicked |
( |
| ) |
|
|
privateslot |
"From file" button: picks a file, reads it as a regular file of at most 16 MiB, requires the -----BEGIN PGP armor header and loads the text into the input field. Binary keyrings are refused with a hint to gpg --armor --export first, and text that fails fitsTheEditor() with the limits it broke.
Definition at line 100 of file importkeydialog.cpp.
◆ on_importButton_clicked
| void ImportKeyDialog::on_importButton_clicked |
( |
| ) |
|
|
privateslot |
◆ on_inputTextEdit_textChanged
| void ImportKeyDialog::on_inputTextEdit_textChanged |
( |
| ) |
|
|
privateslot |
Enables the Import button only while the input field holds non-blank text.
Definition at line 188 of file importkeydialog.cpp.
◆ on_pasteButton_clicked
| void ImportKeyDialog::on_pasteButton_clicked |
( |
| ) |
|
|
privateslot |
"From clipboard" button: replaces the input field with the clipboard text, unless the clipboard is empty or the text fails fitsTheEditor().
Definition at line 161 of file importkeydialog.cpp.
◆ parseGpgImportOutput()
| auto ImportKeyDialog::parseGpgImportOutput |
( |
const QString & | output | ) |
-> QString |
|
static |
Parse GPG import output to extract a key id or fingerprint.
Prefers locale-independent status lines ([GNUPG:] IMPORT_OK and [GNUPG:] IMPORTED) when present, then falls back to the human-readable "gpg: key ...: imported" line (English locale only).
- Parameters
-
| output | Combined stdout/stderr from gpg --import --status-fd 1. |
- Returns
- The imported key id or fingerprint, or empty if not found.
Definition at line 294 of file importkeydialog.cpp.
◆ runGpg()
| auto ImportKeyDialog::runGpg |
( |
const QStringList & | args, |
|
|
const QString & | input, |
|
|
QString * | stdOut, |
|
|
QString * | stdErr, |
|
|
const QElapsedTimer & | timer ) -> bool |
|
private |
Runs gpg with args on input within what is left of m_timeoutMs since timer started.
- Parameters
-
| args | gpg's arguments. |
| input | Text for gpg's stdin. |
| stdOut | Receives gpg's stdout. |
| stdErr | Receives gpg's stderr. |
| timer | Started when the import began. |
- Returns
- true when gpg exited with 0; false after showError() otherwise.
Definition at line 255 of file importkeydialog.cpp.
◆ showError()
| void ImportKeyDialog::showError |
( |
const QString & | message | ) |
|
|
private |
Shows message in a plain-text warning box (gpg's stderr quotes user IDs, which must not be read as markup).
- Parameters
-
Definition at line 345 of file importkeydialog.cpp.
◆ showSuccess()
| void ImportKeyDialog::showSuccess |
( |
const QString & | keyId | ) |
|
|
private |
Shows the "imported, now verify the fingerprint" information box.
- Parameters
-
| keyId | The imported key id or fingerprint. |
Definition at line 351 of file importkeydialog.cpp.
◆ kImportTimeoutMs
| int ImportKeyDialog::kImportTimeoutMs = 60000 |
|
staticconstexpr |
How long gpg may take to import before it is stopped: the import runs on the GUI thread, and a key crafted with many user IDs kept gpg busy for minutes, the window and its autoclear timers frozen with it.
Definition at line 38 of file importkeydialog.h.
◆ kMaxKeyLine
| qsizetype ImportKeyDialog::kMaxKeyLine = 1024 |
|
staticconstexpr |
◆ kMaxKeyLines
| qsizetype ImportKeyDialog::kMaxKeyLines = 16 * 1024 * 1024 / 64 |
|
staticconstexpr |
◆ m_gpgExe
| QString ImportKeyDialog::m_gpgExe |
|
private |
Path of the gpg binary to run; empty means plain gpg on PATH.
Definition at line 151 of file importkeydialog.h.
◆ m_importedKeyId
| QString ImportKeyDialog::m_importedKeyId |
|
private |
◆ m_timeoutMs
| int ImportKeyDialog::m_timeoutMs |
|
private |
Most milliseconds gpg may take to import (kImportTimeoutMs).
Definition at line 153 of file importkeydialog.h.
◆ ui
| QScopedPointer<Ui::ImportKeyDialog> ImportKeyDialog::ui |
|
private |
The documentation for this class was generated from the following files: