1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-06-24 22:42:28 +00:00

Rewrite import key with rnp

This commit is contained in:
2025-01-29 16:42:37 +01:00
parent c01fae0c58
commit 2c9d82e0b1
30 changed files with 654 additions and 719 deletions

View File

@ -5,6 +5,7 @@ set(
SRC
plugin.cpp
utils.cpp
passphraseprovider.h
)
set(CMAKE_AUTOMOC ON)
@ -22,6 +23,31 @@ endif()
add_library(${PLUGIN} MODULE ${SRC})
set_target_properties(${PLUGIN} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN})
qt5_use_modules(${PLUGIN} Qml Quick DBus)
set(RNP_BUILD_DIR "${CMAKE_SOURCE_DIR}/build/${ARCH_TRIPLET}/rnp/install")
INCLUDE_DIRECTORIES(${RNP_BUILD_DIR}/include)
add_library(rnp STATIC IMPORTED)
set_property(TARGET rnp PROPERTY IMPORTED_LOCATION "${RNP_BUILD_DIR}/lib/librnp.a")
add_library(gpgerror SHARED IMPORTED)
set_property(TARGET gpgerror PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libgpg-error.so.0.28.0")
add_library(libassuan SHARED IMPORTED)
set_property(TARGET libassuan PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libassuan.so")
add_library(libgpgme SHARED IMPORTED)
set_property(TARGET libgpgme PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libgpgme.so")
add_library(libgpgmepp SHARED IMPORTED)
set_property(TARGET libgpgmepp PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libgpgmepp.so")
add_library(libqgpgme SHARED IMPORTED)
set_property(TARGET libqgpgme PROPERTY IMPORTED_LOCATION "/usr/lib/${ARCH_TRIPLET}/libqgpgme.so")
target_link_libraries(${PLUGIN} rnp gpgerror libassuan libgpgme libgpgmepp libqgpgme)
set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}")

View File

@ -0,0 +1,24 @@
#ifndef UTPASSPHRASEPROVIDER_H
#define UTPASSPHRASEPROVIDER_H
#include <QObject>
#include <gpg-error.h>
#include <gpgme++/interfaces/passphraseprovider.h>
class TesTPassphraseProvider : public QObject, public GpgME::PassphraseProvider
{
Q_OBJECT
public:
char *getPassphrase(const char *useridHint,
const char *description,
bool previousWasBad,
bool &canceled) override {
char *ret;
gpgrt_asprintf(&ret, "%s", "utpasspassphrase");
return ret;
};
};
#endif

View File

@ -6,5 +6,5 @@
void TestsUtilsPlugin::registerTypes(const char *uri)
{
//@uri TestUtils
qmlRegisterSingletonType<TestsUtilsPlugin>(uri, 1, 0, "TestUtils", [](QQmlEngine *, QJSEngine *) -> QObject * { return new TestsUtils; });
qmlRegisterSingletonType<TestsUtilsPlugin>(uri, 1, 0, "TestsUtils", [](QQmlEngine *, QJSEngine *) -> QObject * { return new TestsUtils; });
}

View File

@ -1,2 +1,2 @@
module TestUtils
plugin TestUtils
module TestsUtils
plugin TestsUtils

View File

@ -3,17 +3,21 @@
#include <QUrl>
#include <QUuid>
#include <QtCore/QStandardPaths>
#include <memory>
#include <quazip5/JlCompress.h>
#include "passphraseprovider.h"
#include "utils.h"
TestsUtils::TestsUtils():
m_passphrase_povider(std::unique_ptr<TesTPassphraseProvider>(new TesTPassphraseProvider()))
{}
QString TestsUtils::getTempPath()
{
qFatal("yp");
// Get the system's temporary directory
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
qDebug() << "TempDir : " << tempDir;
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
// Generate a unique UUID
QString uuid = QUuid::createUuid().toString(QUuid::WithoutBraces);
@ -22,17 +26,16 @@ QString TestsUtils::getTempPath()
QString newTempDir = tempDir + "/" + uuid;
QDir dir;
if (!dir.exists(newTempDir)) {
// Create the directory
if (dir.mkpath(newTempDir)) {
return newTempDir; // Return the path if successful
} else {
return "Failed to create directory"; // Return an error message
}
} else {
return newTempDir; // If the directory already exists, return its path
}
dir.mkpath(newTempDir);
qDebug() << "TempDir : " << newTempDir;
return newTempDir;
}
QObject* TestsUtils::getTestPassphraseProvider()
{
return this->m_passphrase_povider.get();
}

View File

@ -1,19 +1,25 @@
#ifndef TESTSUTILS_H
#define TESTSUTILS_H
#include "passphraseprovider.h"
#include <QObject>
#include <QUrl>
#include <QQuickWindow>
#include <memory>
class TestsUtils : public QObject
{
Q_OBJECT
private:
std::unique_ptr<TesTPassphraseProvider> m_passphrase_povider;
public:
TestsUtils() = default;
TestsUtils();
~TestsUtils() override = default;
Q_INVOKABLE QString getTempPath();
Q_INVOKABLE QObject* getTestPassphraseProvider();
};
#endif