-
Notifications
You must be signed in to change notification settings - Fork 0
/
GpgIdManageType.cpp
124 lines (114 loc) · 3.88 KB
/
GpgIdManageType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "GpgIdManageType.h"
#include <QDebug>
#include <QtConcurrent>
void GpgIdManageType::init(std::string _currentPath,
std::string _stopPath,
bool _isRnPgp,
std::string _rnpHomePath,
std::function<bool(RnpLoginRequestException &e)> rnpPasswdPrompt)
{
m_gpgIdManage = std::make_unique<GpgIdManage>(_currentPath, _stopPath, _isRnPgp, _rnpHomePath, rnpPasswdPrompt);
}
/* [[[cog
import cog
import gpgIdManageType
cog.outl(gpgIdManageType.getQ_src_publics(),
dedent=True, trimblanklines=True)
]]] */
QStringList GpgIdManageType::keysNotFoundInGpgIdFile() const
{
QStringList l;
for (auto r : m_gpgIdManage->keysNotFoundInGpgIdFile) {
l.append(QString::fromStdString(r));
}
return l;
}
QStringList GpgIdManageType::keysFoundInGpgIdFile() const
{
QStringList l;
for (auto r : m_gpgIdManage->keysFoundInGpgIdFile) {
l.append(QString::fromStdString(r.getKeyStr()));
}
return l;
}
QStringList GpgIdManageType::allKeys() const
{
QStringList l;
for (auto r : m_gpgIdManage->allKeys) {
l.append(QString::fromStdString(r.getKeyStr()));
}
return l;
}
QStringList GpgIdManageType::allPrivateKeys() const
{
QStringList l;
for (auto r : m_gpgIdManage->allPrivateKeys) {
l.append(QString::fromStdString(r.getKeyStr()));
}
return l;
}
//[[[end]]]
QString GpgIdManageType::importPublicKeyAndTrust(const QString &urlString)
{
const QUrl url(urlString);
const QString localpath = url.toLocalFile();
try {
m_gpgIdManage->importPublicKeyAndTrust(localpath.toStdString());
return "";
} catch (const std::exception &e) {
return QString(e.what());
}
}
QString GpgIdManageType::importAllGpgPubKeysFolder()
{
try {
m_gpgIdManage->importAllGpgPubKeysFolder();
} catch (const std::exception &e) {
return QString(e.what());
}
return "";
}
QString GpgIdManageType::saveChanges(QStringList keysFound, bool doSign, QString signerStr)
{
QString currentFile = "";
try {
m_gpgIdManage->keysFoundInGpgIdFile.clear();
for (const QString &line : keysFound) {
m_gpgIdManage->populateKeyFromString(line.toStdString());
}
m_gpgIdManage->saveBackGpgIdFile();
m_gpgIdManage->exportGpgIdToGpgPubKeysFolder();
m_gpgIdManage = std::make_unique<GpgIdManage>(m_gpgIdManage->currentPath,
m_gpgIdManage->stopPath,
m_gpgIdManage->isRnPgp,
m_gpgIdManage->rnpHomePath,
m_gpgIdManage->rnpPasswdPrompt
);
try {
m_gpgIdManage->setSigner(signerStr.toStdString());
} catch (...) {
qDebug() << "Bad signer Id \n"; // Block of code to handle errors
}
m_gpgIdManage->reEncryptStoreFolder(
[&](std::string s) {
currentFile = QString::fromStdString(s);
qDebug() << "Re-Encrypt " << currentFile << "\n";
},
doSign);
} catch (RnpLoginRequestException &rlre) {
rlre.functionName = "reEncrypt";
emit loginRequestedRnpG(rlre);
return "Authentication required";
} catch (const std::exception &e) {
qDebug() <<"Error "<< QString(e.what());
return "Error:\n" + currentFile + "\n" + e.what() + "\n";
}
qDebug() << "Finished saveChanges\n";
return "Finished successfully";
}
void GpgIdManageType::saveChangesAsync(QStringList keysFound, bool doSign, QString signerStr, const QJSValue &callback)
{
makeAsync<QString>(callback,[=]() {
return saveChanges(keysFound, doSign, signerStr);
});
}