aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/utils')
-rw-r--r--src/core/utils/CommonUtils.cpp9
-rw-r--r--src/core/utils/CommonUtils.h9
-rw-r--r--src/core/utils/GpgUtils.cpp17
-rw-r--r--src/core/utils/GpgUtils.h10
4 files changed, 44 insertions, 1 deletions
diff --git a/src/core/utils/CommonUtils.cpp b/src/core/utils/CommonUtils.cpp
index 9687acd4..0adc4d7f 100644
--- a/src/core/utils/CommonUtils.cpp
+++ b/src/core/utils/CommonUtils.cpp
@@ -98,4 +98,13 @@ auto GFUnStrDup(const char* s) -> QString {
auto GPGFRONTEND_CORE_EXPORT IsFlatpakENV() -> bool {
return QString::fromLocal8Bit(qgetenv("container")) == "flatpak";
}
+
+auto GPGFRONTEND_CORE_EXPORT ParseHexEncodedVersionTuple(const QString& s)
+ -> int {
+ // s is a hex-encoded, unsigned int-packed version tuple,
+ // i.e. each byte represents one part of the version tuple
+ bool ok;
+ const auto version = s.toUtf8().toUInt(&ok, 16);
+ return ok ? static_cast<int>(version) : -1;
+}
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/utils/CommonUtils.h b/src/core/utils/CommonUtils.h
index de77114f..468d8a59 100644
--- a/src/core/utils/CommonUtils.h
+++ b/src/core/utils/CommonUtils.h
@@ -73,4 +73,13 @@ auto GPGFRONTEND_CORE_EXPORT GFUnStrDup(const char *) -> QString;
*/
auto GPGFRONTEND_CORE_EXPORT IsFlatpakENV() -> bool;
+/**
+ * @brief
+ *
+ * @param s
+ * @return int
+ */
+auto GPGFRONTEND_CORE_EXPORT ParseHexEncodedVersionTuple(const QString &s)
+ -> int;
+
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp
index c7040cc2..22ba856e 100644
--- a/src/core/utils/GpgUtils.cpp
+++ b/src/core/utils/GpgUtils.cpp
@@ -353,4 +353,21 @@ auto GPGFRONTEND_CORE_EXPORT GetUsagesBySubkey(const GpgSubKey& key)
if (key.IsADSK()) usages += "R";
return usages;
}
+
+auto GPGFRONTEND_CORE_EXPORT GetGpgKeyByGpgAbstractKey(GpgAbstractKey* ab_key)
+ -> GpgKey {
+ if (!ab_key->IsGood()) return {};
+
+ if (ab_key->IsSubKey()) {
+ auto* s_key = dynamic_cast<GpgSubKey*>(ab_key);
+
+ assert(s_key != nullptr);
+ if (s_key == nullptr) return {};
+
+ return *s_key->Convert2GpgKey();
+ }
+
+ auto* key = dynamic_cast<GpgKey*>(ab_key);
+ return *key;
+}
} // namespace GpgFrontend
diff --git a/src/core/utils/GpgUtils.h b/src/core/utils/GpgUtils.h
index b453cc0a..9fcfe5cf 100644
--- a/src/core/utils/GpgUtils.h
+++ b/src/core/utils/GpgUtils.h
@@ -28,7 +28,7 @@
#pragma once
-#include "core/function/result_analyse/GpgResultAnalyse.h"
+#include "core/model/GpgAbstractKey.h"
#include "core/model/KeyDatabaseInfo.h"
#include "core/struct/settings_object/KeyDatabaseItemSO.h"
#include "core/typedef/CoreTypedef.h"
@@ -173,4 +173,12 @@ auto GPGFRONTEND_CORE_EXPORT GetUsagesByKey(const GpgKey& key) -> QString;
*/
auto GPGFRONTEND_CORE_EXPORT GetUsagesBySubkey(const GpgSubKey& key) -> QString;
+/**
+ * @brief
+ *
+ * @return GpgKey
+ */
+auto GPGFRONTEND_CORE_EXPORT GetGpgKeyByGpgAbstractKey(GpgAbstractKey*)
+ -> GpgKey;
+
} // namespace GpgFrontend \ No newline at end of file