Extend #383: tag insecure PFX/PKCS#12 algorithms

Show the insecure algorithms with the postfix (insecure)
in the dropdown menu.

Since the "insecure" is translateable, put the algorithm NID
into the data field of the combo-box entry to
reliably find the correct entry by NID instead of text.
This commit is contained in:
Christian Hohnstaedt 2024-03-10 00:23:00 +01:00
parent 10e8385c69
commit e72ffb1445
4 changed files with 20 additions and 9 deletions

View File

@ -207,6 +207,14 @@ QString encAlgo::name() const
return QString(encAlgo_nid == NID_undef ? "" : OBJ_nid2sn(encAlgo_nid));
}
QString encAlgo::displayName() const
{
QString n = name();
if (legacy())
n += QString(" (%1)").arg(QObject::tr("insecure"));
return n;
}
int encAlgo::getEncAlgoNid() const
{
return encAlgo_nid;

View File

@ -28,6 +28,7 @@ class encAlgo
encAlgo& operator=(const encAlgo &d) = default;
QString name() const;
QString displayName() const;
int getEncAlgoNid() const;
bool legacy() const
{

View File

@ -16,34 +16,34 @@ pkcs12EncBox::pkcs12EncBox(QWidget *parent)
const encAlgo pkcs12EncBox::current() const
{
return encAlgo(currentText());
return encAlgo(currentData().toInt());
}
void pkcs12EncBox::setCurrent(const encAlgo &md)
{
int idx = findText(md.name());
int idx = findData(QVariant(md.getEncAlgoNid()));
if (idx != -1) {
setCurrentIndex(idx);
wanted_encAlgo = "";
wanted_encAlgo = NID_undef;
} else {
wanted_encAlgo = md.name();
wanted_encAlgo = md.getEncAlgoNid();
}
}
void pkcs12EncBox::setupEncAlgos(QList<int> nids)
{
QString md = currentText();
int md = currentData().toInt();
if (!wanted_encAlgo.isEmpty())
if (wanted_encAlgo != NID_undef)
md = wanted_encAlgo;
clear();
foreach(int nid, encAlgo::all_encAlgos) {
if (nids.contains(nid))
addItem(encAlgo(nid).name());
addItem(encAlgo(nid).displayName(), QVariant(nid));
}
setEnabled(count() > 0);
setDefaultEncAlgo();
if (!md.isEmpty())
if (md != NID_undef)
setCurrent(encAlgo(md));
else
setDefaultEncAlgo();

View File

@ -14,8 +14,10 @@
class pkcs12EncBox: public QComboBox
{
Q_OBJECT
private:
QString wanted_encAlgo{};
int wanted_encAlgo{};
public:
pkcs12EncBox(QWidget *parent);
const encAlgo current() const;