aboutsummaryrefslogtreecommitdiff
path: root/src/trustedhostcollection.cpp
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-16 00:41:57 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-16 00:41:57 +0200
commit33c91102a58e2fbcf9d7a66e33b41a65fa3f0e0c (patch)
treea724f0c3dcc48c8ce1f78c2665fe8ef170acb379 /src/trustedhostcollection.cpp
parent5bb3f3f92e62a0af02fe475943759b8c25cd4592 (diff)
downloadkristall-33c91102a58e2fbcf9d7a66e33b41a65fa3f0e0c.tar.gz
Adds improved client certificate management, adds server certificate management.
Diffstat (limited to 'src/trustedhostcollection.cpp')
-rw-r--r--src/trustedhostcollection.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/trustedhostcollection.cpp b/src/trustedhostcollection.cpp
new file mode 100644
index 0000000..30a6eff
--- /dev/null
+++ b/src/trustedhostcollection.cpp
@@ -0,0 +1,151 @@
+#include "trustedhostcollection.hpp"
+
+TrustedHostCollection::TrustedHostCollection(QObject *parent)
+ : QAbstractTableModel(parent)
+{
+}
+
+TrustedHostCollection::TrustedHostCollection(const TrustedHostCollection & other) :
+ items(other.items)
+{
+ assert(other.parent() == nullptr);
+
+}
+
+TrustedHostCollection::TrustedHostCollection(TrustedHostCollection &&other) :
+ items(std::move(other.items))
+{
+ assert(other.parent() == nullptr);
+}
+
+QVariant TrustedHostCollection::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if(orientation == Qt::Vertical)
+ return QVariant { };
+ if(role == Qt::DisplayRole)
+ {
+ switch(section)
+ {
+ case 0: return "Host Name";
+ case 1: return "First Seen";
+ case 2: return "Key Type";
+ }
+ }
+ return QVariant { };
+}
+
+int TrustedHostCollection::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+ return items.size();
+}
+
+int TrustedHostCollection::columnCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+ return 3;
+}
+
+QVariant TrustedHostCollection::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant { };
+ if(index.row() < 0 or index.row() >= items.size())
+ return QVariant { };
+
+ auto const & host = items.at(index.row());
+
+ if(role == Qt::DisplayRole)
+ {
+ switch(index.column())
+ {
+ case 0: return host.host_name;
+ case 1: return host.trusted_at.toString();
+ case 2: switch(host.public_key.algorithm())
+ {
+ case QSsl::Rsa: return "RSA";
+ case QSsl::Ec: return "EC";
+ case QSsl::Dh: return "DH";
+ case QSsl::Dsa: return "DSA";
+ case QSsl::Opaque: return "Opaque";
+ default: return "Unforseen";
+ }
+ }
+ }
+ return QVariant { };
+}
+
+TrustedHostCollection &TrustedHostCollection::operator=(const TrustedHostCollection & other)
+{
+ beginResetModel();
+ this->items = other.items;
+ endResetModel();
+ return *this;
+}
+
+TrustedHostCollection &TrustedHostCollection::operator=(TrustedHostCollection && other)
+{
+ beginResetModel();
+ this->items = std::move(other.items);
+ endResetModel();
+ return *this;
+}
+
+void TrustedHostCollection::clear()
+{
+ beginResetModel();
+ this->items.clear();
+ endResetModel();
+}
+
+bool TrustedHostCollection::insert(const TrustedHost &host)
+{
+ for(auto const & item : items)
+ {
+ if(item.host_name == host.host_name)
+ return false;
+ }
+
+ beginInsertRows(QModelIndex { }, items.size(), items.size() + 1);
+ items.append(host);
+ endInsertRows();
+
+ return true;
+}
+
+std::optional<TrustedHost> TrustedHostCollection::get(QString const & host_name) const
+{
+ for(auto const & item : items)
+ {
+ if(item.host_name == host_name)
+ return item;
+ }
+ return std::nullopt;
+}
+
+std::optional<TrustedHost> TrustedHostCollection::get(const QModelIndex &index) const
+{
+ if(not index.isValid())
+ return std::nullopt;
+ if(index.row() < 0 or index.row() >= items.size())
+ return std::nullopt;
+ return items.at(index.row());
+}
+
+void TrustedHostCollection::remove(const QModelIndex &index)
+{
+ if(not index.isValid())
+ return;
+ if(index.row() < 0 or index.row() >= items.size())
+ return;
+ beginRemoveRows(QModelIndex{}, index.row(), index.row() + 1);
+ items.removeAt(index.row());
+ endRemoveRows();
+}
+
+QVector<TrustedHost> TrustedHostCollection::getAll() const
+{
+ return items;
+}