mirror of
https://github.com/QRouland/UTPass.git
synced 2025-06-30 01:02:29 +00:00
Add style command && applied new style format to existing code && setup tests plugins
This commit is contained in:
@ -17,148 +17,157 @@
|
||||
using namespace GpgME;
|
||||
using namespace QGpgME;
|
||||
|
||||
Gpg::Gpg() {
|
||||
auto error = initializeLibrary(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("GpgME init fail");
|
||||
}
|
||||
Gpg::Gpg()
|
||||
{
|
||||
auto error = initializeLibrary(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("GpgME init fail");
|
||||
}
|
||||
|
||||
QString gnuhome = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/gpghome");
|
||||
QDir dir(gnuhome);
|
||||
if (!dir.exists())
|
||||
dir.mkpath(".");
|
||||
qputenv("GNUPGHOME", gnuhome.toStdString().c_str());
|
||||
qDebug() << "GNUPGHOME is :" << qgetenv("GNUPGHOME");
|
||||
QString gnuhome = QStandardPaths::writableLocation(
|
||||
QStandardPaths::AppDataLocation).append("/gpghome");
|
||||
QDir dir(gnuhome);
|
||||
if (!dir.exists())
|
||||
dir.mkpath(".");
|
||||
qputenv("GNUPGHOME", gnuhome.toStdString().c_str());
|
||||
qDebug() << "GNUPGHOME is :" << qgetenv("GNUPGHOME");
|
||||
|
||||
error = checkEngine(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("Engine check Fail");
|
||||
|
||||
}
|
||||
qDebug() << "GpgME Engine Version :" << engineInfo(OpenPGP).version();
|
||||
error = checkEngine(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("Engine check Fail");
|
||||
}
|
||||
qDebug() << "GpgME Engine Version :" << engineInfo(OpenPGP).version();
|
||||
}
|
||||
|
||||
void Gpg::list_dir() {
|
||||
qDebug() << "hello world!";
|
||||
void Gpg::list_dir()
|
||||
{
|
||||
qDebug() << "hello world!";
|
||||
}
|
||||
|
||||
QString Gpg::decrypt(const QByteArray cipherText) {
|
||||
/*auto decJob = openpgp()->decryptJob();
|
||||
auto ctx = DecryptJob::context(decJob);*/
|
||||
QString Gpg::decrypt(const QByteArray cipherText)
|
||||
{
|
||||
/*auto decJob = openpgp()->decryptJob();
|
||||
auto ctx = DecryptJob::context(decJob);*/
|
||||
|
||||
/* TODO
|
||||
* TestPassphraseProvider provider;
|
||||
ctx->setPassphraseProvider(&provider);
|
||||
ctx->setPinentryMode(Context::PinentryLoopback);*/
|
||||
/* TODO
|
||||
* TestPassphraseProvider provider;
|
||||
ctx->setPassphraseProvider(&provider);
|
||||
ctx->setPinentryMode(Context::PinentryLoopback);*/
|
||||
|
||||
/*QByteArray plainText;
|
||||
decJob->exec(cipherText, plainText);
|
||||
/*QByteArray plainText;
|
||||
decJob->exec(cipherText, plainText);
|
||||
|
||||
return QString::fromUtf8(plainText);*/
|
||||
return QString::fromUtf8(plainText);*/
|
||||
}
|
||||
|
||||
QString Gpg::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 this->decrypt(plainText);*/
|
||||
QString Gpg::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 this->decrypt(plainText);*/
|
||||
}
|
||||
|
||||
QByteArray Gpg::encrypt(const QString str) {
|
||||
/*auto listjob = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"), false, keys);
|
||||
QByteArray Gpg::encrypt(const QString str)
|
||||
{
|
||||
/*auto listjob = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"), false, keys);
|
||||
|
||||
auto job = openpgp()
|
||||
->encryptJob(
|
||||
true, //ASCII Armor
|
||||
true //Textmode
|
||||
);
|
||||
QByteArray cipherText;
|
||||
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
|
||||
return cipherText;*/
|
||||
auto job = openpgp()
|
||||
->encryptJob(
|
||||
true, //ASCII Armor
|
||||
true //Textmode
|
||||
);
|
||||
QByteArray cipherText;
|
||||
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
|
||||
return cipherText;*/
|
||||
}
|
||||
|
||||
bool Gpg::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;*/
|
||||
bool Gpg::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;*/
|
||||
}
|
||||
|
||||
QString Gpg::get_key_id(QString uid) {
|
||||
qDebug() << "Getting the key id " << uid;
|
||||
auto *job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList() << uid, false, keys);
|
||||
delete job;
|
||||
QString Gpg::get_key_id(QString uid)
|
||||
{
|
||||
qDebug() << "Getting the key id " << uid;
|
||||
auto *job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList() << uid, false, keys);
|
||||
delete job;
|
||||
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found for" << uid;
|
||||
return nullptr;
|
||||
}
|
||||
const QString kId = QLatin1String(keys.front().keyID());
|
||||
qDebug() << "Id key for " << uid << "is : " << kId;
|
||||
return kId;
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found for" << uid;
|
||||
return nullptr;
|
||||
}
|
||||
const QString kId = QLatin1String(keys.front().keyID());
|
||||
qDebug() << "Id key for " << uid << "is : " << kId;
|
||||
return kId;
|
||||
}
|
||||
|
||||
QStringList Gpg::get_all_keys_id() {
|
||||
qDebug() << "Show all available key";
|
||||
auto job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList(""), false, keys);
|
||||
delete job;
|
||||
QStringList Gpg::get_all_keys_id()
|
||||
{
|
||||
qDebug() << "Show all available key";
|
||||
auto job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList(""), false, keys);
|
||||
delete job;
|
||||
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found";
|
||||
return QStringList();
|
||||
}
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found";
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
auto r = QStringList();
|
||||
for (const auto &key: keys) {
|
||||
r.append(QLatin1String(key.keyID()));
|
||||
qDebug() << "Key" << QLatin1String(key.keyID());
|
||||
}
|
||||
return r;
|
||||
auto r = QStringList();
|
||||
for (const auto &key : keys) {
|
||||
r.append(QLatin1String(key.keyID()));
|
||||
qDebug() << "Key" << QLatin1String(key.keyID());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
bool Gpg::import_key(QString path) {
|
||||
qDebug() << "Importing the key file" << path;
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Can't open the File";
|
||||
return false;
|
||||
}
|
||||
bool Gpg::import_key(QString path)
|
||||
{
|
||||
qDebug() << "Importing the key file" << path;
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Can't open the File";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto job = openpgp()->importJob();
|
||||
auto result = job->exec(file.readAll());
|
||||
auto job = openpgp()->importJob();
|
||||
auto result = job->exec(file.readAll());
|
||||
|
||||
delete job;
|
||||
file.close();
|
||||
delete job;
|
||||
file.close();
|
||||
|
||||
if (result.error()) {
|
||||
qWarning() << "Import go wrong";
|
||||
return false;
|
||||
}
|
||||
if (result.error()) {
|
||||
qWarning() << "Import go wrong";
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Key imported" << result.numImported();
|
||||
qDebug() << "Key not imported" << result.notImported();
|
||||
qDebug() << "Key unchanged" << result.numUnchanged();
|
||||
qDebug() << "Result null" << result.isNull();
|
||||
qDebug() << "newUserIDs" << result.newUserIDs();
|
||||
qDebug() << "Key imported" << result.numImported();
|
||||
qDebug() << "Key not imported" << result.notImported();
|
||||
qDebug() << "Key unchanged" << result.numUnchanged();
|
||||
qDebug() << "Result null" << result.isNull();
|
||||
qDebug() << "newUserIDs" << result.newUserIDs();
|
||||
|
||||
for (const auto &key: result.imports())
|
||||
qDebug() << "Key" << key.fingerprint();
|
||||
for (const auto &key : result.imports())
|
||||
qDebug() << "Key" << key.fingerprint();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
@ -3,21 +3,22 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Gpg : public QObject {
|
||||
Q_OBJECT
|
||||
class Gpg : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Gpg();
|
||||
~Gpg() = default;
|
||||
public:
|
||||
Gpg();
|
||||
~Gpg() = default;
|
||||
|
||||
Q_INVOKABLE void list_dir();
|
||||
Q_INVOKABLE QString get_key_id(QString uid);
|
||||
Q_INVOKABLE QStringList get_all_keys_id();
|
||||
Q_INVOKABLE bool import_key(QString path);
|
||||
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);
|
||||
Q_INVOKABLE void list_dir();
|
||||
Q_INVOKABLE QString get_key_id(QString uid);
|
||||
Q_INVOKABLE QStringList get_all_keys_id();
|
||||
Q_INVOKABLE bool import_key(QString path);
|
||||
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
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include "plugin.h"
|
||||
#include "gpg.h"
|
||||
|
||||
void FileSystemPlugin::registerTypes(const char *uri) {
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Gpg>(uri, 1, 0, "Gpg", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Gpg; });
|
||||
void FileSystemPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Gpg>(uri, 1, 0, "Gpg", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Gpg; });
|
||||
}
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class FileSystemPlugin : public QQmlExtensionPlugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID
|
||||
"org.qt-project.Qt.QQmlExtensionInterface")
|
||||
class FileSystemPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID
|
||||
"org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri);
|
||||
public:
|
||||
void registerTypes(const char *uri);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,12 +3,14 @@
|
||||
|
||||
#include "pass.h"
|
||||
|
||||
Pass::Pass() {
|
||||
Pass::Pass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Pass::speak() {
|
||||
qDebug() << "Starting app from main.cpp";
|
||||
void Pass::speak()
|
||||
{
|
||||
qDebug() << "Starting app from main.cpp";
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,15 +3,16 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Pass : public QObject {
|
||||
Q_OBJECT
|
||||
QString gpgHome;
|
||||
class Pass : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QString gpgHome;
|
||||
|
||||
public:
|
||||
Pass();
|
||||
~Pass() override = default;
|
||||
public:
|
||||
Pass();
|
||||
~Pass() override = default;
|
||||
|
||||
Q_INVOKABLE void speak();
|
||||
Q_INVOKABLE void speak();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include "plugin.h"
|
||||
#include "pass.h"
|
||||
|
||||
void PassPlugin::registerTypes(const char *uri) {
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Pass>(uri, 1, 0, "Pass", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Pass; });
|
||||
void PassPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Pass>(uri, 1, 0, "Pass", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Pass; });
|
||||
}
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class PassPlugin : public QQmlExtensionPlugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID
|
||||
"org.qt-project.Qt.QQmlExtensionInterface")
|
||||
class PassPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID
|
||||
"org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri) override;
|
||||
public:
|
||||
void registerTypes(const char *uri) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user