diff options
author | Claudio Maradonna <claudio@unitoo.pw> | 2018-07-14 10:15:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-14 10:15:19 +0200 |
commit | 9ff9147be35f498ec33e42f44a7aa66f9274524e (patch) | |
tree | 94554e4db2d0eac4fc250490258fe570df0803ca /src | |
parent | 8a907b9c03b73e0a1563c2b1563f5aecace7a466 (diff) | |
parent | da168e03beb4d5a9b09526fc6ed3db8a92fae3c6 (diff) |
Merge pull request #10 from IJHack/master
Update local
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 4 | ||||
-rw-r--r-- | src/pass.cpp | 86 | ||||
-rw-r--r-- | src/pass.h | 3 |
3 files changed, 51 insertions, 42 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 33328e85..4dc56c36 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -841,7 +841,7 @@ void MainWindow::onUsers() { ? Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel) : currentDir; int count = 0; - QString recipients = QtPassSettings::getPass()->getRecipientString( + QStringList recipients = QtPassSettings::getPass()->getRecipientString( dir.isEmpty() ? "" : dir, " ", &count); if (!recipients.isEmpty()) selected_users = QtPassSettings::getPass()->listKeys(recipients); @@ -863,7 +863,7 @@ void MainWindow::onUsers() { users.append(i); } } - } + } UsersDialog d(this); d.setUsers(&users); if (!d.exec()) { diff --git a/src/pass.cpp b/src/pass.cpp index 24b371c4..2586b252 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -113,42 +113,56 @@ void Pass::GenerateGPGKeys(QString batch) { /** * @brief Pass::listKeys list users + * @param keystrings + * @param secret list private keys + * @return QList<UserInfo> users + */ +QList<UserInfo> Pass::listKeys(QStringList keystrings, bool secret) { + QList<UserInfo> users; + QStringList args = {"--no-tty", "--with-colons"}; + args.append(secret ? "--list-secret-keys" : "--list-keys"); + + foreach (QString keystring, keystrings) { + if(!keystring.isEmpty()) { + args.append(keystring); + } + } + QString p_out; + if (exec.executeBlocking(QtPassSettings::getGpgExecutable(), args, &p_out) != + 0) + return users; + QStringList keys = p_out.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); + UserInfo current_user; + foreach (QString key, keys) { + QStringList props = key.split(':'); + if (props.size() < 10) + continue; + if (props[0] == (secret ? "sec" : "pub")) { + if (!current_user.key_id.isEmpty()) + users.append(current_user); + current_user = UserInfo(); + current_user.key_id = props[4]; + current_user.name = props[9].toUtf8(); + current_user.validity = props[1][0].toLatin1(); + current_user.created.setTime_t(props[5].toUInt()); + current_user.expiry.setTime_t(props[6].toUInt()); + } else if (current_user.name.isEmpty() && props[0] == "uid") { + current_user.name = props[9]; + } + } + if (!current_user.key_id.isEmpty()) + users.append(current_user); + return users; +} + +/** + * @brief Pass::listKeys list users * @param keystring * @param secret list private keys * @return QList<UserInfo> users */ QList<UserInfo> Pass::listKeys(QString keystring, bool secret) { - QList<UserInfo> users; - QStringList args = {"--no-tty", "--with-colons"}; - args.append(secret ? "--list-secret-keys" : "--list-keys"); - if (!keystring.isEmpty()) - args.append(keystring); - QString p_out; - if (exec.executeBlocking(QtPassSettings::getGpgExecutable(), args, &p_out) != - 0) - return users; - QStringList keys = p_out.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); - UserInfo current_user; - foreach (QString key, keys) { - QStringList props = key.split(':'); - if (props.size() < 10) - continue; - if (props[0] == (secret ? "sec" : "pub")) { - if (!current_user.key_id.isEmpty()) - users.append(current_user); - current_user = UserInfo(); - current_user.key_id = props[4]; - current_user.name = props[9].toUtf8(); - current_user.validity = props[1][0].toLatin1(); - current_user.created.setTime_t(props[5].toUInt()); - current_user.expiry.setTime_t(props[6].toUInt()); - } else if (current_user.name.isEmpty() && props[0] == "uid") { - current_user.name = props[9]; - } - } - if (!current_user.key_id.isEmpty()) - users.append(current_user); - return users; + return listKeys(QStringList(keystring), secret); } /** @@ -266,15 +280,9 @@ QStringList Pass::getRecipientList(QString for_file) { * @param count * @return recepient string */ -QString Pass::getRecipientString(QString for_file, QString separator, +QStringList Pass::getRecipientString(QString for_file, QString separator, int *count) { - QString recipients_str; - QStringList recipients_list = Pass::getRecipientList(for_file); - if (count) - *count = recipients_list.size(); - foreach (const QString recipient, recipients_list) - recipients_str += separator + '"' + recipient + '"'; - return recipients_str; + return Pass::getRecipientList(for_file); } /* Copyright (C) 2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. @@ -54,11 +54,12 @@ public: virtual QString Generate_b(unsigned int length, const QString &charset); void GenerateGPGKeys(QString batch); + QList<UserInfo> listKeys(QStringList keystring, bool secret = false); QList<UserInfo> listKeys(QString keystring = "", bool secret = false); void updateEnv(); static QStringList getRecipientList(QString for_file); // TODO(bezet): getRecipientString is useless, refactor - static QString getRecipientString(QString for_file, QString separator = " ", + static QStringList getRecipientString(QString for_file, QString separator = " ", int *count = NULL); protected: |