Verified Commit b3dcee27 authored by Ingo Klöcker's avatar Ingo Klöcker Committed by Ingo Klöcker
Browse files

Add simple struct for information on algorithms

GnuPG-bug-id: 4429
parent 9f72d2d7
......@@ -391,6 +391,7 @@ set(_kleopatra_SRCS
selftest/libkleopatrarccheck.h
selftest/selftest.cpp
selftest/selftest.h
smartcard/algorithminfo.h
smartcard/card.cpp
smartcard/card.h
smartcard/deviceinfowatcher.cpp
......
......@@ -11,6 +11,7 @@
#include "cardcommand_p.h"
#include "smartcard/algorithminfo.h"
#include "smartcard/pivcard.h"
#include "smartcard/readerstatus.h"
......
......@@ -9,6 +9,7 @@
#include "gencardkeydialog.h"
#include "smartcard/algorithminfo.h"
#include "utils/qt-cxx20-compat.h"
#include "utils/userinfo.h"
......@@ -117,7 +118,7 @@ public:
q->accept();
}
void setSupportedAlgorithms(const std::vector<std::pair<std::string, QString>> &algorithms, const std::string &defaultAlgo)
void setSupportedAlgorithms(const std::vector<SmartCard::AlgorithmInfo> &algorithms, const std::string &defaultAlgo)
{
if (!mAlgorithmCombo) {
qCWarning(KLEOPATRA_LOG) << "GenCardKeyDialog::setSupportedAlgorithms() called, but algorithm no required key attribute";
......@@ -125,8 +126,8 @@ public:
}
mAlgorithmCombo->clear();
for (auto algorithm: algorithms) {
mAlgorithmCombo->addItem(algorithm.second, QByteArray::fromStdString(algorithm.first));
for (const auto &algorithm: algorithms) {
mAlgorithmCombo->addItem(algorithm.displayName, QByteArray::fromStdString(algorithm.id));
}
mAlgorithmCombo->setCurrentIndex(mAlgorithmCombo->findData(QByteArray::fromStdString(defaultAlgo)));
}
......@@ -160,7 +161,7 @@ GenCardKeyDialog::GenCardKeyDialog(KeyAttributes requiredAttributes, QWidget *pa
{
}
void GenCardKeyDialog::setSupportedAlgorithms(const std::vector<std::pair<std::string, QString>> &algorithms, const std::string &defaultAlgo)
void GenCardKeyDialog::setSupportedAlgorithms(const std::vector<SmartCard::AlgorithmInfo> &algorithms, const std::string &defaultAlgo)
{
d->setSupportedAlgorithms(algorithms, defaultAlgo);
}
......
......@@ -17,6 +17,11 @@
namespace Kleo
{
namespace SmartCard
{
struct AlgorithmInfo;
}
class GenCardKeyDialog: public QDialog
{
Q_OBJECT
......@@ -49,7 +54,7 @@ public:
KeyParams getKeyParams() const;
void setSupportedAlgorithms(const std::vector<std::pair<std::string, QString>> &algorithms, const std::string &defaultAlgo);
void setSupportedAlgorithms(const std::vector<SmartCard::AlgorithmInfo> &algorithms, const std::string &defaultAlgo);
private:
class Private;
......
/* smartcard/algorithminfo.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <string>
class QString;
namespace Kleo
{
namespace SmartCard
{
struct AlgorithmInfo {
std::string id;
QString displayName;
};
} // namespace SmartCard
} // namespace Kleo
......@@ -9,6 +9,7 @@
#include "pivcard.h"
#include "algorithminfo.h"
#include "keypairinfo.h"
#include <KLocalizedString>
......@@ -91,7 +92,7 @@ QString PIVCard::keyDisplayName(const std::string &keyRef)
}
// static
std::vector< std::pair<std::string, QString> > PIVCard::supportedAlgorithms(const std::string &keyRef)
std::vector<AlgorithmInfo> PIVCard::supportedAlgorithms(const std::string &keyRef)
{
if (keyRef == PIVCard::keyManagementKeyRef()) {
return {
......
......@@ -14,6 +14,7 @@ namespace Kleo
{
namespace SmartCard
{
struct AlgorithmInfo;
struct KeyPairInfo;
/** Class to work with PIV smartcards or compatible tokens */
......@@ -34,7 +35,7 @@ public:
static const std::vector<KeyPairInfo> & supportedKeys();
static QString keyDisplayName(const std::string &keyRef);
static std::vector< std::pair<std::string, QString> > supportedAlgorithms(const std::string &keyRef);
static std::vector<AlgorithmInfo> supportedAlgorithms(const std::string &keyRef);
std::string keyAlgorithm(const std::string &keyRef) const;
void setKeyAlgorithm(const std::string &keyRef, const std::string &algorithm);
......
......@@ -18,6 +18,7 @@
#include "commands/createcsrforcardkeycommand.h"
#include "commands/createopenpgpkeyfromcardkeyscommand.h"
#include "smartcard/algorithminfo.h"
#include "smartcard/openpgpcard.h"
#include "smartcard/readerstatus.h"
......@@ -357,7 +358,7 @@ void PGPCardWidget::genkeyRequested()
}
auto dlg = new GenCardKeyDialog(GenCardKeyDialog::AllKeyAttributes, this);
std::vector<std::pair<std::string, QString>> algos = {
std::vector<AlgorithmInfo> algos = {
{ "1024", QStringLiteral("RSA 1024") },
{ "2048", QStringLiteral("RSA 2048") },
{ "3072", QStringLiteral("RSA 3072") }
......
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