14#include <QRegularExpression>
35 if (record_type ==
"pub") {
38 if (record_type ==
"sec") {
41 if (record_type ==
"uid") {
44 if (record_type ==
"fpr") {
47 if (record_type ==
"sub") {
50 if (record_type ==
"ssb") {
53 if (record_type ==
"grp") {
72 bool okCreated =
false;
75 current_user.
created = QDateTime::fromSecsSinceEpoch(createdSecs);
78 bool okExpiry =
false;
81 current_user.
expiry = QDateTime::fromSecsSinceEpoch(expirySecs);
103 static const QRegularExpression shape(
104 QStringLiteral(
"^(?:[0-9A-Fa-f]{40}|[0-9A-Fa-f]{64})$"));
106 if (!current_user.
key_id.isEmpty() && shape.match(fingerprint).hasMatch() &&
107 fingerprint.endsWith(current_user.
key_id, Qt::CaseInsensitive)) {
108 current_user.
key_id = fingerprint;
114 QList<UserInfo> users;
116 const QStringList lines =
121 for (
const QString &key : lines) {
122 QStringList props = key.split(
':');
127 const QString &record_type = props[0];
133 if (!current_user.
key_id.isEmpty()) {
134 users.append(current_user);
141 if (current_user.
name.isEmpty()) {
153 if (!current_user.
key_id.isEmpty()) {
154 users.append(current_user);
162 QString wanted = key.trimmed().toUpper();
163 if (wanted.startsWith(QLatin1String(
"0X"))) {
166 if (wanted.isEmpty()) {
169 const bool isId = wanted.size() == 8 || wanted.size() == 16;
172 bool expectPrimary =
false;
176 const auto namesKeyId = [&](
const QStringList &props) {
179 const auto endBlock = [&] {
180 if (holds && !primary.isEmpty() && !holders.contains(primary)) {
186 const QStringList lines =
188 for (
const QString &line : lines) {
189 const QStringList props = line.split(QLatin1Char(
':'));
196 expectPrimary =
true;
197 holds = holds || namesKeyId(props);
200 expectPrimary =
false;
201 holds = holds || namesKeyId(props);
206 expectPrimary =
false;
217 return holders.size() == 1 ? holders.first() : QString();
static auto newLinesRegex() -> const QRegularExpression &
Returns a regex to match newline characters.
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,...
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.
constexpr int GPG_FIELD_KEY_ID
Field index of the key ID.
constexpr int GPG_FIELD_VALIDITY
Field index of the validity letter (u, f, r, ...).
constexpr int GPG_FIELD_EXPIRY
Field index of the expiry time; empty for a key without one.
constexpr int GPG_FIELD_CREATED
Field index of the creation time, in seconds since the epoch.
constexpr int GPG_MIN_FIELDS
Fewest fields a record must have to be read at all.
auto classifyRecord(const QString &record_type) -> GpgRecordType
Classify a record of a gpg colon listing by its first field.
void handleFprRecord(const QStringList &props, UserInfo ¤t_user)
Replace the key ID of the key being built with its fingerprint.
void handleUidRecord(const QStringList &props, UserInfo ¤t_user)
Handle a uid record in GPG colon output.
constexpr int GPG_FIELD_USERID
Field index of the user ID.
constexpr int GPG_FIELD_FINGERPRINT
Field 9 of an fpr record: the fingerprint, in the slot the user ID occupies in a uid record.
Parsing of gpg --with-colons key listings into UserInfo records.
GpgRecordType
The record types of a gpg --with-colons listing that the parser tells apart; the first field of each ...
Record handlers of the gpg colon-listing parser, declared separately only so the unit tests can call ...
Stores GPG key info including validity, creation date, and more.
bool have_secret
Whether secret key is available (can decrypt with this key).
QString key_id
Hexadecimal representation of the GnuPG key identifier.
QDateTime created
Date/time when key was created.
QString name
GPG user ID / full name.
UserInfo()
Construct a UserInfo with default (invalid/disabled) state.
char validity
GnuPG representation of validity. http://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg....
QDateTime expiry
Date/time when key expires.
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...