QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
gpgkeystate.h File Reference

Parsing of gpg --with-colons key listings into UserInfo records. More...

#include "userinfo.h"
#include <QList>
#include <QString>
#include <QStringList>
Include dependency graph for gpgkeystate.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum class  GpgRecordType {
  Unknown , Pub , Sec , Uid ,
  Fpr , Sub , Ssb , Grp
}
 The record types of a gpg --with-colons listing that the parser tells apart; the first field of each line names one. More...

Functions

GpgRecordType classifyRecord (const QString &record_type)
 Classify a record of a gpg colon listing by its first field.
QList< UserInfo > parseGpgColonOutput (const QString &output, bool secret)
 Parse a gpg colon listing into one UserInfo per key.
QString primaryFingerprintOf (const QString &output, const QString &key)
 The primary key fingerprint of the key that key names.
QStringList 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.

Detailed Description

Parsing of gpg --with-colons key listings into UserInfo records.

Definition in file gpgkeystate.h.

Enumeration Type Documentation

◆ GpgRecordType

enum class GpgRecordType
strong

The record types of a gpg --with-colons listing that the parser tells apart; the first field of each line names one.

Enumerator
Unknown 

Any record type not listed here; skipped.

Pub 

pub: a public primary key, starting a new key block.

Sec 

sec: a secret primary key, starting a new key block.

Uid 

uid: a user ID of the current key.

Fpr 

fpr: the fingerprint of the key or subkey before it.

Sub 

sub: a public subkey.

Ssb 

ssb: a secret subkey.

Grp 

grp: a keygrip.

Definition at line 21 of file gpgkeystate.h.

Function Documentation

◆ blocksHolding()

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

Parameters
outputAs for primaryFingerprintOf().
keyAs for primaryFingerprintOf(); a trailing ! is ignored.
Returns
The holders' primary fingerprints in upper case, in listing order, each once; empty when no block holds key.

Definition at line 357 of file gpgkeystate.cpp.

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

◆ classifyRecord()

GpgRecordType classifyRecord ( const QString & record_type)

Classify a record of a gpg colon listing by its first field.

Parameters
record_typeThe first field of the record (pub, sec, uid, and so on).
Returns
The matching GpgRecordType, or GpgRecordType::Unknown.

Definition at line 36 of file gpgkeystate.cpp.

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

◆ parseGpgColonOutput()

QList< UserInfo > 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.

Parameters
outputRaw output of gpg --with-colons --with-fingerprint.
secretTrue when output lists secret keys (--list-secret-keys); the keys are then marked as having a secret part.
Returns
The keys, in the order gpg listed them.

Definition at line 280 of file gpgkeystate.cpp.

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

◆ primaryFingerprintOf()

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

Parameters
outputRaw output from GPG –with-colons –with-fingerprint –with-subkey-fingerprint –list-keys.
keyA 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.
Returns
The primary fingerprint in upper case, or empty when no block, or more than one, in output holds key.

Definition at line 319 of file gpgkeystate.cpp.

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