|
QtPass 2.0.0
Developer documentation
|
Implements the colon-listing parser: record classification, one handler per record type, and primary-fingerprint lookup. More...
#include "gpgkeystate.h"#include "gpgkeystate_p.h"#include "util.h"#include <QDateTime>#include <QRegularExpression>#include <cctype>Go to the source code of this file.
Functions | |
| auto | classifyRecord (const QString &record_type) -> GpgRecordType |
| Classify a record of a gpg colon listing by its first field. | |
| void | handlePubSecRecord (const QStringList &props, bool secret, UserInfo ¤t_user) |
| Start a key from a pub or sec record: key ID, the user ID the record may carry, validity, creation and expiry time. | |
| auto | uidNameRank (const QString &validity) -> int |
| How far a uid record's own validity vouches for its name. | |
| auto | decodeColonField (const QString &field) -> QString |
| Decode a field of GPG colon output: gpg writes a colon, a backslash and control characters in a user ID as \xHH. | |
| void | handleUidRecord (const QStringList &props, UserInfo ¤t_user, int &nameRank) |
| Handle a uid record in GPG colon output: its name is the key's name unless an earlier uid vouches at least as well for its own. | |
| void | handleFprRecord (const QStringList &props, UserInfo ¤t_user) |
| Replace the key ID of the key being built with its fingerprint. | |
| auto | parseGpgColonOutput (const QString &output, bool secret) -> QList< UserInfo > |
| Parse a gpg colon listing into one UserInfo per key. | |
| auto | primaryFingerprintOf (const QString &output, const QString &key) -> QString |
The primary key fingerprint of the key that key names. | |
| auto | blocksHolding (const QString &output, const QString &key) -> QStringList |
The primary fingerprints of every key block in output that holds key, as its primary key or as a subkey. | |
Variables | |
| constexpr int | GPG_MIN_FIELDS = 10 |
| Fewest fields a record must have to be read at all. | |
| constexpr int | GPG_FIELD_VALIDITY = 1 |
| Field index of the validity letter (u, f, r, ...). | |
| constexpr int | GPG_FIELD_KEY_ID = 4 |
| Field index of the key ID. | |
| constexpr int | GPG_FIELD_CREATED = 5 |
| Field index of the creation time, in seconds since the epoch. | |
| constexpr int | GPG_FIELD_EXPIRY = 6 |
| Field index of the expiry time; empty for a key without one. | |
| constexpr int | GPG_FIELD_USERID = 9 |
| Field index of the user ID. | |
| constexpr int | GPG_FIELD_FINGERPRINT = 9 |
| Field 9 of an fpr record: the fingerprint, in the slot the user ID occupies in a uid record. | |
Implements the colon-listing parser: record classification, one handler per record type, and primary-fingerprint lookup.
Definition in file gpgkeystate.cpp.
| auto blocksHolding | ( | const QString & | output, |
| const QString & | key ) |
The primary fingerprints of every key block in output that holds key, as its primary key or as a subkey.
gpg resolves a fingerprint or key ID among primary keys and subkeys alike, and anyone can bind another person's public key to their own key as a subkey: a .gpg-id line held by two blocks may be encrypted to either.
| output | As for primaryFingerprintOf(). |
| key | As for primaryFingerprintOf(); a trailing ! is ignored. |
key. Definition at line 357 of file gpgkeystate.cpp.
| auto classifyRecord | ( | const QString & | record_type | ) |
Classify a record of a gpg colon listing by its first field.
| record_type | The first field of the record (pub, sec, uid, and so on). |
Definition at line 36 of file gpgkeystate.cpp.
| auto decodeColonField | ( | const QString & | field | ) | -> QString |
Decode a field of GPG colon output: gpg writes a colon, a backslash and control characters in a user ID as \xHH.
| field | The field as gpg listed it |
Definition at line 121 of file gpgkeystate.cpp.
| void handleFprRecord | ( | const QStringList & | props, |
| UserInfo & | current_user ) |
Replace the key ID of the key being built with its fingerprint.
Only when the fpr record's value has the expected fingerprint shape and contains the exact 16-hex key ID in its version-specific position: the tail for a 40-hex v4 fingerprint, the head for a 64-hex v5/v6 fingerprint. A subkey's fingerprint therefore cannot replace the primary key's ID.
| props | The colon-split fields of the record. |
| current_user | The key being built; its key ID may be replaced. |
Definition at line 160 of file gpgkeystate.cpp.
| void handlePubSecRecord | ( | const QStringList & | props, |
| bool | secret, | ||
| UserInfo & | current_user ) |
Start a key from a pub or sec record: key ID, the user ID the record may carry, validity, creation and expiry time.
An empty expiry field (gpg's "no expiry") leaves the date null. A record with fewer than ten fields changes nothing.
| props | The colon-split fields of the record. |
| secret | Whether to mark the key as having a secret part. |
| current_user | The key being built; filled in. |
Definition at line 61 of file gpgkeystate.cpp.
| void handleUidRecord | ( | const QStringList & | props, |
| UserInfo & | current_user, | ||
| int & | nameRank ) |
Handle a uid record in GPG colon output: its name is the key's name unless an earlier uid vouches at least as well for its own.
| props | The colon-split fields of the record |
| current_user | UserInfo to populate with user name |
| nameRank | uidNameRank() of the name taken so far; updated |
Definition at line 150 of file gpgkeystate.cpp.
| auto parseGpgColonOutput | ( | const QString & | output, |
| bool | secret ) |
Parse a gpg colon listing into one UserInfo per key.
A pub or sec record starts a key; the first uid after it supplies the name when the key record carried none, and an fpr record whose value ends in the key ID replaces the key ID with the full fingerprint. Lines with fewer than ten fields are skipped.
| output | Raw output of gpg --with-colons --with-fingerprint. |
| secret | True when output lists secret keys (--list-secret-keys); the keys are then marked as having a secret part. |
Definition at line 280 of file gpgkeystate.cpp.
| auto primaryFingerprintOf | ( | const QString & | output, |
| const QString & | key ) |
The primary key fingerprint of the key that key names.
gpg accepts a signature by a subkey for its primary key, and verification here takes either fingerprint from VALIDSIG: a key written as a subkey's fingerprint, or as a key ID, signs as its primary key. Only the block that holds key is taken, whatever else gpg printed; when several do (a short ID, which collides easily), none is.
| output | Raw output from GPG –with-colons –with-fingerprint –with-subkey-fingerprint –list-keys. |
| key | A fingerprint (40 or 64 hex) or a key ID (8 or 16 hex), optionally with 0x; any case. A key ID is matched against the record's own key ID, so it works for v4 keys (the fingerprint's tail) and v5/v6 keys (its head) alike. |
output holds key. Definition at line 319 of file gpgkeystate.cpp.
| auto uidNameRank | ( | const QString & | validity | ) | -> int |
How far a uid record's own validity vouches for its name.
The key's validity on the pub record is that of its best uid, so the name shown beside it has to be one that earned it: a certified key whose owner adds an uncertified uid and makes it primary must not show that name as valid.
| validity | The record's validity field. |
Definition at line 100 of file gpgkeystate.cpp.
|
constexpr |
Field index of the creation time, in seconds since the epoch.
Definition at line 25 of file gpgkeystate.cpp.
|
constexpr |
Field index of the expiry time; empty for a key without one.
Definition at line 27 of file gpgkeystate.cpp.
|
constexpr |
Field 9 of an fpr record: the fingerprint, in the slot the user ID occupies in a uid record.
Definition at line 34 of file gpgkeystate.cpp.
|
constexpr |
Field index of the key ID.
Definition at line 23 of file gpgkeystate.cpp.
|
constexpr |
Field index of the user ID.
Definition at line 29 of file gpgkeystate.cpp.
|
constexpr |
Field index of the validity letter (u, f, r, ...).
Definition at line 21 of file gpgkeystate.cpp.
|
constexpr |
Fewest fields a record must have to be read at all.
Definition at line 19 of file gpgkeystate.cpp.