mirror of
https://github.com/QRouland/UTPass.git
synced 2025-06-30 01:02:29 +00:00
Various improvement :)
This commit is contained in:
@ -1,20 +1,59 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include "pass.h"
|
||||
#include "gpgme++/global.h"
|
||||
#include "qgpgme/protocol.h"
|
||||
#include "qgpgme/encryptjob.h"
|
||||
#include "qgpgme/decryptjob.h"
|
||||
#include "qgpgme/keylistjob.h"
|
||||
|
||||
|
||||
Pass::Pass() {
|
||||
|
||||
GpgME::initializeLibrary();
|
||||
this->gpgHome = qgetenv("GNUPGHOME");
|
||||
}
|
||||
|
||||
void Pass::cmd_show(const QString path) {
|
||||
QDir dir = QDir(path);
|
||||
if (!dir.exists()) {
|
||||
qWarning("Path to show not found");
|
||||
return;
|
||||
QString Pass::decrypt(const QByteArray cipherText) {
|
||||
/*auto decJob = QGpgME::openpgp()->decryptJob();
|
||||
auto ctx = QGpgME::Job::context(decJob);
|
||||
|
||||
TestPassphraseProvider provider;
|
||||
ctx->setPassphraseProvider(&provider);
|
||||
ctx->setPinentryMode(Context::PinentryLoopback);
|
||||
|
||||
QByteArray plainText;
|
||||
decJob->exec(cipherText, plainText);
|
||||
|
||||
return QString::fromUtf8(plainText);*/
|
||||
}
|
||||
|
||||
QString Pass::decrypt_file(const QString path) {
|
||||
/*QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qErrnoWarning("Can't open the File");
|
||||
return nullptr;
|
||||
}
|
||||
QByteArray plainText = file.readAll();
|
||||
return Pass::decrypt(plainText);*/
|
||||
}
|
||||
|
||||
void Pass::cmd_version() {
|
||||
QByteArray Pass::encrypt(const QString str) {
|
||||
/*auto listjob = QGpgME::openpgp()->keyListJob(false, false, false);
|
||||
std::vector<GpgME::Key> keys;
|
||||
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
|
||||
false, keys);
|
||||
auto job = QGpgME::openpgp()->encryptJob(/*ASCII Armor *//*true, /* Textmode *//* true);
|
||||
QByteArray cipherText;
|
||||
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), GpgME::Context::AlwaysTrust, cipherText);
|
||||
return cipherText;*/
|
||||
}
|
||||
|
||||
bool Pass::encrypt_file(const QString str, const QString path) {
|
||||
/*QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
qErrnoWarning("Can't open the File");
|
||||
return false;
|
||||
}
|
||||
file.write(Pass::encrypt(str));
|
||||
return true;*/
|
||||
}
|
@ -5,13 +5,16 @@
|
||||
|
||||
class Pass: public QObject {
|
||||
Q_OBJECT
|
||||
QString gpgHome;
|
||||
|
||||
public:
|
||||
Pass();
|
||||
~Pass() override = default;
|
||||
|
||||
Q_INVOKABLE void cmd_show(QString path) ;
|
||||
Q_INVOKABLE void cmd_version() ;
|
||||
Q_INVOKABLE QString decrypt(QByteArray plainText);
|
||||
Q_INVOKABLE QString decrypt_file(QString path);
|
||||
Q_INVOKABLE QByteArray encrypt(QString str);
|
||||
Q_INVOKABLE bool encrypt_file(QString str, QString path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@ class PassPlugin : public QQmlExtensionPlugin {
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri);
|
||||
void registerTypes(const char *uri) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user