From 2e70aa6329489c35cac32773ca1a42fa416a1fe2 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Wed, 11 Sep 2024 20:46:31 +0200 Subject: [PATCH] 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. --- lib/db_base.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/db_base.cpp b/lib/db_base.cpp index 4e1312af..10d38d78 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -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 names; + + foreach(QModelIndex idx, indexes) { + QJsonObject jwk; + pki_base *pki = fromIndex(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,