13#include "keyparameters.h"
15#include <Libkleo/KeyUsage>
20#include "libkleo_debug.h"
39 return email.
left(at + 1) + encodeDomainName(email.
mid(at + 1));
43class KeyParameters::Private
45 friend class ::Kleo::KeyParameters;
49 Subkey::PubkeyAlgo keyType = Subkey::AlgoUnknown;
51 unsigned int keyLength = 0;
55 Subkey::PubkeyAlgo subkeyType = Subkey::AlgoUnknown;
56 unsigned int subkeyLength = 0;
63 std::vector<QString> emailAdresses;
64 std::vector<QString> domainNames;
65 std::vector<QString> uris;
70 explicit Private(Protocol proto)
76KeyParameters::KeyParameters()
77 : KeyParameters{NoProtocol}
81KeyParameters::KeyParameters(Protocol protocol)
82 : d{new Private{protocol}}
86KeyParameters::~KeyParameters() =
default;
88KeyParameters::KeyParameters(
const KeyParameters &other)
89 : d{new Private{*other.d}}
93KeyParameters &KeyParameters::operator=(
const KeyParameters &other)
99KeyParameters::KeyParameters(KeyParameters &&other) =
default;
101KeyParameters &KeyParameters::operator=(KeyParameters &&other) =
default;
103KeyParameters::Protocol KeyParameters::protocol()
const
108void KeyParameters::setKeyType(Subkey::PubkeyAlgo type)
113GpgME::Subkey::PubkeyAlgo KeyParameters::keyType()
const
118void KeyParameters::setCardKeyRef(
const QString &cardKeyRef)
120 d->cardKeyRef = cardKeyRef;
123QString KeyParameters::cardKeyRef()
const
125 return d->cardKeyRef;
128void KeyParameters::setKeyLength(
unsigned int length)
130 d->keyLength = length;
133unsigned int KeyParameters::keyLength()
const
138void KeyParameters::setKeyCurve(
const QString &curve)
143QString KeyParameters::keyCurve()
const
148void KeyParameters::setKeyUsage(
const KeyUsage &usage)
153KeyUsage KeyParameters::keyUsage()
const
158void KeyParameters::setSubkeyType(Subkey::PubkeyAlgo type)
160 d->subkeyType =
type;
163Subkey::PubkeyAlgo KeyParameters::subkeyType()
const
165 return d->subkeyType;
168void KeyParameters::setSubkeyLength(
unsigned int length)
170 d->subkeyLength = length;
173unsigned int KeyParameters::subkeyLength()
const
175 return d->subkeyLength;
178void KeyParameters::setSubkeyCurve(
const QString &curve)
180 d->subkeyCurve = curve;
183QString KeyParameters::subkeyCurve()
const
185 return d->subkeyCurve;
188void KeyParameters::setSubkeyUsage(
const KeyUsage &usage)
190 d->subkeyUsage = usage;
193KeyUsage KeyParameters::subkeyUsage()
const
195 return d->subkeyUsage;
198void KeyParameters::setExpirationDate(
const QDate &date)
200 d->expirationDate = date;
203QDate KeyParameters::expirationDate()
const
205 return d->expirationDate;
208void KeyParameters::setName(
const QString &name)
213QString KeyParameters::name()
const
218void KeyParameters::setComment(
const QString &comment)
220 d->comment = comment;
223QString KeyParameters::comment()
const
228void KeyParameters::setDN(
const QString &dn)
233QString KeyParameters::dn()
const
238void KeyParameters::setEmail(
const QString &email)
240 d->emailAdresses = {email};
243void KeyParameters::addEmail(
const QString &email)
245 d->emailAdresses.push_back(email);
248std::vector<QString> KeyParameters::emails()
const
250 return d->emailAdresses;
253void KeyParameters::addDomainName(
const QString &domain)
255 d->domainNames.push_back(domain);
258std::vector<QString> KeyParameters::domainNames()
const
260 return d->domainNames;
263void KeyParameters::addURI(
const QString &uri)
265 d->uris.push_back(uri);
268std::vector<QString> KeyParameters::uris()
const
275QString serialize(Subkey::PubkeyAlgo algo)
280QString serialize(
unsigned int number)
285QString serialize(KeyUsage keyUsage)
288 if (keyUsage.canSign()) {
289 usages << QStringLiteral(
"sign");
291 if (keyUsage.canEncrypt()) {
292 usages << QStringLiteral(
"encrypt");
294 if (keyUsage.canAuthenticate()) {
295 usages << QStringLiteral(
"auth");
297 if (keyUsage.canCertify()) {
298 usages << QStringLiteral(
"cert");
314QString KeyParameters::toString()
const
320 if (d->protocol == OpenPGP) {
322 keyParameters.
push_back(QStringLiteral(
"%ask-passphrase"));
326 if (!d->cardKeyRef.isEmpty()) {
328 }
else if (d->keyType != Subkey::AlgoUnknown) {
329 keyParameters.
push_back(serialize(
"Key-Type", serialize(d->keyType)));
331 qCWarning(LIBKLEO_LOG) <<
"KeyParameters::toString(): Key type is unset/empty";
334 keyParameters.
push_back(serialize(
"Key-Length", serialize(d->keyLength)));
336 if (!d->keyCurve.isEmpty()) {
337 keyParameters.
push_back(serialize(
"Key-Curve", d->keyCurve));
339 keyParameters.
push_back(serialize(
"Key-Usage", serialize(d->keyUsage)));
341 if (d->subkeyType != Subkey::AlgoUnknown) {
342 keyParameters.
push_back(serialize(
"Subkey-Type", serialize(d->subkeyType)));
343 if (d->subkeyUsage.value()) {
344 keyParameters.
push_back(serialize(
"Subkey-Usage", serialize(d->subkeyUsage)));
346 if (d->subkeyLength) {
347 keyParameters.
push_back(serialize(
"Subkey-Length", serialize(d->subkeyLength)));
349 if (!d->subkeyCurve.isEmpty()) {
350 keyParameters.
push_back(serialize(
"Subkey-Curve", d->subkeyCurve));
354 if (d->expirationDate.isValid()) {
355 keyParameters.
push_back(serialize(
"Expire-Date", serialize(d->expirationDate)));
358 if (!d->name.isEmpty()) {
359 keyParameters.
push_back(serialize(
"Name-Real", d->name));
361 if (!d->comment.isEmpty()) {
362 keyParameters.
push_back(serialize(
"Name-Comment", d->comment));
364 if (!d->dn.isEmpty()) {
365 keyParameters.
push_back(serialize(
"Name-DN", d->dn));
367 std::transform(std::cbegin(d->emailAdresses), std::cend(d->emailAdresses), std::back_inserter(keyParameters), [
this](
const auto &email) {
368 return serialize(
"Name-Email", (d->protocol == CMS) ? encodeEmail(email) : email);
370 std::transform(std::cbegin(d->domainNames), std::cend(d->domainNames), std::back_inserter(keyParameters), [](
const auto &domain) {
371 return serialize(
"Name-DNS", encodeDomainName(domain));
373 std::transform(std::cbegin(d->uris), std::cend(d->uris), std::back_inserter(keyParameters), [](
const auto &uri) {
374 return serialize(
"Name-URI", uri);
Type type(const QSqlDatabase &db)
bool isEmpty() const const
QString toString(QStringView format, QCalendar cal) const const
void push_back(parameter_type value)
QString fromLatin1(QByteArrayView str)
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) const const
QString mid(qsizetype position, qsizetype n) const const
QString number(double n, char format, int precision)
QString join(QChar separator) const const
QByteArray toAce(const QString &domain, AceProcessingOptions options)