diff options
author | Saturneric <[email protected]> | 2021-05-23 16:45:30 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-05-23 16:45:30 +0000 |
commit | 40634e042d39e3537a3cfa1a2dfb6a8203a7d6ab (patch) | |
tree | 0535b4213b5bf69febf90f0a4d2b515ab2a15c34 /src | |
parent | Enhance code robustness; (diff) | |
download | GpgFrontend-40634e042d39e3537a3cfa1a2dfb6a8203a7d6ab.tar.gz GpgFrontend-40634e042d39e3537a3cfa1a2dfb6a8203a7d6ab.zip |
Declare and Define getSigners;
Expand KeyList;
Project's Files Structure Modified;
Signed-off-by: Saturneric <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | src/gpg/GpgContext.cpp | 104 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 3 | ||||
-rwxr-xr-x | src/ui/FileEncryptionDialog.cpp | 5 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.cpp (renamed from src/ui/KeyList.cpp) | 37 |
4 files changed, 98 insertions, 51 deletions
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 2ca2f625..91602a70 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -275,18 +275,20 @@ namespace GpgME { gpgme_key_t key; - GpgKeyList keys; + mKeyList.clear(); + mKeyMap.clear(); + + auto &keys = mKeyList; + auto &keys_map = mKeyMap; - //TODO dont run the loop more often than necessary - // list all keys ( the 0 is for all ) gpgmeError = gpgme_set_keylist_mode(mCtx, GPGME_KEYLIST_MODE_LOCAL | GPGME_KEYLIST_MODE_WITH_SECRET); - if (gpgmeError != GPG_ERR_NO_ERROR) { + if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { checkErr(gpgmeError); return; } gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 0); - if (gpgmeError != GPG_ERR_NO_ERROR) { + if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { checkErr(gpgmeError); return; } @@ -295,53 +297,56 @@ namespace GpgME { if (!key->subkeys) continue; - keys.append(GpgKey(key)); + GpgKey gpg_key(key); + + keys_map.insert(gpg_key.id, gpg_key); gpgme_key_unref(key); } -// if (gpgmeError != GPG_ERR_EOF) { -// checkErr(gpgmeError); -// return; -// } - - gpgmeError = gpgme_op_keylist_end(mCtx); - if (gpgmeError != GPG_ERR_NO_ERROR) { + if (gpg_err_code(gpgmeError) != GPG_ERR_EOF) { checkErr(gpgmeError); return; } - // list only private keys ( the 1 does ) - gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 1); - if (gpgmeError != GPG_ERR_NO_ERROR) { + gpgmeError = gpgme_op_keylist_end(mCtx); + if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { checkErr(gpgmeError); return; } - while ((gpgmeError = gpgme_op_keylist_next(mCtx, &key)) == GPG_ERR_NO_ERROR) { - if (!key->subkeys) - continue; - // iterate keys, mark privates - GpgKeyList::iterator it = keys.begin(); - while (it != keys.end()) { - if (key->subkeys->keyid == it->id.toStdString()) - it->is_private_key = true; - it++; - } - gpgme_key_unref(key); - } - -// if (gpgmeError != GPG_ERR_EOF) { +// list only private keys ( the 1 does ) +// gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 1); +// if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { +// checkErr(gpgmeError); +// return; +// } +// +// while ((gpgmeError = gpgme_op_keylist_next(mCtx, &key)) == GPG_ERR_NO_ERROR) { +// if (key->subkeys) { +// auto it = keys_map.find(key->subkeys->keyid); +// if (it != keys_map.end()) { +// it->is_private_key = true; +// } +// } +// gpgme_key_unref(key); +// } +// +// if (gpg_err_code(gpgmeError) != GPG_ERR_EOF) { // checkErr(gpgmeError); // return; // } gpgmeError = gpgme_op_keylist_end(mCtx); - if (gpgmeError != GPG_ERR_NO_ERROR) { + if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { checkErr(gpgmeError); return; } + for(auto &gpg_key : keys_map) { + keys.append(gpg_key); + } + mKeyList = keys; } @@ -546,6 +551,7 @@ namespace GpgME { QString passwordDialogMessage; QString gpgHint = QString::fromUtf8(uid_hint); bool result; + #ifdef _WIN32 DWORD written; HANDLE hd = (HANDLE)fd; @@ -807,11 +813,11 @@ namespace GpgME { return (gpgmeError == GPG_ERR_NO_ERROR); } -/* - * if there is no '\n' before the PGP-Begin-Block, but for example a whitespace, - * GPGME doesn't recognise the Message as encrypted. This function adds '\n' - * before the PGP-Begin-Block, if missing. - */ + /* + * if there is no '\n' before the PGP-Begin-Block, but for example a whitespace, + * GPGME doesn't recognise the Message as encrypted. This function adds '\n' + * before the PGP-Begin-Block, if missing. + */ void GpgContext::preventNoDataErr(QByteArray *in) { int block_start = in->indexOf(GpgConstants::PGP_CRYPT_BEGIN); if (block_start > 0 && in->at(block_start - 1) != '\n') { @@ -823,12 +829,12 @@ namespace GpgME { } } -/* - * isSigned returns: - * - 0, if text isn't signed at all - * - 1, if text is partially signed - * - 2, if text is completly signed - */ + /* + * isSigned returns: + * - 0, if text isn't signed at all + * - 1, if text is partially signed + * - 2, if text is completly signed + */ int GpgContext::textIsSigned(const QByteArray &text) { if (text.trimmed().startsWith(GpgConstants::PGP_SIGNED_BEGIN) && text.trimmed().endsWith(GpgConstants::PGP_SIGNED_END)) { @@ -891,6 +897,20 @@ namespace GpgME { return mKeyList; } + void GpgContext::getSigners(QVector<GpgKey> &signer) { + auto count = gpgme_signers_count(mCtx); + signer.clear(); + for(auto i = 0; i < count; i++){ + auto key = gpgme_signers_enum(mCtx, i); + auto it = mKeyMap.find(key->subkeys->keyid); + if(it == mKeyMap.end()) { + signer.push_back(GpgKey(key)); + } else { + signer.push_back(*it); + } + } + } + } diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index c319b294..5456c2a4 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -1,5 +1,6 @@ aux_source_directory(. QTUI_SOURCE) -aux_source_directory(./keypair_details QTUI_KEYPAIR_DETAILS_SOURCE) +aux_source_directory(./keypair_details QTUI_SOURCE) +aux_source_directory(./widgets QTUI_SOURCE) add_library(qtui STATIC ${QTUI_SOURCE} ${QTUI_KEYPAIR_DETAILS_SOURCE}) diff --git a/src/ui/FileEncryptionDialog.cpp b/src/ui/FileEncryptionDialog.cpp index 49d012f4..97e0d357 100755 --- a/src/ui/FileEncryptionDialog.cpp +++ b/src/ui/FileEncryptionDialog.cpp @@ -87,10 +87,7 @@ FileEncryptionDialog::FileEncryptionDialog(GpgME::GpgContext *ctx, QStringList k groupBox1->setLayout(gLayout); /*Setup KeyList*/ - mKeyList = new KeyList(mCtx); - mKeyList->hide(); - mKeyList->setColumnWidth(2, 150); - mKeyList->setColumnWidth(3, 150); + mKeyList = new KeyList(mCtx, KeyListRow::ONLY_SECRET_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress); mKeyList->setChecked(&keyList); statusLabel = new QLabel(); diff --git a/src/ui/KeyList.cpp b/src/ui/widgets/KeyList.cpp index c21a41ff..337c1fc5 100644 --- a/src/ui/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -22,12 +22,15 @@ * */ -#include "ui/KeyList.h" +#include "ui/widgets/KeyList.h" #include <utility> -KeyList::KeyList(GpgME::GpgContext *ctx, QWidget *parent) - : QWidget(parent) +KeyList::KeyList(GpgME::GpgContext *ctx, + KeyListRow::KeyType selectType, + KeyListColumn::InfoType infoType, + QWidget *parent) + : QWidget(parent), mSelectType(selectType), mInfoType(infoType) { mCtx = ctx; @@ -47,9 +50,30 @@ KeyList::KeyList(GpgME::GpgContext *ctx, QWidget *parent) mKeyList->setAlternatingRowColors(true); + // Hidden Column For Purpose + if(!(mInfoType & KeyListColumn::TYPE)) { + mKeyList->setColumnHidden(1, true); + } + if(!(mInfoType & KeyListColumn::NAME)) { + mKeyList->setColumnHidden(2, true); + } + if(!(mInfoType & KeyListColumn::EmailAddress)) { + mKeyList->setColumnHidden(3, true); + } + if(!(mInfoType & KeyListColumn::Usage)) { + mKeyList->setColumnHidden(4, true); + } + if(!(mInfoType & KeyListColumn::Validity)) { + mKeyList->setColumnHidden(5, true); + } + if(!(mInfoType & KeyListColumn::FingerPrint)) { + mKeyList->setColumnHidden(6, true); + } + QStringList labels; labels << tr("Select") << tr("Type") << tr("Name") << tr("Email Address") - << tr("Usage") << tr("Validity") << tr("Finger Print"); + << tr("Usage") << tr("Validity") << tr("Finger Print"); + mKeyList->setHorizontalHeaderLabels(labels); mKeyList->horizontalHeader()->setStretchLastSection(true); @@ -82,6 +106,11 @@ void KeyList::slotRefresh() while (it != keys.end()) { + if(mSelectType == KeyListRow::ONLY_SECRET_KEY && !it->is_private_key) { + it++; + continue; + } + buffered_keys.push_back(*it); auto *tmp0 = new QTableWidgetItem(QString::number(row)); |