Commit be31bd7a authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Store type of key and subkey with native type

Defer the serialization of key type and subkey type. This makes it
possible to retrieve the original values.

GnuPG-bug-id: 5832
parent df4ce171
......@@ -179,7 +179,7 @@ void CreateCSRForCardKeyCommand::Private::slotDialogAccepted()
});
KeyParameters keyParameters(KeyParameters::CMS);
keyParameters.setKeyType(QString::fromStdString(keyRef));
keyParameters.setCardKeyRef(QString::fromStdString(keyRef));
keyParameters.setKeyUsages(keyUsages);
keyParameters.setDN(dialog->dn());
keyParameters.setEmail(dialog->email());
......
......@@ -44,7 +44,12 @@ class KeyParameters::Private
friend class ::Kleo::KeyParameters;
Protocol protocol;
QString keyType;
Subkey::PubkeyAlgo keyType = Subkey::AlgoUnknown;
QString cardKeyRef;
Subkey::PubkeyAlgo subkeyType = Subkey::AlgoUnknown;
QMap<QString, QStringList> parameters;
public:
......@@ -88,12 +93,22 @@ KeyParameters &KeyParameters::operator=(KeyParameters &&other) = default;
void KeyParameters::setKeyType(Subkey::PubkeyAlgo type)
{
d->keyType = QString::fromLatin1(Subkey::publicKeyAlgorithmAsString(type));
d->keyType = type;
}
GpgME::Subkey::PubkeyAlgo KeyParameters::keyType() const
{
return d->keyType;
}
void KeyParameters::setCardKeyRef(const QString &cardKeyRef)
{
d->cardKeyRef = cardKeyRef;
}
void KeyParameters::setKeyType(const QString &cardKeyRef)
QString KeyParameters::cardKeyRef() const
{
d->keyType = QLatin1String("card:") + cardKeyRef;
return d->cardKeyRef;
}
void KeyParameters::setKeyLength(unsigned int length)
......@@ -113,7 +128,12 @@ void KeyParameters::setKeyUsages(const QStringList &usages)
void KeyParameters::setSubkeyType(Subkey::PubkeyAlgo type)
{
d->setValue(QStringLiteral("Subkey-Type"), QString::fromLatin1(Subkey::publicKeyAlgorithmAsString(type)));
d->subkeyType = type;
}
Subkey::PubkeyAlgo KeyParameters::subkeyType() const
{
return d->subkeyType;
}
void KeyParameters::setSubkeyLength(unsigned int length)
......@@ -180,12 +200,18 @@ QString KeyParameters::toString() const
}
// add Key-Type as first parameter
if (!d->keyType.isEmpty()) {
keyParameters.push_back(QLatin1String("Key-Type:") + d->keyType);
if (!d->cardKeyRef.isEmpty()) {
keyParameters.push_back(QLatin1String{"Key-Type:card:"} + d->cardKeyRef);
} else if (d->keyType != Subkey::AlgoUnknown) {
keyParameters.push_back(QLatin1String{"Key-Type:"} + QString::fromLatin1(Subkey::publicKeyAlgorithmAsString(d->keyType)));
} else {
qCWarning(KLEOPATRA_LOG) << "KeyParameters::toString(): Key type is unset/empty";
}
if (d->subkeyType != Subkey::AlgoUnknown) {
keyParameters.push_back(QLatin1String{"Subkey-Type:"} + QString::fromLatin1(Subkey::publicKeyAlgorithmAsString(d->subkeyType)));
}
for (auto it = d->parameters.constBegin(); it != d->parameters.constEnd(); ++it) {
for (const auto &v : it.value()) {
keyParameters.push_back(it.key() + QLatin1Char(':') + v);
......
......@@ -39,12 +39,15 @@ public:
KeyParameters &operator=(KeyParameters &&other);
void setKeyType(GpgME::Subkey::PubkeyAlgo type);
void setKeyType(const QString &cardKeyRef);
GpgME::Subkey::PubkeyAlgo keyType() const;
void setCardKeyRef(const QString &cardKeyRef);
QString cardKeyRef() const;
void setKeyLength(unsigned int length);
void setKeyCurve(const QString &curve);
void setKeyUsages(const QStringList &usages);
void setSubkeyType(GpgME::Subkey::PubkeyAlgo type);
GpgME::Subkey::PubkeyAlgo subkeyType() const;
void setSubkeyLength(unsigned int length);
void setSubkeyCurve(const QString &curve);
void setSubkeyUsages(const QStringList &usages);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment