Feature #313: Support JWK sets

When multiple keys are selected, put them all into
one file as a JWK set, which is "keys" array of JWK objects.
This commit is contained in:
Christian Hohnstaedt 2024-09-11 20:46:31 +02:00
parent 778e5c2e3a
commit 2e70aa6329

View File

@ -678,8 +678,31 @@ void db_base::writeVcalendar(XFile &file, QStringList vcal) const
void db_base::exportItems(const QModelIndexList &indexes,
const pki_export *xport, XFile &file) const
{
foreach(QModelIndex idx, indexes)
exportItem(idx, xport, file);
if (xport->match_all(F_JWK) && indexes.size() > 1) {
QJsonArray arr;
QSet<QString> names;
foreach(QModelIndex idx, indexes) {
QJsonObject jwk;
pki_base *pki = fromIndex<pki_base>(idx);
if (pki) {
pki->fillJWK(jwk, xport);
QString name = jwk["kid"].toString();
for (int i = 1; names.contains(name); i++)
name = QString("%1 (%2)").arg(jwk["kid"].toString()).arg(i);
jwk["kid"] = name;
names.insert(name);
arr.append(jwk);
}
}
QJsonObject obj { { "keys", arr } };
QJsonDocument doc(obj);
file.write(doc.toJson());
} else {
foreach(QModelIndex idx, indexes)
exportItem(idx, xport, file);
}
}
void db_base::exportItem(const QModelIndex &index,