QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
KeygenDialog Class Reference

Handles GPG keypair generation. More...

#include <keygendialog.h>

Inheritance diagram for KeygenDialog:
Collaboration diagram for KeygenDialog:

Public Member Functions

 KeygenDialog (const QString &gpgExe, Pass *pass, QWidget *parent=nullptr)
 Construct a KeygenDialog.
 ~KeygenDialog () override
 Destroys the dialog and its generated UI.

Static Public Member Functions

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.

Private Slots

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.

Private Member Functions

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.

Private Attributes

QScopedPointer< Ui::KeygenDialog > ui
 Generated form (keygendialog.ui); owned.
Pass * m_pass
 Backend that runs gpg; not owned, may be nullptr.
QMetaObject::Connection m_finished
 Connection to Pass::finishedGenerateGPGKeys, live only during an attempt.
QMetaObject::Connection m_failed
 Connection to Pass::generateGPGKeysFailed, live only during an attempt.
std::unique_ptr< QProgressIndicator > m_progressIndicator
 Spinner shown while gpg works; created lazily on the first attempt, reused (hidden) across retries.

Detailed Description

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.

Constructor & Destructor Documentation

◆ KeygenDialog()

KeygenDialog::KeygenDialog ( const QString & gpgExe,
Pass * pass,
QWidget * parent = nullptr )
explicit

Construct a KeygenDialog.

Parameters
gpgExePath to the gpg executable (for the default template).
passBackend that runs gpg --gen-key; the dialog accepts on its finishedGenerateGPGKeys() and shows generateGPGKeysFailed().
parentParent widget, or nullptr.

Definition at line 23 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~KeygenDialog()

KeygenDialog::~KeygenDialog ( )
overridedefault

Destroys the dialog and its generated UI.

Here is the call graph for this function:

Member Function Documentation

◆ 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
batchGPG batch template text.
passphraseKey passphrase, empty for an unprotected key.
Returns
Batch text ready for gpg –gen-key –batch.

Definition at line 141 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
rThe QDialog result code.

Definition at line 219 of file keygendialog.cpp.

Here is the call graph for this function:

◆ 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
errorBackend error text; HTML-escaped before display.

Definition at line 335 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
valueA field's text.
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.

Here is the caller graph for this function:

◆ 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
passphraseThe passphrase typed; empty means none.
Returns
False when it starts or ends with ASCII white space.

Definition at line 210 of file keygendialog.cpp.

Here is the caller graph for this function:

◆ 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
valueA field's text.
Returns
False when hasBatchBreak() finds a break, or it is not valid UTF-16.

Definition at line 181 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
arg1The new field text.

Definition at line 82 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_name_textChanged

void KeygenDialog::on_name_textChanged ( const QString & arg1)
privateslot

Mirrors the name field into the template's Name-Real: line.

Parameters
arg1The new field text.

Definition at line 86 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
arg1The new field text (unused).

Definition at line 47 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_passphrase2_textChanged

void KeygenDialog::on_passphrase2_textChanged ( const QString & arg1)
privateslot

Confirmation field edited: same as on_passphrase1_textChanged().

Parameters
arg1The new field text (unused).

Definition at line 72 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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
keyBatch parameter name, e.g. Name-Real.
valueNew value for that parameter.

Definition at line 104 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
checkedtrue when the Expert box is checked.

Definition at line 76 of file keygendialog.cpp.

Here is the caller graph for this function:

◆ 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
checkedThe checkbox state.

Definition at line 62 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
batchComplete batch text, passphrase already spliced in.

Definition at line 312 of file keygendialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_failed

QMetaObject::Connection KeygenDialog::m_failed
private

Connection to Pass::generateGPGKeysFailed, live only during an attempt.

Definition at line 198 of file keygendialog.h.

◆ m_finished

QMetaObject::Connection KeygenDialog::m_finished
private

Connection to Pass::finishedGenerateGPGKeys, live only during an attempt.

Definition at line 195 of file keygendialog.h.

◆ 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

std::unique_ptr<QProgressIndicator> KeygenDialog::m_progressIndicator
private

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: