Skip to content

Commit

Permalink
Feature #313: Support JWK sets
Browse files Browse the repository at this point in the history
When multiple keys are selected, put them all into
one file as a JWK set, which is "keys" array of JWK objects.
  • Loading branch information
chris2511 committed Sep 13, 2024
1 parent 778e5c2 commit 2e70aa6
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/db_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2e70aa6

Please sign in to comment.