Handles GPG keypair generation.
More...
#include <keygendialog.h>
|
| static QString | applyPassphrase (const QString &batch, const QString &passphrase) |
| | Splice a passphrase into a GPG batch template.
|
| static auto | isBatchValue (const QString &value) -> bool |
| | Whether value can go into a GPG batch line as one value.
|
| static auto | hasBatchBreak (const QString &value) -> bool |
| | Whether a field's text holds a line break or NUL, which would end its batch line early.
|
| static auto | isBatchPassphrase (const QString &passphrase) -> bool |
| | Whether gpg reads passphrase back as typed from a batch Passphrase: line.
|
|
| void | on_passphrase1_textChanged (const QString &arg1) |
| | First passphrase field edited: re-evaluates whether OK may be enabled. The text itself stays out of the template box.
|
| void | on_passphrase2_textChanged (const QString &arg1) |
| | Confirmation field edited: same as on_passphrase1_textChanged().
|
| void | setNoPassphrase (bool checked) |
| | Ticking "no passphrase" clears and disables the passphrase fields and makes OK available; unticking it asks for one again.
|
| void | setExpertMode (bool checked) |
| | Enable or disable expert mode (the editable batch template).
|
| void | on_email_textChanged (const QString &arg1) |
| | Mirrors the e-mail field into the template's Name-Email: line.
|
| void | on_name_textChanged (const QString &arg1) |
| | Mirrors the name field into the template's Name-Real: line.
|
|
| void | updateOkState () |
| | OK is available when a passphrase is typed twice the same, or when no passphrase was asked for explicitly. Empty fields alone are not a choice: the key would be stored unprotected without anyone saying so.
|
| auto | passphraseChosen () const -> bool |
| | Whether the passphrase question has an answer: typed twice the same, or waived with the checkbox. Empty fields alone are neither.
|
| void | replace (const QString &key, const QString &value) |
| | Rewrites every <key>: ... line of the batch template to carry value. Values that fail isBatchValue() are ignored so a pasted line break can never become a directive of its own.
|
| void | done (int r) override |
| | On Accepted, validates the form (passphrase chosen, no line breaks, name of 5+ characters, plausible e-mail), swaps the form for the progress indicator and calls startGeneration(); the dialog only closes once the backend reports success. Any other result disconnects the backend signals and closes normally.
|
| void | startGeneration (const QString &batch) |
| | Connects to the backend's finished/failed signals for this one attempt and calls Pass::GenerateGPGKeys(). With no backend the attempt fails at once.
|
| void | generationFailed (const QString &error) |
| | Stops and hides the progress indicator, re-enables the form under the usual OK rule and shows error in the status label, so the user can correct the input and try again.
|
Handles GPG keypair generation.
The form asks for a name, an e-mail address and a passphrase typed twice (or an explicit "no passphrase"); an Expert checkbox reveals the editable GPG batch template that the name and e-mail fields are mirrored into. The passphrase is never written into that template: on OK, done() validates the fields, splices the passphrase in with applyPassphrase() and hands the batch to Pass::GenerateGPGKeys(), replacing the form with a progress indicator. The dialog owns nothing of the backend; it connects to Pass::finishedGenerateGPGKeys (accept) and Pass::generateGPGKeysFailed (show the error and give the form back) for the duration of one attempt only, so an exec() caller such as the first-run wizard sees Accepted exactly when a key exists.
Definition at line 40 of file keygendialog.h.
◆ KeygenDialog()
| KeygenDialog::KeygenDialog |
( |
const QString & | gpgExe, |
|
|
Pass * | pass, |
|
|
QWidget * | parent = nullptr ) |
|
explicit |
Construct a KeygenDialog.
- Parameters
-
| gpgExe | Path to the gpg executable (for the default template). |
| pass | Backend that runs gpg --gen-key; the dialog accepts on its finishedGenerateGPGKeys() and shows generateGPGKeysFailed(). |
| parent | Parent widget, or nullptr. |
Definition at line 23 of file keygendialog.cpp.
◆ ~KeygenDialog()
| KeygenDialog::~KeygenDialog |
( |
| ) |
|
|
overridedefault |
Destroys the dialog and its generated UI.
◆ applyPassphrase()
| QString KeygenDialog::applyPassphrase |
( |
const QString & | batch, |
|
|
const QString & | passphrase ) |
|
static |
Splice a passphrase into a GPG batch template.
Replaces no-protection (or an existing Passphrase: line) with "Passphrase: <passphrase>"; an empty passphrase yields no-protection.
- Parameters
-
| batch | GPG batch template text. |
| passphrase | Key passphrase, empty for an unprotected key. |
- Returns
- Batch text ready for gpg –gen-key –batch.
Definition at line 141 of file keygendialog.cpp.
◆ done()
| void KeygenDialog::done |
( |
int | r | ) |
|
|
overrideprivate |
On Accepted, validates the form (passphrase chosen, no line breaks, name of 5+ characters, plausible e-mail), swaps the form for the progress indicator and calls startGeneration(); the dialog only closes once the backend reports success. Any other result disconnects the backend signals and closes normally.
- Parameters
-
| r | The QDialog result code. |
Definition at line 219 of file keygendialog.cpp.
◆ generationFailed()
| void KeygenDialog::generationFailed |
( |
const QString & | error | ) |
|
|
private |
Stops and hides the progress indicator, re-enables the form under the usual OK rule and shows error in the status label, so the user can correct the input and try again.
- Parameters
-
| error | Backend error text; HTML-escaped before display. |
Definition at line 335 of file keygendialog.cpp.
◆ hasBatchBreak()
| auto KeygenDialog::hasBatchBreak |
( |
const QString & | value | ) |
-> bool |
|
staticnodiscard |
Whether a field's text holds a line break or NUL, which would end its batch line early.
The template box reads U+2028, U+2029, U+FDD0 and U+FDD1 back as LF, so those count as line breaks too.
- Parameters
-
- Returns
- True when it holds a CR, LF, NUL, U+2028, U+2029, U+FDD0 or U+FDD1.
Definition at line 190 of file keygendialog.cpp.
◆ isBatchPassphrase()
| auto KeygenDialog::isBatchPassphrase |
( |
const QString & | passphrase | ) |
-> bool |
|
staticnodiscard |
Whether gpg reads passphrase back as typed from a batch Passphrase: line.
gpg skips white space after the colon and cuts spaces and tabs off the end of a value, so a passphrase with a blank at either end would protect the key without it, and the passphrase typed twice is then refused. Only ASCII white space counts: gpg keeps a no-break space.
- Parameters
-
| passphrase | The passphrase typed; empty means none. |
- Returns
- False when it starts or ends with ASCII white space.
Definition at line 210 of file keygendialog.cpp.
◆ isBatchValue()
| auto KeygenDialog::isBatchValue |
( |
const QString & | value | ) |
-> bool |
|
staticnodiscard |
Whether value can go into a GPG batch line as one value.
The batch is line-oriented, and gpg reads a line as a C string: a line break or NUL in a name or passphrase would start a directive of its own (no-protection, a Passphrase: of the paster's choosing). Text that is not valid UTF-16 (a lone surrogate) is refused too: gpg gets no such text, only a replacement for it.
- Parameters
-
- Returns
- False when hasBatchBreak() finds a break, or it is not valid UTF-16.
Definition at line 181 of file keygendialog.cpp.
◆ on_email_textChanged
| void KeygenDialog::on_email_textChanged |
( |
const QString & | arg1 | ) |
|
|
privateslot |
Mirrors the e-mail field into the template's Name-Email: line.
- Parameters
-
Definition at line 82 of file keygendialog.cpp.
◆ on_name_textChanged
| void KeygenDialog::on_name_textChanged |
( |
const QString & | arg1 | ) |
|
|
privateslot |
Mirrors the name field into the template's Name-Real: line.
- Parameters
-
Definition at line 86 of file keygendialog.cpp.
◆ on_passphrase1_textChanged
| void KeygenDialog::on_passphrase1_textChanged |
( |
const QString & | arg1 | ) |
|
|
privateslot |
First passphrase field edited: re-evaluates whether OK may be enabled. The text itself stays out of the template box.
- Parameters
-
| arg1 | The new field text (unused). |
Definition at line 47 of file keygendialog.cpp.
◆ on_passphrase2_textChanged
| void KeygenDialog::on_passphrase2_textChanged |
( |
const QString & | arg1 | ) |
|
|
privateslot |
◆ passphraseChosen()
| auto KeygenDialog::passphraseChosen |
( |
| ) |
const -> bool |
|
private |
Whether the passphrase question has an answer: typed twice the same, or waived with the checkbox. Empty fields alone are neither.
- Returns
- true when generation may proceed as far as the passphrase goes.
Definition at line 52 of file keygendialog.cpp.
◆ replace()
| void KeygenDialog::replace |
( |
const QString & | key, |
|
|
const QString & | value ) |
|
private |
Rewrites every <key>: ... line of the batch template to carry value. Values that fail isBatchValue() are ignored so a pasted line break can never become a directive of its own.
- Parameters
-
| key | Batch parameter name, e.g. Name-Real. |
| value | New value for that parameter. |
Definition at line 104 of file keygendialog.cpp.
◆ setExpertMode
| void KeygenDialog::setExpertMode |
( |
bool | checked | ) |
|
|
privateslot |
Enable or disable expert mode (the editable batch template).
Connected explicitly to QCheckBox::toggled in the constructor; the box is two-state, so the deprecated stateChanged(int) is not needed.
- Parameters
-
| checked | true when the Expert box is checked. |
Definition at line 76 of file keygendialog.cpp.
◆ setNoPassphrase
| void KeygenDialog::setNoPassphrase |
( |
bool | checked | ) |
|
|
privateslot |
Ticking "no passphrase" clears and disables the passphrase fields and makes OK available; unticking it asks for one again.
- Parameters
-
| checked | The checkbox state. |
Definition at line 62 of file keygendialog.cpp.
◆ startGeneration()
| void KeygenDialog::startGeneration |
( |
const QString & | batch | ) |
|
|
private |
Connects to the backend's finished/failed signals for this one attempt and calls Pass::GenerateGPGKeys(). With no backend the attempt fails at once.
- Parameters
-
| batch | Complete batch text, passphrase already spliced in. |
Definition at line 312 of file keygendialog.cpp.
◆ updateOkState()
| void KeygenDialog::updateOkState |
( |
| ) |
|
|
private |
OK is available when a passphrase is typed twice the same, or when no passphrase was asked for explicitly. Empty fields alone are not a choice: the key would be stored unprotected without anyone saying so.
Definition at line 58 of file keygendialog.cpp.
◆ m_failed
| QMetaObject::Connection KeygenDialog::m_failed |
|
private |
◆ m_finished
| QMetaObject::Connection KeygenDialog::m_finished |
|
private |
◆ m_pass
| Pass* KeygenDialog::m_pass |
|
private |
Backend that runs gpg; not owned, may be nullptr.
Definition at line 192 of file keygendialog.h.
◆ m_progressIndicator
Spinner shown while gpg works; created lazily on the first attempt, reused (hidden) across retries.
Definition at line 201 of file keygendialog.h.
◆ ui
| QScopedPointer<Ui::KeygenDialog> KeygenDialog::ui |
|
private |
Generated form (keygendialog.ui); owned.
Definition at line 159 of file keygendialog.h.
The documentation for this class was generated from the following files: