QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
gpgidsigner.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_GPGIDSIGNER_H_
9#define SRC_GPGIDSIGNER_H_
10
11#include <QString>
12#include <QStringList>
13#include <functional>
14
29public:
35 static constexpr qint64 kMaxSignatureBytes = 64 * 1024;
36
41 using Exec =
42 std::function<int(const QString &app, const QStringList &args,
43 const QString &input, QString *out, QString *err)>;
44
57 GpgIdSigner(QString gpgExecutable, QStringList signingKeys,
58 Exec exec = Exec());
59
66 static auto keysFromSetting(const QString &passSigningKey) -> QStringList;
67
72 auto enabled() const -> bool { return !m_keys.isEmpty(); }
73
78 auto keys() const -> const QStringList & { return m_keys; }
79
85 auto haveSecretKey() const -> bool;
86
112 auto sign(const QString &gpgIdFile, const QByteArray &contents,
113 QString *error = nullptr) const -> bool;
114
128 auto verify(const QByteArray &contents, const QString &signatureFile) const
129 -> bool;
130
139 auto verifyFile(const QString &gpgIdFile, QByteArray *contents) const -> bool;
140
148 static auto validSigFingerprints(const QString &statusOutput) -> QStringList;
149
150private:
152 QString m_gpg;
157 QStringList m_keys;
160
169 auto run(const QStringList &args, QString *out = nullptr,
170 QString *err = nullptr, const QString &input = QString()) const
171 -> int;
172};
173
174#endif // SRC_GPGIDSIGNER_H_
static auto validSigFingerprints(const QString &statusOutput) -> QStringList
Pick the fingerprints out of gpg's --status-fd VALIDSIG line.
Exec m_exec
How gpg is run; replaced by a fake in the unit tests.
auto enabled() const -> bool
Whether any signing key is configured at all.
Definition gpgidsigner.h:72
auto run(const QStringList &args, QString *out=nullptr, QString *err=nullptr, const QString &input=QString()) const -> int
Run gpg with args through m_exec.
auto sign(const QString &gpgIdFile, const QByteArray &contents, QString *error=nullptr) const -> bool
Write <file>.sig, a detached signature by the first key over contents, the bytes the caller just wrot...
GpgIdSigner(QString gpgExecutable, QStringList signingKeys, Exec exec=Exec())
Create a signer.
std::function< int(const QString &app, const QStringList &args, const QString &input, QString *out, QString *err)> Exec
Blocking process runner: Executor::executeBlocking()'s shape.
Definition gpgidsigner.h:41
QStringList m_keys
The configured signing keys. The first one signs; a signature by any of them verifies.
auto keys() const -> const QStringList &
The keys this signer was given.
Definition gpgidsigner.h:78
auto verifyFile(const QString &gpgIdFile, QByteArray *contents) const -> bool
Read gpgIdFile and verify it against <file>.sig.
static constexpr qint64 kMaxSignatureBytes
Most bytes of a .gpg-id.sig verify() hands to gpg.
Definition gpgidsigner.h:35
QString m_gpg
The gpg executable, as configured.
static auto keysFromSetting(const QString &passSigningKey) -> QStringList
Split the settings value into keys, upper-cased the way gpg prints fingerprints.
auto verify(const QByteArray &contents, const QString &signatureFile) const -> bool
Check a detached signature against the given bytes: gpg must report a VALIDSIG whose key or primary-k...
auto haveSecretKey() const -> bool
Whether gpg has the secret key that sign() will use, i.e. the first configured key.